Skip to Content

Vim edit file on remote server

Posted on

Vim supports to edit files remotely. You can use this feature with openssh-client, which comes installed with most Linux flavors.

Sometime, I want to edit a file on remote server, but there is no vim on this remote server, just vi. I want to use my local config (to edit easier and quickly), but it takes time :3

In local machine with vim, you can use this command:

vim scp://remoteuser@remote_IP_or_hostname/relative/path/to/file

For example, if your file is stored in ~/project/src/test.rb:

vim scp://ec2-user@127.145.12.11/project/src/test.rb

Cause I access remote machine frequently, so I use ~/.ssh/config file to create a shortcut for the connection:

# ~/.ssh/config
Host remote-server
	Hostname 127.145.12.11
	User ec2-user
	IdentityFile ~/.ssh/id_rsa

Now, you can using this command to do the same thing:

vim scp://remote-server/project/src/main.c
comments powered by Disqus