Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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)

share|improve this question

2 Answers 2

up vote 7 down vote accepted

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.

share|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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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