In Vim, the canonical methods to interact with X11's Clipboard and Primary is to use + and * registers.

There are at least another two ways to paste from Primary into Vim: Shift-Insert and Mouse Middle-Click, which have nearly the same effect of "*p. Their advantage is that they should work even if Vim has no clipboard support (-clipboard).

However, since those are handled by the terminal emulator rather than Vim, if the selected text happens to be too large or comes from a cranky PDF, the paste can be really slow and there is no clean way to abort it.

Edit: There are also security concerns when pasting malicious but apparently innocuous data directly into the terminal.

Hence comes the question: Can Vim be made to refuse text pasted from Shift-Insert? I would not like to unbind it from my terminal, XTerm, because it is the only way to paste text into XTerm.

I do not care much to disable Mouse Middle-Click because, after all, it's the mouse and I'm not touching it as long as I have the keyboard. But if there is a solution to both, I will much glad to disable both.

  • You could :set paste or use your pastetoggle before one of those methods—that usually helps speed up a slow paste (treating the input as a paste instead of as characters typed one at a time)
    – D. Ben Knoble
    Jul 6, 2020 at 12:23
  • 1
    Vim does not know that the input comes from Shift+Insert, it merely sees some input, but it doesn't know whether you typed it or it was pasted, because this is some interprocess communication from your X11 session. If at all, you would need to configure your X11 session to ignore the Shift-Insert key combination. Don't think this is actually possible. Jul 6, 2020 at 12:55

1 Answer 1


I found a solution which relies on Vim's +clientserver capability. It just took a small addition to a script I already used. The final result is this vimserver.sh:

if [ -z "$(vim --serverlist)" ]; then
    xterm -name vimserver -xrm 'vimserver*vt100.Translations:#override\
    Shift <KeyPress> Insert: insert-selection(None,None)' \
    -e vim -p --servername XVIM "$@"
    xdotool search --classname vimserver windowactivate
    vim --servername XVIM --remote-tab "$@"

I discussed it in detail in my answer to How to open new files in a same Vim instance from Midnight Commander?. The idea is that, with that script, each file I open for editing in Vim is in a separate tab of a same Vim instance in a dedicated XTerm. So issuing

vimserver.sh file1 &
vimserver.sh file2 &
vimserver.sh file3 &

opens the three files in a same new terminal with Vim, each in its own tab.

Since it uses a single, dedicated terminal, the key was to remove the Shift-Insert binding from that XTerm with the option

-xrm 'vimserver*vt100.Translations:#override\
    Shift <KeyPress> Insert: insert-selection(None,None)'

It is not necessary to remove Mouse Middle-Click, as Vim itself deals with that binding (see :help <MiddleMouse>).

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.