Search code examples
vimremap

How do I stop my cursor from moving in vim when executing a :noremap?


I have a number of these in my .vimrc:

:noremap <F1> :set hls!<CR> :echo "hilight seach (hls) =" &hls<CR>

(It's nice to have things like autoindent, line numbering, ignorecase, etc., toggled at the press of a button.)

But there is one strange behavior when these actions are executed. The cursor moves to the right by one column. If I'm at the end of a line, the cursor moves to the beginning of the next line. Why is it doing this and how do I prevent it?

This is vim 7.3.429, but I also see it in 7.2.411.

Thanks


Solution

  • The problem is the space between the <CR> and the :echo. Remove it and it should work.

    :noremap <F1> :set hls!<CR>:echo "hilight seach (hls) =" &hls<CR>