Tuesday, April 1, 2014

Re: how can I configure word highlighting in VIM ?

[Text re-ordered; please don't top-post]

Hi,

Arup Rakshit wrote:
>
> On Sun, Mar 30, 2014 at 8:12 AM, John Beckett <johnb.beckett@gmail.com <mailto:johnb.beckett@gmail.com>> wrote:
>>
>> Arup Rakshit wrote:
>> > Subject: how can I configure word highlighting in VIM ?
>>
>> If you mean by searching, I suggest starting here:
>>
>> http://vim.wikia.com/wiki/Searching
>>
>> See what it says (you know about "*"?), and scan down to the
>> "Highlighting search matches" link near the bottom. There are
>> also some search-without-moving ideas there somewhere.
>>
>> To just highlight, see:
>>
>> http://vim.wikia.com/wiki/Highlight_multiple_words
>
> I found this feature, long back in Notepad++. In that editor, if you
> select any word, it will highlight all occurrence of that word. It
> sometime helps to verify if at the line# 100 any variable I am using,
> it will confirm, if that was defined previously or not.

you can put the following lines in a script file in your plugins directory:

highlight default link CurrentWord IncSearch

function! s:HighlightCurrentWord(on)
if a:on
augroup HighlightCurrentWord
au CursorMoved,CursorMovedI * exe 'match CurrentWord /\<' . escape(expand('<cword>'), '\/.*$^~[]') . '\>/'
augroup END
else
augroup HighlightCurrentWord
au!
match NONE
augroup END
endif
endfunction

command! -bang HiCurWord call s:HighlightCurrentWord(expand('<bang>') != '!')

Then, if you execute ":HiCurWord", all occurences of the word under the
cursor will get highlighted. If you move the cursor to a different word,
the new word will get highlighted.

":HiCurWord!" switches highlighting off.

If you want to save some key strokes, define mappings like

nnoremap <F12> :HiCurWord<cr>
nnoremap <S-F12> :HiCurWord!<cr>

Regards,
Jürgen

--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: