Vim Tips Wiki

Editing

Filter buffer on a search result

1
  • The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit. If you are undoing an edit that is …
Latest revision Your text
Line 3: Line 3:
 
|previous=1556
 
|previous=1556
 
|next=1558
 
|next=1558
|created=2008
+
|created=April 22, 2008
 
|complexity=basic
 
|complexity=basic
 
|author=Niels AdB
 
|author=Niels AdB
Line 51: Line 51:
 
</pre>
 
</pre>
   
In Vim, the command <code>:source filter.vim</code> will execute the script.
+
In Vim, the command <tt>:source filter.vim</tt> will execute the script.
   
 
Assuming the default leader key (backslash), you can now:
 
Assuming the default leader key (backslash), you can now:
*Type <code>\f</code> and enter a pattern when prompted.
+
*Type <tt>\f</tt> and enter a pattern when prompted.
*Type <code>\F</code> to filter on the last search pattern.
+
*Type <tt>\F</tt> to filter on the last search pattern.
 
*Press Escape to close the scratch buffer listing the search hits.
 
*Press Escape to close the scratch buffer listing the search hits.
   
For example, you could put the cursor on a word and press <code>*</code> to search for the next occurrence of that word. If you now type <code>\F</code> a new window will open with a list of all lines that contain the word you searched for. Press Escape to close the window.
+
For example, you could put the cursor on a word and press <tt>*</tt> to search for the next occurrence of that word. If you now type <tt>\F</tt> a new window will open with a list of all lines that contain the word you searched for. Press Escape to close the window.
   
 
==Alternative procedures==
 
==Alternative procedures==
Line 69: Line 69:
 
</pre>
 
</pre>
   
The following will delete all lines that do not contain a pattern, leaving only the search hits. You could then press <code>u</code> to undo the changes.
+
The following will delete all lines that do not contain a pattern, leaving only the search hits. You could then press <tt>u</tt> to undo the changes.
 
<pre>
 
<pre>
 
:v/pattern/d
 
:v/pattern/d
Line 78: Line 78:
 
*[[Search_for_lines_not_containing_pattern_and_other_helpful_searches#Using_the_:v_command]] for some simple techniques to display lines of interest
 
*[[Search_for_lines_not_containing_pattern_and_other_helpful_searches#Using_the_:v_command]] for some simple techniques to display lines of interest
 
*[[VimTip478|Copy the search results into clipboard]] to copy matching patterns (not lines)
 
*[[VimTip478|Copy the search results into clipboard]] to copy matching patterns (not lines)
*[[VimTip1063|Redirect g search output]] uses <code>:redir</code> with <code>g//p</code> for a limited one-line version of this tip
+
*[[VimTip1063|Redirect g search output]] uses <tt>:redir</tt> with <tt>g//p</tt> for a limited one-line version of this tip
*[[VimTip1141|List lines with current search pattern highlighted]] defines command <code>PP</code> to highlight matches displayed with <code>:g//PP</code>
+
*[[VimTip1141|List lines with current search pattern highlighted]] defines command <tt>PP</tt> to highlight matches displayed with <tt>:g//PP</tt>
   
 
==Comments==
 
==Comments==
  Loading editor
Below are some commonly used wiki markup codes. Simply click on what you want to use and it will appear in the edit box above.

View this template