Vim Tips Wiki
(Change to TipImported template + severe manual clean)
(Move categories to tip template)
Line 9: Line 9:
 
|version=5.7
 
|version=5.7
 
|rating=38/16
 
|rating=38/16
  +
|category1=
  +
|category2=
 
}}
 
}}
 
Suppose you are using <tt>g/pattern/</tt> to display all lines containing some pattern in your file. When you are satisfied with the regex you are using for the pattern, you can press F3 to output the <tt>g/pattern/</tt> results to a new window.
 
Suppose you are using <tt>g/pattern/</tt> to display all lines containing some pattern in your file. When you are satisfied with the regex you are using for the pattern, you can press F3 to output the <tt>g/pattern/</tt> results to a new window.

Revision as of 08:57, 25 April 2008

Tip 1063 Printable Monobook Previous Next

created December 1, 2005 · complexity basic · author zzapper · version 5.7


Suppose you are using g/pattern/ to display all lines containing some pattern in your file. When you are satisfied with the regex you are using for the pattern, you can press F3 to output the g/pattern/ results to a new window.

To achieve this, you need the following map (place in your vimrc):

nmap <F3> :redir @a<CR>:g//<CR>:redir END<CR>:new<CR>:put! a<CR><CR>

Explanation:

:redir @a         redirect output to register a
:g//              repeat last global command
:redir END        end redirection
:new              create new window
:put! a           paste register a into new window

Comments

Send output of last g// to a named file (and open):

:nmap <F4> :redir! >/aaa/xz<CR>:g//<CR>:redir END<CR>:new /aaa/xz<CR><CR>

To not get line numbers printed if line numbers are turned on:

" before g//, store line number state and turn off line numbers; after g//, restore the previous state
:nmap <F3> :let @b=&number<CR>:set nonumber<CR>:redir @a<CR>:g//<CR>:redir END<CR>:let &number=@b<CR>:new<CR>:put! a<CR><CR>