9

I know one can use vim scp://host/path/to/file to edit locally remote files then update the remote machine when saving (:w). However I would like to know if it's possible to navigate through directories using ssh (or if there's a plugin to do that)

NERDTree doesn't support it, and when viming into a folder, although netrw allow me to navigate into directories, opening a file doesn't work.

12

Instead of pointing Vim/Netrw to a file:

scp://host/path/file

point it to a directory:

scp://host/path/

This gives you the same listing and the same shortcuts as if you were browsing your machine.

  • have you tried this when remoting from your Unix machine to access folders on a Windows machine.. I just tried vim scp://user@10.1.4.4//C:/Users/user/Desktop/tmp/, and it just gave me a blank screen, with the error 'ls' is not recognized as an internal or external command when I try: vim scp://user@10.1.4.4//C:/Users/user/Desktop/tmp/filename.. it works fine. – alpha_989 Jul 18 '18 at 18:41
  • From this it seems that vim is issuing a command ls, when it logs into the remote computer.. and because its a windows computer.. there is no ls.. and the command fails. Is it possible for vim to traverse windows directories over ssh using netrw plugin or something else ? I using VIM 8.1 – alpha_989 Jul 18 '18 at 18:46
  • Please note that the trailing slash after scp://host//path/ is necessary for this to work; otherwise, vim will try to open the path as a regular file, which will load blank. – koyae Jul 4 at 18:45
1

Oops forgot I had this question opened !

So the problem was that, with the netrw version I had (packaged with vim-gnome on Debian Jessie), modifying a file from the explorer (through ssh) would not use the correct URI (from memory, the '@' in the 'user@host' was missing). It opened an empty file (because it didn't find anything) but it still saved the new file using the good URI (effectively overwriting the original file).

@user21497's answer also helped me though because I never found that 'new file' shortcut, which is quite handy because using ':e' creates the file locally.

Finally, this question helped me navigate better using netrw (getting back to the explorer after opening a file using :Ex)

Thanks for your help guys !

0

I'm not sure what you mean by "notify new file"; if you want to create a new file, when browsing via scp://hostname/directory, just press "%" like you would when in a local directory to create a new file. See :help netrw-%. You may create a directory using d (:help netrw-d). If you want to modify an already existing file, select it with your cursor atop the filename in the netrw display and press <cr> (there are other selection methods, too, including v, o, t, etc). See :help netrw-quickmap for an overview on this. I've just tried this and did not get an empty file (when pre-existing). A new file, of course, will be empty.

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.