为什么 <Ca> (CTRL+A) 在 windows 上的 gvim 下不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/289681/
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
Why does < C-a> (CTRL+A) not work under gvim on windows?
提问by snth
I'm trying to use the < C-a> (CTRL+A) shorcut under vim to increment a variable under the cursor. This works fine under vim running on Linux. However when I try to do this in gvim under windows it "selects all" (i.e. highlights or visually selects all text in the current window). How can I change this behaviour or alternatively how can I recover the increment variable functionality (e.g. perhaps with a different key mapping)?
我正在尝试使用vim 下的 < Ca> ( CTRL+ A) 快捷方式来增加光标下的变量。这在 Linux 上运行的 vim 下工作正常。但是,当我尝试在 windows 下的 gvim 中执行此操作时,它会“全选”(即突出显示或直观地选择当前窗口中的所有文本)。我怎样才能改变这种行为,或者我怎样才能恢复增量变量功能(例如,可能使用不同的键映射)?
采纳答案by Luc Hermitte
This is because of mswin.vim that is sourced by the default _vimrc generated when you install vim. Just override your _vimrc with the .vimrc you are using under *nix, or delete mswin.vim.
这是因为 mswin.vim 来自安装 vim 时生成的默认 _vimrc。只需使用您在 *nix 下使用的 .vimrc 覆盖您的 _vimrc,或者删除 mswin.vim。
回答by Matthew Strawbridge
I know I'm late to the party, but I thought I'd share the following:
我知道我参加聚会迟到了,但我想我会分享以下内容:
nnoremap <kPlus> <C-a>
nnoremap <kMinus> <C-x>
This remaps increment to the +key on the numeric keypad and decrement to the -key. It's the solution I've used in my own _vimrc
file on Windows. It keeps the Windows compatibility and is easier to remember than the original Ctrl+A/Ctrl+Xas well.
这将增量重新映射到+数字小键盘上的键并减量到-键。这是我_vimrc
在 Windows 上自己的文件中使用的解决方案。它保持了 Windows 兼容性,并且比原来的Ctrl+ A/ Ctrl+更容易记住X。
回答by Michael Madsen
Vim on Windows has specialized key mappings by default to make shortcuts more "windows-y". These are specified in the $VIMRUNTIME\mswin.vim file, which is loaded via your vimrc unless you disabled it. You can edit the mswin.vim file (you may want to edit a copy instead, changing your vimrc to use your edited copy instead).
默认情况下,Windows 上的 Vim 具有专门的键映射,以使快捷方式更“windows-y”。这些在 $VIMRUNTIME\mswin.vim 文件中指定,除非你禁用它,否则它会通过你的 vimrc 加载。你可以编辑 mswin.vim 文件(你可能想编辑一个副本,改变你的 vimrc 来使用你编辑过的副本)。
I'm not entirely sure it's a default Vim mapping, since the only reference I can find on Ctrl+A in the help file is this, which doesn't seem to do what you are referring to:
我不完全确定这是一个默认的 Vim 映射,因为我在帮助文件中的 Ctrl+A 上可以找到的唯一参考是这个,它似乎没有做你所指的:
*c_CTRL-A*
CTRL-A All names that match the pattern in front of the cursor are
inserted.
so you may want to check your Linux box to see if any plugins or anything change the key mapping. (Of course, it may be that I just can't find the appropriate part of the Vim help.)
所以你可能想要检查你的 Linux 框,看看是否有任何插件或任何东西改变了键映射。(当然,也可能是我找不到合适的 Vim 帮助部分。)
回答by SingleNegationElimination
in the current version of mswin.vim provided with gvim, the file checks for the value of a global named skip_loading_mswin
; If set, the rest of the file is skipped; thus it is sufficient to add
在 gvim 提供的当前版本的 mswin.vim 中,该文件检查名为skip_loading_mswin
;的全局变量的值。如果设置,则跳过文件的其余部分;因此足以添加
let skip_loading_mswin=1
to $HOME/_vimrc
and normal vim bindings will be restored the next time you start vim.
$HOME/_vimrc
下次启动 vim 时将恢复到和正常的 vim 绑定。
回答by PeerBr
If you just do not like CtrlAbehaviour but are fine with other windows behaviours in VIM (like CtrlZfor undo), just disable that specific line:
如果您只是不喜欢CtrlA行为,但对 VIM 中的其他 Windows 行为(例如CtrlZ撤消)感到满意,只需禁用该特定行:
- Edit said file (
c:\Program Files\Vim\vim73\mswin.vim
for me) - Find the paragraph starting with
CTRL-A is Select all
- Prepend all (6) lines of that paragraph with opening brackets (
"
) - Reopen your GVIM windows.
- 编辑上述文件(
c:\Program Files\Vim\vim73\mswin.vim
对我来说) - 找到以开头的段落
CTRL-A is Select all
- 在该段落的所有 (6) 行前加上左括号 (
"
) - 重新打开 GVIM 窗口。
You can still "select all" by typing ggVG
(position cursor at first line, select entire line, select until the last line of the document).
您仍然可以通过键入来“全选” ggVG
(将光标置于第一行,选择整行,选择直到文档的最后一行)。
Happy incrementing!
快乐递增!