How do I remotely edit files via ssh?

You can do that via scp like this:

vim scp://user@myserver[:port]//path/to/file.txt

Notice the two slashes // between server and path, which is needed to correctly resolve the absolute path. (The first slash is syntactic, while the second slash specifies the remote user's root directory, as usual. To start at the home directory, you'd do [:port]/~/path/to/file.txt.) [:port]is optional.

This is handled by vim's netrw.vim standard plugin. Several other protocols are supported.


You could do this by mounting the remote folder as a file-system using sshfs. To do this, first some pre-requisites:

#issue all these cmds on local machine
sudo apt-get install sshfs
sudo adduser <username> fuse #Not required for new Linux versions (including Ubuntu > 18.04)

Now, do the mounting process:

mkdir ~/remoteserv    
sshfs -o idmap=user <username>@<ipaddress>:/remotepath ~/remoteserv

After this, just go into the mounted folder and use your own local customized vim.


Depending on what you mean when you say you do not have the rights to edit the Vim settings, there may be a way of using Vim on the server in the way you want anyway. If you can't change your user .vimrc (because you're logging in as a shared user, for example) but you can still create files, create it as a file called, say, Loom.vimrc and then call Vim using the -u switch:

vim -u ~/Loom.vimrc file_to_edit

You can even then use an alias: alias vim='vim -u ~/Loom.vimrc' will allow you to use Vim in the usual way, and it'll still load your custom .vimrc file. This alias won't persist after you log out, so you don't need to worry about anyone else accidentally using your customised Vim.

Tags:

Vim

Ssh

Editors