Vim Tips Wiki

We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 23: Line 23:
 
You can also type the search pattern on the command line. For example, <code>:Filter red\|blue</code> lists all lines that contain "red" or "blue".
 
You can also type the search pattern on the command line. For example, <code>:Filter red\|blue</code> lists all lines that contain "red" or "blue".
   
The command accepts zero or one argument (<code>-nargs=?</code>), and the argument replaces <code><args></code> where it occurs in the following. Register <code>a</code> is cleared (<code>let @a='&#39;</code>), then each matching line is appended to that register (<code>y A</code> performed on all matching lines by <code>g/pattern/</code>). A new window with a scratch buffer is created (<code>new | setlocal bt=nofile</code>), and the register is pasted before the blank line in the scratch buffer (<code>put! a</code>). When <code>:g/pattern/</code> is used, all following text is taken as a command to be executed on matching lines. Since only <code>y A</code> is wanted, the <code>execute</code> command is used as it stops at the bar.
+
The command accepts zero or one argument (<code>-nargs=?</code>), and the argument replaces <code><args></code> where it occurs in the following. Register <code>a</code> is cleared (<code>let @a='&#39;</code>), then each matching line is appended to that register ({{tt|y A}} performed on all matching lines by <code>g/pattern/</code>). A new window with a scratch buffer is created ({{tt|1=new &#124; setlocal bt=nofile}}), and the register is pasted before the blank line in the scratch buffer ({{tt|put! a}}). When <code>:g/pattern/</code> is used, all following text is taken as a command to be executed on matching lines. Since only {{tt|y A}} is wanted, the <code>execute</code> command is used as it stops at the bar.
 
Another way of working with search results is using <code>:vimgrep</code>. After the searching, do the following:
 
:vimgrep // %
 
The limitation of this approach is that you must be editing an existing file. However, the results will appear in a '''quick list'''. QuickList is a special vim buffer containing a list of file positions, with possibility to jump there. Its original purpose was to display the output of compilation, with possibility to jump to errors. Working with QuickLists is a whole separate topic on its own, so only a very quick intro here. QuickLists can be augmented, stacked and so on. QuickList window can be opened/closed with <code>:copen/:cclose</code> commands. Finally, QuickList can only be one for the whole vim session, while each window can have its own '''local''' location lists. Commands that work with local lists are very similar to quicklist commands, but usually start with "l" : <code>:vimgrep</code> -> <code>:lvimgrep</code>, <code>:copen</code> -> <code>:lopen</code> and so on ...
 
   
 
==Redirecting output==
 
==Redirecting output==

Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA

Cancel Editing help (opens in new window)