When connected to a remote headless Linux server via SSH, I want to be able to do 3 things:

  • select text using the mouse and copy the selection into my local X clipboard

  • paste from local X clipboard into the remote document I'm editing

  • position editing cursor using the mouse (:set mouse=a).

Please suggest the best way to achieve all three of these features together.

Here's where I am in my attempts. I'm running KDE and my terminal is Konsole. I get the first two things "free" with Konsole (it just works) but I dont' get the last feature, which would have to be enabled in vim (or neovim).

However, if I invoke :set mouse=a to get that last feature, I lose both of the other two. My goal is to have all 3 features at the same time.

In my research I checked this question: How can I copy text to the system clipboard from Vim?

My situation bumps into every gotcha listed in that question:

  • the remote system is not running X. It is a headless Linux server.

  • the CentOS vim package is compiled with "-clipboard"

  • I cannot use X11Forwarding with SSH (due to policy and due to remote system not having X)

  • As far as I know, I cannot use scp to edit files. I have to have root permissions to edit many files, but I cannot make an ssh connection as root (by policy / sshd_config settings on remote system).

  • the last option suggested there is neovim which is available for me to use. But again, the remote system doesn't have X. However, I understand I may be able to use tmux, but haven't gotten that to work yet.

What is the usual way someone would achieve what I'm trying to do? Are there solutions I have overlooked?

If the best option is neovim + tmux, how do I get that to work? Should I use one of these?


1 Answer 1


I cannot use X11Forwarding with SSH (due to policy and due to remote system not having X)

That's a very restrictive one...

Note that you don't need an X11 server running at your remote machine. All you need is the X11 libraries installed. You also would need a build of Vim that has +clipboard feature, which you can typically find in a gvim binary if one is installed.

If you have a gvim binary available, you can use gvim -v to start it in Vim mode, meaning it will run in the terminal and not use X11 forwarding. But it will still be able to use X11 for the clipboard.

Some distributions also ship a vimx binary which doesn't include GUI support but do include +clipboard.

So if you were able to use SSH with X11 forwarding and you had a gvim or vimx binary on your server, then all you would need would be:

set mouse=a
set mousemodel=extend
set clipboard=unnamed

The mousemodel one is the default, and the clipboard setting is so that Vim will always sync yanks and pastes with the X11 selection (a.k.a "primary"; use unnamedplus if you prefer to use the X11 "clipboard" instead.)

Take a look at the help for these options if you plan to employ them.

Using X11 forwarding also might present some problems if you're running Vim as root under sudo, since sometimes X11 forwarding will break under that setup (xauth token needs to be forwarded.) It's possible to set up sudo so that it works, but you might need to spend even more time testing that and researching it to make all of it works seamlessly...

Another approach to keep both mouse=a and copy and paste from your terminal is to look into your terminal support for bypassing mouse capture.

Most terminal emulators will allow mouse capture by the application running on the terminal, but they'll also bypass it if you make a selection while holding one (or more?) of the modifier keys: Shift, Ctrl or Alt. Perhaps try that on Konsole and see if that works? That way you still keep mouse=a, but you're able to use Konsole to copy & paste when needed, while not depending on X11 forwarding for clipboard synchronization.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.