这个映射有什么问题?Vim在-- REPLACE --模式下启动。

9

自从我上次更新了.vimrc后,我的vim遇到了一个奇怪的bug。

每次启动vim时,它都会以-- REPLACE --模式启动,这真的很烦人。

我成功地发现,是我的.vimrc中的这行代码导致了问题。

" Disable search highlighting temporally
nnoremap <esc> :nohl<cr>

如果我注释掉这一行,问题就消失了。

我真的很困惑这个映射有什么问题。它按照预期工作,但会导致 vim 在启动时进入 -- REPLACE -- 模式。

目前我没有启用任何插件。


那一行不在你的.vimrc文件中... - 1983
@wefwef:还可以查看vi.SE - 0xC0000022L
@0xC0000022L 我已经等待了很长时间! - wefwefa3
3个回答

12
我曾经遇到过同样的问题,尽管我使用tmux,但当我启动vi(即vim)时,它会以替换模式启动。罪魁祸首似乎是我一直在使用的TERM的TERMCAP定义:xterm-256color。
一旦我将TERM设置为其他值,vi(vim)就能正常工作了。即使是"ansi"的TERM设置表现得更好。
我最终选择了一个TERM设置为"screen-256color-s",这正是我所需要的。
与TERMCAP定义有趣的玩法。

我在使用WSL上的Ubuntu时遇到了这个问题。这个方法对我有用。谢谢。 - NanoNi

7

1

我通过将以下内容添加到我的vimrc文件中来解决了同样的问题:

" Terminal fixes
"
" These originate from some linux distribution's system vimrc. I can't say
" that I understand the details what's going on here, but without these
" settings, I've had problems like vim starting in REPLACE mode for
" TERM=xterm-256color (neovim is fine)

if &term =~? 'xterm'
    let s:myterm = 'xterm'
else
    let s:myterm =  &term
endif
let s:myterm = substitute(s:myterm, 'cons[0-9][0-9].*$',  'linux', '')
let s:myterm = substitute(s:myterm, 'vt1[0-9][0-9].*$',   'vt100', '')
let s:myterm = substitute(s:myterm, 'vt2[0-9][0-9].*$',   'vt220', '')
let s:myterm = substitute(s:myterm, '\\([^-]*\\)[_-].*$', '\\1',   '')

" Here we define the keys of the NumLock in keyboard transmit mode of xterm
" which misses or hasn't activated Alt/NumLock Modifiers.  Often not defined
" within termcap/terminfo and we should map the character printed on the keys.
if s:myterm ==? 'xterm' || s:myterm ==? 'kvt' || s:myterm ==? 'gnome'
    " keys in insert/command mode.
    map! <ESC>Oo  :
    map! <ESC>Oj  *
    map! <ESC>Om  -
    map! <ESC>Ok  +
    map! <ESC>Ol  ,
    map! <ESC>OM  
    map! <ESC>Ow  7
    map! <ESC>Ox  8
    map! <ESC>Oy  9
    map! <ESC>Ot  4
    map! <ESC>Ou  5
    map! <ESC>Ov  6
    map! <ESC>Oq  1
    map! <ESC>Or  2
    map! <ESC>Os  3
    map! <ESC>Op  0
    map! <ESC>On  .
    " keys in normal mode
    map <ESC>Oo  :
    map <ESC>Oj  *
    map <ESC>Om  -
    map <ESC>Ok  +
    map <ESC>Ol  ,
    map <ESC>OM  
    map <ESC>Ow  7
    map <ESC>Ox  8
    map <ESC>Oy  9
    map <ESC>Ot  4
    map <ESC>Ou  5
    map <ESC>Ov  6
    map <ESC>Oq  1
    map <ESC>Or  2
    map <ESC>Os  3
    map <ESC>Op  0
    map <ESC>On  .
endif

https://gist.github.com/goerz/36015f27c2a5423c64a5f9dc03865f2c中还有更多类似的设置,可能也会有所帮助。根本原因是termcap/terminfo中有些问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接