2

How to install gvim on a RHEL server that doesn't have it (for use with SSH with X11 forwarding*)? No sudo access is available, so it has to be in the user's home directory.

*Getting all the convenience of having the remote Vim in a window that's separate from the shell.

3 Answers 3

6

For those of you who are looking at this now, in fedora/RHEL based distributions, you can do the installation with,

sudo yum install vim-X11
2

It isn't very difficult to install vim in your home directory, and I see that you've found a way. However this is not necessarily the best solution.

Running vim on the remote machine has the downsides of running a remote editor: it lags if the connection lags; it dies if the connection dies.

You can use (g)vim locally to edit remote files. There are two approaches for that. One approach is to mount the remote filesystem over sshfs. Sshfs is available on most unices (but not on Windows). Once mounted, you can edit files with Vim and generally manipulate files as if they were local. Sshfs requires SFTP access on the remote machine.

mkdir ~/net/someserver
sshfs someserver:/ ~/net/someserver
gvim ~/net/someserver/path/to/file
fusermount -u ~/net/someserver

Alternatively, you can make Vim do the remote access. The netrw plugin is bundled with Vim.

gvim scp://someserver/path/to/file

A limitation of both approaches is that the files are opened with the permissions of the user that you SSH into. This can be a problem if you need to edit files as root, since SSH servers are often configured to forbid direct root logins over SSH (not so much for security as for accountability — having a trace if a non-malicious root screws up). Vim has a plugin to edit over ssh and a plugin to edit over sudo, but I don't know how to combine the two.

5
  • This is a much better solution for the long term, because it avoids having to synchronise .vimrc files between N machines. Oct 2, 2013 at 3:03
  • I got it to work on Windows by defining let g:netrw_cygwin = 0 and let g:netrw_scp_cmd = "C:\\Programs\\PuTTY\\pscp.exe " in _vimrc, which lets me write in Command Prompt gvim scp://user@host/file/relative/to/home.txt, which works great, but it asks for the password on every read and write (doesn't keep alive). I'd rather not store the password in plain text on disk. Oct 2, 2013 at 3:04
  • 1
    @EvgeniSergeev For the password, run Pageant so that you only have to type your password once per session, or run the Cygwin scp and ssh-agent, or run the Cygwin scp through a ControlMaster connection (and optionally ssh-agent). Oct 2, 2013 at 7:48
  • As described here the.earth.li/~sgtatham/putty/0.58/htmldoc/Chapter8.html#pubkey and elsewhere, I used PuTTYgen to generate public+private keys, saved the files locally, copied the (public key) string it produced into ~/.ssh/authorized_keys on the server as a new line, started up Pageant daemon on my Windows machine, added the private key file into it, and now editing using SCP in Vim doesn't ask for a password anymore, but only "press any key to continue". Which makes it usable! (It is also possible to configure WinSCP such that Editing will get Vim to do it.) Oct 2, 2013 at 7:49
  • 1
    In fact the WinSCP integration is even more seamless, and is a breeze to set up. Just a matter of locating gvim.exe in a file picker and assigning it to handle the editing of all files. Oct 3, 2013 at 7:03
1

Thanks to this answer https://unix.stackexchange.com/a/61295/32647 it turns out to be simple, like:

$ yumdownloader vim-X11
$ rpm2cpio vim-X11-7.2.411-1.8.el6.x86_64.rpm > vim-X11.cpio
$ cpio -idv < vim-X11.cpio
$ ./usr/bin/gvim

It works!

Explanation: the first command gets the RPM into the current directory without installing it. The second converts it into a cpio archive. The third unpacks it under the current directory.

To make it usable as gvim:

$ echo alias gvim=\'`pwd`/usr/bin/gvim\' >> ~/.bashrc
$ source ~/.bashrc
$ gvim

There.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .