Hi,

Paul wrote:
>
> Often I'll want to see a list of lines that contain a pattern. I'll do
> ':g/pattern/', sometimes followed by # if I want the line numbers.
> Sometimes I'd like to see where in the line the pattern matched, so,
> is there a way to have the output of :g// highlight the pattern?

this is almost completely untested (especially for corner cases):

    function! PrintWithHighlighting()
        let line = getline('.')
        let ms = match(line, @/)
        let me = matchend(line, @/)

        if ms != -1
            echohl none
            echo strpart(line, 0, ms)
            echohl Search
            echon strpart(line, ms, me - ms)
            echohl none
            echon strpart(line, me, strlen(line))
        else
            echo line
        endif
    endfunction

    command! P call PrintWithHighlighting()

Use it like

    :g/your pattern/P

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

Reply via email to