function! PrintWithHighlighting()
let line = getline('.')
let ms = match(line, @/)
let me = matchend(line, @/)
while ms != -1
echohl none
echon strpart(line, 0, ms)
echohl Search
echon strpart(line, ms, me - ms)
echohl none
let line = strpart(line, me)
let ms = match(line, @/)
let me = matchend(line, @/)
endwhile
echon line . "\n"
Based on your input my final version (taking into account vim's number setting):
command! -nargs=? P :call PrintHighlighted(<q-args>)
function! PrintHighlighted(arg)
echo ""
if a:arg == "#" || &number
let l:lnum = line(".")
echohl LineNr
echon " " . repeat(" ", len(line("$")) - strlen(l:lnum)) . l:lnum . " "
echohl NONE
endif
let l:line = getline(".")
let l:pos = 0
while 1
let l:ms = match(l:line, @/, l:pos)
if l:ms == -1
echon strpart(l:line, l:pos)
return
endif
echon strpart(l:line, l:pos, l:ms - l:pos)
let l:me = matchend(l:line, @/, l:pos)
echohl MarkerBlue
echon strpart(l:line, l:ms, l:me - l:ms)
echohl NONE
if l:pos == l:me
echon strpart(l:line, l:me)
return
endif
let l:pos = l:me
endwhile
endfunction
--
--
You received this message from the "vim_dev" 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 a topic in the Google Groups "vim_dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_dev/V2vGo2CcHqU/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to vim_dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
How about using ‘:grep’ when searching through the entire file?
function! Grep(pattern)
exe 'grep ' . a:pattern
let @/ = substitute(a:pattern, '/\(.*\)/.*$', '\1', '')
copen
endfunction
command! -nargs=+ Grep call Grep(<q-args>) | set hls
cnoreabbrev grep Grep<Space>//<Space>%<C-Left><C-Left><Right><C-r>=Eatchar('\s')<CR>
(for Eatchar(), :helpgrep Eatchar )
I prefer Quickfix list more than ‘:print’ output. Just personal preference :)
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
Hi Barry!