From e5f24e2b8bc09ce6fc3488215d69ddb7cadc5f8d Mon Sep 17 00:00:00 2001 From: Phil Runninger Date: Tue, 7 Sep 2021 10:14:36 -0400 Subject: [PATCH] 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. --- CHANGELOG.md | 1 + README.markdown | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8a2341..87e0f78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR) --> #### 6.10 +- **.12**: Answer the question about accessing files over scp or ftp. (PhilRunninger) [#1259](https://github.com/preservim/nerdtree/pull/1259) - **.11**: Trim filenames created via the fs_menu (elanorigby) [#1243](https://github.com/preservim/nerdtree/pull/1243) - **.10**: Improve F.A.Q. Answers and Issue Templates (PhilRunninger) [#1249](https://github.com/preservim/nerdtree/pull/1249) - **.9**: `go` on a bookmark directory will NERDTreeFind it. (PhilRunninger) [#1236](https://github.com/preservim/nerdtree/pull/1236) diff --git a/README.markdown b/README.markdown index ea10c11..2de10d6 100644 --- a/README.markdown +++ b/README.markdown @@ -187,3 +187,35 @@ let g:NERDTreeDirArrowExpandable = '▸' let g:NERDTreeDirArrowCollapsible = '▾' ``` 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. + +### Can NERDTree access remote files via scp or ftp? + +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. + +```vim +" Function to open the file or NERDTree or netrw. +" Returns: 1 if either file explorer was opened; otherwise, 0. +function! s:OpenFileOrExplorer(...) + if a:0 == 0 || a:1 == '' + NERDTree + elseif filereadable(a:1) + execute 'edit '.a:1 + return 0 + elseif a:1 =~? '^\(scp\|ftp\)://' " Add other protocols as needed. + execute 'Vexplore '.a:1 + elseif isdirectory(a:1) + execute 'NERDTree '.a:1 + endif + return 1 +endfunction + +" Auto commands to handle OS commandline arguments +autocmd StdinReadPre * let s:std_in=1 +autocmd VimEnter * if argc()==1 && !exists('s:std_in') | if OpenFileOrExplorer(argv()[0]) | wincmd p | enew | wincmd p | endif | endif + +" Command to call the OpenFileOrExplorer function. +command! -n=? -complete=file -bar Edit :call OpenFileOrExplorer('') + +" Command-mode abbreviation to replace the :edit Vim command. +cnoreabbrev e Edit +```