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 have to edit some files placed on some server I could reach via ssh. I would prefer to edit these files in customized vim on my workstation (I have not rights to change vim settings on remote server). Sometimes I would like to edit a file with sublime text or other GUI editor. Of course, I can download these files, edit them locally and upload them back to server. Is there more elegant solution?

share|improve this question

4 Answers 4

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. [:port]is optional.

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

share|improve this answer
    
when you save the file changes are the saved back to the remote server? –  rob yesterday
5  
Yes, the file is retrieved to a temporary file, that is uploaded to the server on save. –  FloHimself yesterday
    
Thank you. However, I have got an error, when tried to save file: E382: Cannot write, 'buftype' option is set –  Loom yesterday
1  
@Loom, I had the same problem, because I omitted the double slash //. Perhaps you made the same mistake? –  Benjamin B. yesterday
1  
You can try :set buftype=""​ in vim. –  FloHimself yesterday

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

sudo apt-get install sshfs      #for Debian based OS, use yum or zypper depending on your OS
sudo adduser <username> fuse

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.

share|improve this answer
    
Thank you. I tried it. Unfortunately, I have no /dev/fusermount on my computer. I have /bin/fusermount. Does it the same? –  Loom yesterday
    
Without /dev/fusermount all works perfect. Thank you –  Loom yesterday
5  
The referenced information from HowToGeek was from 2006 and heavily outdated. I've updated the answer to the much simpler and up-to-date way of invoking SSHFS. –  Benjamin B. yesterday
3  
Unsurprisingly, the installation step will fail on distributions that are not deb-based and hence don't have apt-get. (In which case, yum or zypper might be present.) They also require root on the local machine, whcih may or may not be available. (This is not to say it's a bad solution, but it comes with a big prerequisite.) –  Ulrich Schwarz yesterday
    
Thank you, @BenjaminB. –  user1717828 yesterday

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.

share|improve this answer

Depending on how many files and what kind of files you are expecting to edit, this is maybe not exactly what you want to do here, but I think it's worth mentioning. If you have to edit files in a remote server, but want to use everything you have in your own working station, then you may want to start thinking of using some kind of Revision Control system in your machines. That way, you can modify your local copies in your own machine using your software of choice, commit the changes, and then just update the local copies in the destination machine. Besides editing the files with whatever software you feel comfortable with, you have the added value of having a history of changes related to each file, which is always good.

Here's a list of Revision Control Software, just in case.

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.