Mapping in vimrc causes bizarre arrow behaviour

后端 未结 5 1149
孤街浪徒
孤街浪徒 2020-11-30 09:53

I am a happy VIM user, although I admit I\'m quite far from being fluent. I found this nice post: Vim clear last search highlighting and I thought I\'d become a better perso

5条回答
  •  离开以前
    2020-11-30 10:40

    This solution preserves the ESC mapping to :nohlsearch.

    The comment on this answer explaining why this is happening tells us that the root cause is the TermResponse behavior of vim. This can be compensated for by wrapping the mapping in an autocommand for the TermResponse event.

    This ensures that the binding doesn't happen until after the term response is set, which prevents Esc from also sending a string like ]>1;3201;0c to vim.

    Change your line in vimrc to this:

    augroup no_highlight
        autocmd TermResponse * nnoremap  :noh
    augroup END
    

    The augroup commands are not strictly necessary, but they prevent multiple mappings when you reload your vimrc without quitting vim.

    EDIT: If you also use a graphical vim like Gvim or Macvim, the TermResponse event will not fire. Assuming you use a single vimrc, you'll need some additional code like

    if has('gui_running')
      nnoremap   :nohlsearch
    else
      " code from above
      augroup no_highlight
        autocmd TermResponse * nnoremap  :noh
      augroup END
    
    end
    

提交回复
热议问题