> I'm not sure what this is supposed to look like. I put it in
> my .vimrc (after unwrapping the line) and opened another
> file, set hls and did a search. All search results looked
> exactly as they do normally, even after specifically :so'ing
> my .vimrc again...
After moving the cursor (say with n to find next occurrence),
you should see the current search hit highlighted with a
DarkOrange background, while other hits are highlighted with
a Yellow background (if you have the default Search highlight
group).
The 'b:xxx' variables should be 'w:xxx', and I have started
playing with the script because it has an irritating feature:
if you search for "the" then it works nicely, but when you use
:noh to turn off highlighting, the first "the" after the cursor
(on the cursor line) will be highlighted with DarkOrange.
I haven't given it serious attention yet, but here is what I
came up with to make it somewhat usable (still needs work).
This is based on the idea by Matt Wozniski 2010-02-24.
I put the script in file highlight-current.vim in my plugin
directory. Some lines will wrap.
---start---
" Highlight current search hit so can easily see it if many hits.
if v:version < 702 || exists('loaded_highlightcurrent') || &cp
finish
endif
let loaded_highlightcurrent = 1
highlight SearchCurrent guifg=black guibg=DarkOrange
function! s:SetHighlightCurrent(enable)
if a:enable
augroup highlight_current
autocmd!
autocmd CursorMoved * silent call s:HighlightCurrent(1)
augroup END
call s:HighlightCurrent(1)
else
autocmd! highlight_current
call s:HighlightCurrent(0)
endif
endfunction
function! s:HighlightCurrent(show)
if exists('w:searchmatch')
" Ignore any error because user might have cleared all matches.
silent! call matchdelete(w:searchmatch)
unlet w:searchmatch
endif
if a:show && !empty(@/)
let beg = searchpos(@/, 'cnW', line('.'), 100)
if beg != [0, 0]
let end = searchpos(@/, 'cenW', line('.'), 100)
if end != [0, 0]
let w:searchmatch = matchadd('SearchCurrent', printf('\%%%dl\%%%dc\_.*\%%%dl\%%%dc.', beg[0], beg[1], end[0], end[1]))
endif
endif
endif
endfunction
call s:SetHighlightCurrent(1)
nnoremap <silent> <Space> :nohlsearch<Bar>:call <SID>SetHighlightCurrent(0)<Bar>:echo<CR>
nnoremap <silent> <S-Space> :set hlsearch<Bar>:call <SID>SetHighlightCurrent(1)<Bar>:echo<CR>
" Could remap n and N so they enable highlight current.
" nnoremap <silent> n n:call <SID>SetHighlightCurrent(1)<CR>
" nnoremap <silent> N N:call <SID>SetHighlightCurrent(1)<CR>
---end---
After searching, pressing Space will clear all search
highlights. Press Shift-Space to enable the DarkOrange
highlighting of the current hit.
John
--
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
No comments:
Post a Comment