0

tl;dr: Any ideas on how to have the esc key map to :noh and the mouse=a working, but at the same time without breaking vim completely?

I added the following lines to my .vimrc file:

nnoremap <esc> :noh<return><esc>

as suggested by:

Vim clear last search highlighting

though, I have the following also on:

:set mouse=a

I am not sure why but now whenever I start vim, it starts by trying to do a :noh command without me telling it. Furthermore, if I try clicking on my vim screen it just decides to replace everything from line 1 to wherever I clicked with an empty space. I am also in insert mode automatically after the click. Even after get out of it and start trying to edit normally, the mouse click is completely messed up, I'm not even sure what its doing.

I am using iTerm2 in mac OS X. I am also using the z shell and oh-my-zsh.

Here is how my .vimrc file looks like:

"
""disabiling arrows
"
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>

" ---
filetype off
call pathogen#infect()
call pathogen#helptags()

let g:gofmt_command = 'goimports'
autocmd BufWritePre *.go Fmt
" ---

:syntax on
:set mouse=a
:set nu
:set hlsearch
nnoremap <esc> :noh<return><esc>

"
filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on
"

Any ideas on how to have the esc key map to :noh and the mouse=a working, but at the same time without breaking vim completely?

A possible solution might be to map :noh to some other key or sequence of keys that are safer. I am not sure which one might be a good idea, but if someone has one that makes sense, I would be happy to hear suggestions!

Community
  • 1
  • 1
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
  • just found something that might answer this at: http://stackoverflow.com/questions/11940801/mapping-esc-in-vimrc-causes-bizzare-arrow-behaviour – Charlie Parker Jun 16 '14 at 17:02
  • the solution that I have is nnoremap :noh: to also delete the :noh that is written at the bottom. However, I am also interested in other suggestion and understanding why mouse=a was screwed up with the short-cut. – Charlie Parker Jun 16 '14 at 17:58
  • 1
    I think xterm uses escape sequences to send mouse events. So vim starts interpreting thing incorrectly. As for your solution, if you use `` in the mapping `:noh` won't show up at the bottom. – FDinoff Jun 16 '14 at 18:42
  • I am not sure what you mean by "use ", do you ming writing the command that should be done? thnx btw – Charlie Parker Jun 16 '14 at 18:57
  • 1
    Not tested but I meant adding `` after nnormeap. `nnoremap :noh` – FDinoff Jun 16 '14 at 19:05

0 Answers0