简体   繁体   English

奇怪的行为:Vim 以命令行模式启动

[英]Weird behaviour: Vim starts in command line mode

My Vim (8.0) has started launching in command mode with the value :2R .我的 Vim (8.0) 已开始以命令模式启动,值为:2R

I keep my vimrc in a git repo, so I checked out previous commits until I got to a point where the weird behaviour stopped.我将我的 vimrc 保存在一个 git 仓库中,所以我检查了以前的提交,直到我发现奇怪的行为停止了。 The git diff between the last functioning commit and the first one with the error is simply:最后一个正常运行的提交和第一个出现错误的提交之间的 git diff 很简单:

diff --git a/.vim/common.vim b/.vim/common.vim
index a5b2443..bb209c3 100644
--- a/.vim/common.vim
+++ b/.vim/common.vim
@@ -13,27 +13,28 @@ noremap ( zz
 nnoremap Y y$

 " Find my way around inside text objects
-map [[ "_yaB
-map ]] "_yaB%
-map [b "_yab
-map ]b "_yab%
-map [d "_ya]
-map ]d "_ya]%
+noremap [[ "_yaB
+noremap ]] "_yaB%
+noremap [b "_yab
+noremap ]b "_yab%
+noremap [d "_ya]
+noremap ]d "_ya]%

-map [s (
-map }s )
+noremap [s (
+noremap ]s )

 " Various C-macros
-nmap <C-n> nzz
-nmap <C-a> W50i <Esc>B50ldwBj
-nmap <C-u> ElldwBj
-nmap <C-f> }?function<Enter>{jVN/{<Enter>%
+nnoremap <C-n> nzz
+nnoremap <C-a> W50i <Esc>B50ldwBj
+nnoremap <C-u> ElldwBj
+nnoremap <C-f> }?function<Enter>{jVN/{<Enter>%
 nnoremap <C-c> mwA;<Esc>`w
 nnoremap <C-o> mwO<Esc>0Dj`w
 nnoremap <C-.> mwo<Esc>0Dk`w

 " Give it back
-nnoremap <C-p> <C-o>
+nnoremap <C-[> <C-o>
+nnoremap <C-]> <C-p>

 " for search highlighting
 set hlsearch

How on earth would this change cause this behaviour?这种变化到底会如何导致这种行为?

Related: Strange symbol in vim command line after start suggests it's a misconfigured TERM environment variable, but I certainly didn't change that manually and comparing the output of env for the two commits shows no difference.相关: 启动后 vim 命令行中的奇怪符号表明它是一个错误配置的TERM环境变量,但我当然没有手动更改它,并且比较两次提交的env输出没有显示任何区别。

Edit: I traced it back to the line编辑:我将其追溯到该行

nnoremap <C-[> <C-o>

This must be a problem because I'm remapping the escape key.这一定是一个问题,因为我正在重新映射转义键。 I'm embarrassed I didn't think about that.我很尴尬,我没有想到这一点。

I still wonder how that could possibly manifest in the behaviour I saw, so any explanations would be welcome.我仍然想知道这怎么可能体现在我所看到的行为中,因此欢迎提供任何解释。

The Linux terminal uses ANSI escape sequences (ie strings of characters starting with <Esc> ) to send special keys to Vim, and as part of the communication protocol with which the application queries for its capabilities. Linux 终端使用 ANSI 转义序列(即以<Esc>开头的字符串)向 Vim 发送特殊键,并作为应用程序查询其功能的通信协议的一部分。 Your mapping interferes with that, and thereby leads to these "strange" behaviors.您的映射会干扰它,从而导致这些“奇怪”的行为。

Therefore, don't map <Esc> .因此,不要映射<Esc> Use another key.使用另一个键。 The problem is less pronounced in GVIM, but I wouldn't recommend it there, neither.这个问题在 GVIM 中不那么明显,但我也不推荐它。 If you absolutely want a mapping for <Esc> , only define it after Vim has fully started up, via :autocmd VimEnter * nnoremap <Esc> ...如果您绝对需要<Esc>的映射,请仅在 Vim 完全启动后定义它,通过:autocmd VimEnter * nnoremap <Esc> ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM