1

This question already has an answer here:

I want to use <C-S-v> to block visual selection and <C-v> to paste. And I have the following mapping in the vimrc.

" block visual selection
nnoremap <C-S-v> <c-v>

" paste
map <C-v> "+gp

but the latter seems to override the former. Can anyone help to get it right.

marked as duplicate by Rich, Peter Rincker, Herb Wolfe, 8bittree, statox Nov 2 '17 at 8:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Historically, this behaviour was caused by the underlying terminal implementation.

When you press the V key, the terminal sends the ASCII code 118, and when you press Shift-V, the terminal sends the ASCII code 86.

The Ctrl key was used for sending control characters, and it worked by clearing the 6th and 7th bits of any other keys pressed while it was held down.

If we convert the ASCII codes into binary, it's easier to see what's happening:

  • V 86 → 1010110
  • Shift-V 118 → 1110110
  • Ctrl-V xx10110 → 0010110 → 22
  • Ctrl-Shift-V xx10110 → 0010110 → 22

The codes sent to Vim are identical!

It is therefore impossible for terminal Vim to distinguish Ctrl-Shift-V from Ctrl-V.*

gVim uses the same underlying code for handling key-presses, and although it can handle some things that terminal Vim cannot, distinguishing between Ctrl+Shift and unshifted Ctrl is not one of these.

You can work around this in some terminals by configuring them to send a different keycode when you press certain key combinations and then mapping these keycodes in Vim, but such terminal configuration is outside the scope of this site.

A more detailed explanation of the issue, along with other terminal quirks, can be found here: Terminals are Weird.

*: There have been more recent developments that enable this, but so far, these have not been incorporated into Vim and there are no concrete plans to do so.

2

In insert mode, without any of those mappings, try entering CtrlV followed by CtrlV. Now try CtrlV followed by CtrlShiftV. Do you see ^V in both cases? Vim doesn't treat the two key-presses as distinct...so you're out of luck.

As far as I know control-shift is never a reliable key-combo for use in mappings. Or, to paraphrase FAQ 20.5, Vim can't reliably detect any control characters except those defined by the ASCII standard:

    Ctrl-@                 0x00            NUL
    Ctrl-A to Ctrl-Z       0x01 to 0x1A
    Ctrl-a to Ctrl-z       0x01 to 0x1A
    Ctrl-[                 0x1B            ESC
    Ctrl-\                 0x1C
    Ctrl-]                 0x1D
    Ctrl-^                 0x1E
    Ctrl-_                 0x1F
    Ctrl-?                 0x7F            DEL

Note the 2nd and 3rd lines showing identical codes for lower/upper case and no mention of Shift beyond that.

Read the linked FAQ section for a bit more info on the topic including map key recommendations.

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