On Tue, 31 Jul 2012, Dotan Cohen wrote:
> On Tue, Jul 31, 2012 at 3:24 PM, Benjamin R. Haskell <vim@benizi.com> wrote:
>> " <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?
>>
>
> Thanks, Ben. The problem is that I cannot turn the feature off! That 
> was the question in the OP, with a different method of achieving the 
> same effect.
Ah.  I didn't understand that you wanted the feature to be completely 
eradicated, rather than just turned off (which toggling accomplishes).
> My ultimate goal is to be able to set specific words to be 
> highlighted, say toggling them with \hw (highlight word), and _also_ 
> to have the ablility to toggle highlight-word-under-cursor, say with 
> \hh.
Not sure quite what you want w/ the \hw portion, but for the \hh, put 
the autocmd in an augroup.  Probably not the most elegant VimL, but 
it'll work:
fun! EnableUnderCursorHighlighting()
   let g:under_cursor_hl_enabled = 1
   aug UnderCursorHighlighting
     au!
     au CursorMoved * if get(g:, 'under_cursor_hl', 1) | exe printf('match IncSearch /\V\<%s\>/', escape(expand('<cword>'), '/\')) | end
   aug END
   let g:under_cursor_hl = 1
   map <Leader>h let g:under_cursor_hl = 1 - g:under_cursor_hl
endf
fun! DisableUnderCursorHighlighting()
   unlet g:under_cursor_hl_enabled
   aug UnderCursorHighlighting
     au!
   aug END
   unmap <Leader>h
endf
fun! ToggleUnderCursorHighlighting()
   if exists('g:under_cursor_hl_enabled')
     call EnableUnderCursorHighlighting()
   else
     call DisableUnderCursorHighlighting()
   end
endf
map <Leader>hh call ToggleUnderCursorHighlighting()
-- 
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