简体   繁体   English

psearch 的奇怪行为 (Vim)

[英]Weird behaviour with psearch (Vim)

So this is a part of my .vimrc所以这是我的.vimrc的一部分

" Mapping
nnoremap <F3> :cclose<cr>
nnoremap <F4> :w <bar> !cd ../build; make<cr><cr>:cw<cr>
autocmd filetype cpp nnoremap <F6> :Termdebug %:r<CR><c-w>2j<c-w>L
nnoremap <F12> :!cd ..; !ctags -R 
"nnoremap <C-[> :psearch <C-R><C-W><CR>
nnoremap <C-H> <C-W>h
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-L> <C-W>l
inoremap <C-H> <Left>
inoremap <C-J> <Down>
inoremap <C-K> <Up>
inoremap <C-L> <Right>
nnoremap <esc><esc> :silent! noh<cr>
inoremap " ""<left>
inoremap ' ''<left>
inoremap ( ()<left>
inoremap [ []<left>
inoremap { {}<left>
inoremap {<CR> {<CR>}<ESC>O
inoremap {;<CR> {<CR>};<ESC>O

As you can see I have a line commented, which I think is giving me some problems.如您所见,我注释了一行,我认为这给我带来了一些问题。 When that is not commented and I open vim this is what I got:当没有评论时,我打开 vim 这就是我得到的:

截屏

A preview windows of the actual file is opened and I get into replace mode, also there are more weird behaviour, for example if I am in insert mode and I press <Esc><Esc> and press some arrow key vim insert a D or an U (as you can imagine depend on which key I press)实际文件的预览 windows 打开,我进入替换模式,还有更多奇怪的行为,例如,如果我在插入模式下,我按<Esc><Esc>并按一些箭头键 vim 插入 D 或一个 U(你可以想象取决于我按的是哪个键)

You got this problem because <C-[> has the same keycode as ESC .您遇到此问题是因为<C-[>具有与ESC相同的键码。

:h keycodes

then you search for "esc", you will find both have keycode 27. That is, you mapped ctrl-[ , in fact, you mapped ESC .然后你搜索“esc”,你会发现它们的键码都是27。也就是说,你映射了ctrl-[ ,实际上你映射了ESC

In INSERT mode, when you pressed ESC twice, the first ESC brings you back to NORMAL mode, and the 2nd ESC triggers your mapping, the :psearch command.在 INSERT 模式下,当您按 ESC 两次时,第一个 ESC 将您带回 NORMAL 模式,第二个 ESC 触发您的映射,即:psearch命令。

Also when you press ESC in normal mode, the mapping is gonna be triggered as well.此外,当您在正常模式下按 ESC 时,映射也会被触发。

The solution is also easy, don't map <C-[> .解决方案也很简单,不要 map <C-[>

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

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