-
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 [email protected] &
💡 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://[email protected]/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://[email protected]//home/username/path/to/personal/file.txt
Another example of an absolute path, using a commonly-available file,
/etc/shells
:vim scp://[email protected]//etc/shells
-
Forked from sloanlance/Editing remote files in Vim with SSH.md
Created
October 8, 2021 16:22
-
-
Save pidb/7d4d65b287cec4583d4d8094fc65e632 to your computer and use it in GitHub Desktop.
Editing remote files in Vim with SSH
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment