VIM Ctrl-V Conflict with Windows Paste

Viewed 79987

I am using VIM in Windows. The problem is that I want to use CtrlV as a visual mode. However, this key has conflict with Windows paste. How can I reset this key back to VIM visual mode instead of pasting. I prefer to set this in my _vimrc configuration file.

11 Answers

From the VIM documentation:

Since CTRLV is used to paste, you can't use it to start a blockwise Visual selection. You can use CTRLQ instead. You can also use CTRLQ in Insert mode and Command-line mode to get the old meaning of CTRLV. But CTRLQ doesn't work for terminals when it's used for control flow.

Check your _vimrc file and see if it sources mswin.vim. That script maps the ^v to the paste. You can either remove that line on your _vimrc file or disable the mapping commands directly on mswin.vim.

Do a :help behave on vim for more info.

If this line in your _vimrc troubles you:

behave mswin

then delete that line.

Here's a modern day solution to this problem. It applies to the terminal version of Vim/Neovim, not the GUI version. If you use Microsoft's new-ish Windows Terminal (I highly recommend it.), you can redefine its key bindings to your advantage. The following section of the settings file is initially NOT commented out. If you comment it out, as I've shown, Ctrl+V becomes the rectangular visual select key in Vim we all know and love.

// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
//{
//    "command": {
//        "action": "copy",
//        "singleLine": false
//    },
//    "keys": "ctrl+c"
//},
//{
//    "command": "paste",
//    "keys": "ctrl+v"
//}

Now here's the weird part. I'd expected this to change the behavior of Ctrl+V outside of Vim in the Terminal, so I checked. It still does a paste, but it's different than the Ctrl+Shift+V paste. Inside Vim, however, all is good: Ctrl+V for rectangular select; and "*P, Ctrl+Shift+V, or Right Mouse Button for pasting from the clipboard.

I'm not sure there is a lot you can do about that. You can use CtrlQ instead though.

For the Windows Terminal (PowerShell), click on the Dropdown arrow right next to the Shell-Tab and select settings. In the "actions" section of settings.json you can comment out the following lines so they're saying:

// { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },

and

// { "command": "paste", "keys": "ctrl+v" },

This unbounds Ctrl+V and Ctrl+C from Paste and Copy. However due to the defaults.json you're still able to use Shift+Ctrl+C and Shift+Ctrl+V for Copy and Paste with this solution.

Please see Phil R comment. Didnt see his solution in the first place.

The combination of jop's advice (looking for mswin.vim in the default _vimrc file) and "Windows programmer's" advice (getting rid of the "behave mswin" line) worked like a charm for me.

(my rep is too low to vote them up or combine them -- someone clean this up for me, or I'll come back once my rep is higher)

If the Windows-specific mappings as a whole bother you, you can set

let g:skip_loading_mswin = 1

in your vimrc to disable loading it (mswin.vim) entirely.

Related