Reputation: 11831
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
Upvotes: 1
Views: 168
Reputation: 45117
gpojd is correct the space is causing your movement issues. Perhaps you might be interested in a simpler toggle mappings?
nnoremap <f1> :set hls! hls?<cr>
nnoremap <f2> :set spell! spell?<cr>
nnoremap <f3> :set list! list?<cr>
Using set hls?
will display the current value of 'hlsearch'
. Because :set
can set multiple settings at once you are toggling the value and then asking for the current value to be displayed.
Upvotes: 1
Reputation: 23065
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>
Upvotes: 4