On Tue, 31 Jul 2012, Dotan Cohen wrote:
> On Superuser I found this nice way to highlight the word under the
> cursor for the whole page:
> :autocmd CursorMoved * exe printf('match IncSearch /\V\<%s\>/', escape(expand('<cword>'), '/\'))
>
> http://superuser.com/questions/255024/vim-highlighting-a-search-term-without-moving-the-cursor
>
> I would like to enable / disable this feature, for instance on
> <leader>h. Is there any way to do this? I could write a function to
> set the option, but how to disable it afterwards, and how to check the
> state so that the same key could toggle?
" <Leader>h toggles the under-cursor highlighting
:map <Leader>h let g:under_cursor_hl = 1 - get(g:, 'under_cursor_hl', 1)
" Use it in the CursorMoved autocmd
:autocmd CursorMoved * if get(g:, 'under_cursor_hl', 1) | exe printf('match IncSearch /\V\<%s\>/', escape(expand('<cword>'), '/\')) | end
Or am I missing something?
--
Best,
Ben
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Tuesday, July 31, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment