16

My friend showed me a cool trick on Emacs some days ago where he could just open a file on a remote server and I instantly thought "there should be a way to do that in vim too" and it was true.

I can just use :e scp://user@server//filepath to do that, no problem ;). However, he could just type the server name and then get completion for file paths and names (with tab), something that I haven't been able to do. Does somebody know if this can be done in vim?

  • 1
    I'd have though ctrlp might support it... but apparently it's a feature request. – muru Jul 14 '15 at 4:58
6

Yes, but currently(2015) not out-of-the-box, because the built-in file-manager of vim doesn't natively support remote browsing. .

Update Q3@2016:

There are several work-arounds, with varying degrees of comfort/compatibility/effort. All together they add up to a nice solution, but they can all also be used individually:

If you can't modify your environment or .vimrc-only: In the vim file-manager you can use the //? Keys to search forwards/backwards, and you could map TAB to one of them. This is more powerful than it sounds for quickly navigating you around the file-system. Description below.

Basic Workaround (for standard vim with NetRW):

  • Don't point vim to a remote file
  • Point to a directory "at the top" e.g. $HOME: vim scp://files/, or /: vim scp://files///
  • NetRW plugin opens in wanted top-level-folder (/ or $HOME).
  • In NetRW, you can navigate with surprisingly few keystrokes:
  • To edit remote /etc/network/interfaces with NetRW on /:

    /etENTERENTER/netwENTERENTER/intENTERt

You can always use ? to search back upwards, without wrapping from the top.

Even better, for nearly mimicking TAB-Completion add in .vimrc:

  • Map TAB to / in NetRW: autocmd filetype netrw noremap <buffer> <TAB> /
  • Configure NetRW for TreeView: let g:netrw_liststyle=3
  • Add a toggle for a remote VExplore for <C-E>, if you want (I use it).
  • I also recommend incsearch, ignorecase and smartcase for NetRW, or all buffers.

Compared to "conventional" tab-completion, the above is different, yet very comfortable.

Note: All of the above assumes ssh certificate based password-less connections in ~/.ssh/config with User, Port, Compression, JumpHost (ProxyCommand are setup up such that only hostname/aliases are needed.

This has also been previously discussed offsite here and here

  • 1
    Can you expand on the trick by summarizing the link? A plain link is not very useful if the site goes down or dies. – muru Aug 10 '15 at 2:18
  • I think, this is more or less my final "solution", until NetRW can do this natively. I will still take care of remaining known issues, but expect to find (or be pointed to) more subtle bugs, fixes, and enhancements. They will be addressed/incorporated. Thank you for commenting. – Alex Stragies Aug 12 '15 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.