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

有帮助吗?

解决方案

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>

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top