I was reading about SSH here http://blogs.perl.org/users/smylers/2011/08/ssh-productivity-tips.html and found that you can use vim to directly modify a file on a remote server that you can ssh into. Like:

vim scp://testserver/path/filename

And it works perfectly except that I need to provide a username (because I have a different user name on the server). How can I do that? (vim asks for the password, but uses my local username)


To open file using path relative to username's home directory run,

vim scp://username@remotehost/file
which is same as,
vim scp://username@remotehost//home/username/file

If you want to enter the absolute path to a file starting from / instead of your home directory, use two slashes after the host name run,

vim scp://username@remotehost//absolute/path/to/file

Editing your file is done exactly the same as for local files, including using :w to save your changes.

Behind the scene vim uses netrw plugin to read files, write files, browse over a network using various protocols like scp, rsync, ftp etc. :help netrw inside vim can give you a lot more information.

| improve this answer | |

Trying a couple things, I got this message:

format: protocol://[user@]hostname[:port]/[path]

Note that [path] will be interpreted from your home directory unless you add an additional / (vim scp://user@host//etc/vim/vimrc).

| improve this answer | |

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.