tags:

views:

1384

answers:

8

I have a longish list of files opened in vim that looks like this:

/dir1/file1
/dir2/file2
/dir2/file3
.....

How can I open all of them one by one the easiest way possible in the same session of vim either with split or edit?

+2  A: 

You can do the following

cat file | xargs vim

Where "file" contains your list of files, this will open the files in the same vim session. As usual when opening multiple buffers, you can navigate forward with :bn and backward :bp.

ng
..Unless the number of files is greater than xargs's split threshold, in which case you'll get multiple vim sessions.
Paul Tomblin
Using xargs you can handle tens of thousands of files, are you suggesting typing these one by one on the command line like you have suggested, this seems a lot less practical.
ng
@ng, you don't understand xargs at all. If you pass "tens of thousands of files" to it, it will issue the vim command for the first 20, then issue another vim command for the second 20, and so on.
Paul Tomblin
+7  A: 

I'd say with -p for tabs

vim -p `cat yourlistoffiles`
Ronny
A: 

Maybe this could help:

http://vimdoc.sourceforge.net/htmldoc/windows.html

Ubersoldat
A: 

It's as simple as typing

vim /dir1/file1 /dir2/file1 /dir2/file2 ...

Once you're in vim, you can switch betwen then with ":n" to go to the next file, ":prev" to go to the previous file.

Paul Tomblin
This is not what was asked, the question is how to open a long list of files.
ng
@ng, the question is exceptionally ambiguous.
Paul Tomblin
+4  A: 

I'm going to assume you have the file list open inside Vim, and want to simulate the "gf" command across the whole list...

Edit your .vimrc to include this function:

function Openall()
    edit <cfile>
    bfirst
endfunction

You can then highlight the entire file (or the set of paths you want to open) using visual mode (1G, Shift-V, G) and typing ":call Openall()". Afterwards the command row will show this:

:'<,'>call Openall()

This will run the new Openall() function across all highlighted lines.

Press Enter and all the files will be opened in background buffers. You can then access them using the usual buffer commands. :ls will display them as a list.

seanhodges
A: 

My searchInRuntime plugin has a :Sp and a :Vsp commands that'll do the trick when called banged. However, the files have to exist.

Luc Hermitte
A: 

You can use quickfix mode, as following

:set errorformat=%f
:cf myfilelist

at this point you can use the normal quickfix shortcuts to go through your files, :cn for the next file, :cp for the previous one and :cr to go to the first again.

EDIT:

oh, if you want to read the list from the current buffer, use :cb instead of :cf in in the instructions above

Hasturkun
A: 

Try:

with bash$ vim -S <(sed "s/^/badd /" <your file name>)

But I don't know why the first line of the file is ignored... :-O

This script works as expected:

rm -f myfile
for i in `seq 10000`
do
  touch $i
  echo $i >> myfile
done
vi -c "badd `head -1 myfile`" -S <(sed "s/^/badd /" myfile)


http://vimdoc.sourceforge.net/htmldoc/starting.html#-S
http://vimdoc.sourceforge.net/htmldoc/windows.html#:bad

Banengusk