VIM Ctrl-V 与 Windows 粘贴冲突

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/426896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:55:39  来源:igfitidea点击:

VIM Ctrl-V Conflict with Windows Paste

windowsvim

提问by David.Chu.ca

I am using VIM in Windows. The problem is that I want to use CtrlVas 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 中使用 VIM。问题是我想CtrlV用作视觉模式。但是,该键与 Windows 粘贴有冲突。如何将此键重置回 VIM 可视模式而不是粘贴。我更喜欢在我的 _vimrc 配置文件中设置它。

回答by Alex

From the VIM documentation:

VIM 文档

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

由于CTRLV用于粘贴,您不能使用它来启动块状视觉选择。你可以CTRLQ改用。您还可以CTRLQ在插入模式和命令行模式下使用来获得CTRLV. 但是CTRLQ当它用于控制流时不适用于终端。

回答by jop

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.

检查你的 _vimrc 文件,看看它是否来自 mswin.vim。该脚本将 ^v 映射到粘贴。您可以在 _vimrc 文件中删除该行,也可以直接在 mswin.vim 上禁用映射命令。

Do a :help behave on vim for more info.

在 vim 上执行 :help 行为以获取更多信息。

回答by dannysauer

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

像在 Unix 中一样工作的可视模式(和其他东西)需要 JOP 和 Windows 程序员的建议。

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

在 Windows 上的 GVim 中,转到编辑菜单,单击启动设置,然后注释掉特定于 Windows 的垃圾(使用 vimrc 注释字符,这是一个双引号)。mswin.vim 文件是指定ctrl-v覆盖的地方,行为 mswin 选项使得箭头键不会像您期望的那样应用运动(它还改变鼠标选择行为)。

"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

我也喜欢在那里添加一个黑色背景颜色方案,所以它看起来更像我在终端中看到的(因为浅色背景在纸上很好,但在背光屏幕上很糟糕): colorscheme koehler

回答by Windows programmer

If this line in your _vimrc troubles you:

如果 _vimrc 中的这一行让您感到困扰:

behave mswin

then delete that line.

然后删除该行。

回答by rshdev

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

我更喜欢在任何地方使用相同的按键,所以我在我的 .vimrc 中使用它来覆盖 mswin.vim:

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

回答by Starkii

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

我不确定你可以做很多事情。你可以改用CtrlQ

回答by Rick Reynolds

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.

jop 的建议(在默认的 _vimrc 文件中查找 mswin.vim)和“Windows 程序员”的建议(去掉“behave mswin”行)的组合对我来说就像一个魅力。

(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)

(我的代表太低,无法对它们进行投票或将它们合并——有人为我清理这个,否则一旦我的代表更高,我就会回来)