Vim Tips Wiki
Register
(Fix typos)
(Remove html character entities)
 
Line 14: Line 14:
 
Following is a ''big'' timesaver if you need to open lots of files.
 
Following is a ''big'' timesaver if you need to open lots of files.
   
Assume you have a text file containing filenames with or without paths (created by for instance 'grep -Erl "^" * > files.txt'). Following opens all these files in the same vim.
+
Assume you have a text file containing filenames with or without paths (created by for instance 'grep -Erl "^" * > files.txt'). Following opens all these files in the same vim.
   
 
Assuming that only this text file is opened:
 
Assuming that only this text file is opened:
Line 21: Line 21:
   
 
<pre>
 
<pre>
q0gf:rew&lt;CR&gt;&lt;DOWN-ARROW&gt;q
+
q0gf:rew<CR><DOWN-ARROW>q
 
</pre>
 
</pre>
   
 
This loads the file on the first line, and creates macro '0'.
 
This loads the file on the first line, and creates macro '0'.
   
Check the number of lines with &lt;CTRL-g&gt; and subtract one for the first line. Type this value, then:
+
Check the number of lines with <CTRL-g> and subtract one for the first line. Type this value, then:
   
 
<pre>
 
<pre>
Line 38: Line 38:
   
 
<pre>
 
<pre>
bash&gt; gvim $(grep -l *.* string)
+
bash> gvim $(grep -l *.* string)
 
</pre>
 
</pre>
   
Line 44: Line 44:
   
 
<pre>
 
<pre>
bash&gt; grep -n *.* string &gt; list
+
bash> grep -n *.* string > list
bash&gt; vim -q list .. you can visit each file:line with :cnext, :cprev
+
bash> vim -q list .. you can visit each file:line with :cnext, :cprev
 
</pre>
 
</pre>
   
Line 51: Line 51:
   
 
<pre>
 
<pre>
bash&gt; find . -name *.* | xargs grep -l string | vim -
+
bash> find . -name *.* | xargs grep -l string | vim -
 
</pre>
 
</pre>
   
Line 66: Line 66:
 
</pre>
 
</pre>
   
Last command may be replaced with typing :cfile &lt;c-r&gt;%&lt;cr&gt;
+
Last command may be replaced with typing :cfile <c-r>%<CR>
   
 
Now you may navigate through these files using copen, cnext, cNext, cfirst, clast.
 
Now you may navigate through these files using copen, cnext, cNext, cfirst, clast.

Latest revision as of 09:31, 29 September 2008

Tip 837 Printable Monobook Previous Next

created December 21, 2004 · complexity basic · author Wim Rijnders · version 5.7


Following is a big timesaver if you need to open lots of files.

Assume you have a text file containing filenames with or without paths (created by for instance 'grep -Erl "^" * > files.txt'). Following opens all these files in the same vim.

Assuming that only this text file is opened:

Set the cursor on the first line. In normal mode, type:

q0gf:rew<CR><DOWN-ARROW>q

This loads the file on the first line, and creates macro '0'.

Check the number of lines with <CTRL-g> and subtract one for the first line. Type this value, then:

@0

This loads the remaining files.

Comments[]

How about:

bash> gvim $(grep -l *.* string)

Or

bash> grep -n *.* string > list
bash> vim -q list .. you can visit each file:line with :cnext, :cprev

Or

bash> find . -name *.* | xargs grep -l string | vim -

No macro, it is all builtin.


Returning to original tip: "Assume you have a text file containing filenames with or without paths". Very easy and elegant way to run through these files is the following (supposing there is no spaces around filenames):

Open the file then enter:

:setlocal efm=%f
:execute 'cfile '.expand('%')

Last command may be replaced with typing :cfile <c-r>%<CR>

Now you may navigate through these files using copen, cnext, cNext, cfirst, clast.