Skip to content

Commit e5f24e2

Browse files
Answer the question about accessing files over scp or ftp. (#1259)
* Answer the question about accessing files over scp or ftp. * Minor formatting change to README. * Update version number in Change Log.
1 parent 0e71462 commit e5f24e2

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR)
66
-->
77
#### 6.10
8+
- **.12**: Answer the question about accessing files over scp or ftp. (PhilRunninger) [#1259](https://github.com/preservim/nerdtree/pull/1259)
89
- **.11**: Trim filenames created via the fs_menu (elanorigby) [#1243](https://github.com/preservim/nerdtree/pull/1243)
910
- **.10**: Improve F.A.Q. Answers and Issue Templates (PhilRunninger) [#1249](https://github.com/preservim/nerdtree/pull/1249)
1011
- **.9**: `go` on a bookmark directory will NERDTreeFind it. (PhilRunninger) [#1236](https://github.com/preservim/nerdtree/pull/1236)

README.markdown

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,35 @@ let g:NERDTreeDirArrowExpandable = '▸'
187187
let g:NERDTreeDirArrowCollapsible = ''
188188
```
189189
The preceding values are the non-Windows default arrow symbols. Setting these variables to empty strings will remove the arrows completely and shift the entire tree two character positions to the left. See `:h NERDTreeDirArrowExpandable` for more details.
190+
191+
### Can NERDTree access remote files via scp or ftp?
192+
193+
Short answer: No, and there are no plans to add that functionality. However, Vim ships with a plugin that does just that. It's called netrw, and by adding the following lines to your `.vimrc`, you can use it to open files over the `scp:`, `ftp:`, or other protocols, while still using NERDTree for all local files. The function seamlessly makes the decision to open NERDTree or netrw, and other supported protocols can be added to the regular expression.
194+
195+
```vim
196+
" Function to open the file or NERDTree or netrw.
197+
" Returns: 1 if either file explorer was opened; otherwise, 0.
198+
function! s:OpenFileOrExplorer(...)
199+
if a:0 == 0 || a:1 == ''
200+
NERDTree
201+
elseif filereadable(a:1)
202+
execute 'edit '.a:1
203+
return 0
204+
elseif a:1 =~? '^\(scp\|ftp\)://' " Add other protocols as needed.
205+
execute 'Vexplore '.a:1
206+
elseif isdirectory(a:1)
207+
execute 'NERDTree '.a:1
208+
endif
209+
return 1
210+
endfunction
211+
212+
" Auto commands to handle OS commandline arguments
213+
autocmd StdinReadPre * let s:std_in=1
214+
autocmd VimEnter * if argc()==1 && !exists('s:std_in') | if <SID>OpenFileOrExplorer(argv()[0]) | wincmd p | enew | wincmd p | endif | endif
215+
216+
" Command to call the OpenFileOrExplorer function.
217+
command! -n=? -complete=file -bar Edit :call <SID>OpenFileOrExplorer('<args>')
218+
219+
" Command-mode abbreviation to replace the :edit Vim command.
220+
cnoreabbrev e Edit
221+
```

0 commit comments

Comments
 (0)