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.
9 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.
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
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.
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)
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.