VIM Ctrl-V Conflict with Windows Paste

WindowsVim

Windows Problem Overview


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.

Windows Solutions


Solution 1 - Windows

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.

Solution 2 - Windows

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.

Solution 3 - Windows

Visual mode (and other stuff) working like in Unix requires both JOP's and Windows Programmer's suggestions.

In GVim on Windows, go to the edit menu, click on startup settings, and comment out the windows-specific garbage (using the vimrc comment character, which is a double-quote). The mswin.vim file is where the ctrl-v override is specified, and the behave mswin option makes it so that the arrow keys don't just apply motion like you'd expect (it also changes the mouse selection behavior).

"source $VIMRUNTIME/mswin.vim
"behave mswin

I like to add a black-background colorscheme in there as well, so it looks more like what I'd see in a terminal (and because a light background is great on paper, but awful on a backlit screen): colorscheme koehler

Solution 4 - Windows

If this line in your _vimrc troubles you:

behave mswin

then delete that line.

Solution 5 - Windows

I prefer the same keystrokes everywhere so I use this in my .vimrc to override mswin.vim:

if has('win32')
  " Avoid mswin.vim making Ctrl-v act as paste
  noremap <C-V> <C-V>
endif

Solution 6 - Windows

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.

Solution 7 - Windows

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

Solution 8 - Windows

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.

Solution 9 - Windows

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)

Solution 10 - Windows

Correct answer for this question would be comment mentioned by stevesliva.

For VMs on Windows where CTRL+V does the pasting:

simply do CNTL+SHIFT+V ... works immediately and similarly to original CTRL+V visual selection.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavid.Chu.caView Question on Stackoverflow
Solution 1 - WindowsAlexView Answer on Stackoverflow
Solution 2 - WindowsjopView Answer on Stackoverflow
Solution 3 - WindowsdannysauerView Answer on Stackoverflow
Solution 4 - WindowsWindows programmerView Answer on Stackoverflow
Solution 5 - WindowsrshdevView Answer on Stackoverflow
Solution 6 - WindowsPhil RView Answer on Stackoverflow
Solution 7 - WindowsStarkiiView Answer on Stackoverflow
Solution 8 - WindowsPhilipp1887View Answer on Stackoverflow
Solution 9 - WindowsRick ReynoldsView Answer on Stackoverflow
Solution 10 - WindowsdgargView Answer on Stackoverflow