-
In
~/.ssh/config
, include the lines:Host * ControlPath ~/.ssh/sockets/%r@%h-%p
-
In a shell, start an SSH session to the server on which the file is stored:
ssh -MNv username@server.example.org &
💡 Note: If SSH isn't configured to connect to the server without prompting for a password, omit the
&
symbol from the end of the command above. Also, the command shown in the next step will need to be run in another shell. -
There are two options for specifying the path to the file to be edited:
💡 Note: If the username on the local computer is the same as the username on the remote server, the
username@
portion of the SCP URLs shown below may omitted. If unsure, it's best to include the username as shown.-
After SSH has connected, start Vim with an SCP URL for the file to be edited:
vim scp://username@server.example.org/path/to/personal/file.txt
Now, any file operations in Vim will be sent over the network by SSH.
The path to the file given in the example above is relative to the home directory of the username. If the home directory is
/home/username
, then the file being edited in the example would be/home/username/path/to/personal/file.txt
. -
To use an absolute path, one that begins at the root filesystem of
server.example.org
, two slashes must be used between the hostname and the file path ("//
"). An absolute path example equivalent to the one above, assuming the home directory is/home/username
, would be:vim scp://username@server.example.org//home/username/path/to/personal/file.txt
Another example of an absolute path, using a commonly-available file,
/etc/shells
:vim scp://username@server.example.org//etc/shells
-
Created
July 13, 2017 16:11
-
-
Save sloanlance/f481b7b8ffc0bfa3f46a1c942c7e7b78 to your computer and use it in GitHub Desktop.
Editing remote files in Vim with SSH
Eipc
🥲 ...just so beautiful.
This is awesome.
you can use sshfs to mount remote files to local and edit with VIM https://www.youtube.com/watch?v=-0jyrvMl0Ic
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Legendary.