2

Using vim I can open multiple tabbed files using the -p switch:

$ vim -p file1 file2 file3

Using vim I can open a file at a particular line:

$ vim file1 +123

How can I open multiple files in tabs, each at their own distinct line?

1 Answer 1

7

This will do it: vim +123 file1 +"tabnew +20 file2"

As mentioned in the comments, you can continue adding files in using the same syntax:

vim +123 file1 +"tabnew +20 file2" +"tabnew +40 file3" +"tabnew +10 file4"

user74094 made the point that unfortunately this opens to the last tab rather than the first. This can be fixed with the addition of tabfirst as such:

vim +123 file1 +"tabnew +20 file2" +tabfirst

For anyone who doesn't understand, a + means vim executes a new command. So this is essentially saying, "open vim to line 123 on file1, then open a new tab with file2 to line 20, then switch to the first tab"

Original answer/research taken from here.

4
  • Thanks. A bit verbose; and it opens on the rightmost file rather than the leftmost with -p; but I suppose it gets the job done!
    – user74094
    Commented Aug 27, 2013 at 22:10
  • By the way, 3 files would look like this: vim +123 file1 +"tabnew +456 file2" +"tabnew +789 file3"
    – user74094
    Commented Aug 27, 2013 at 22:11
  • You could always add +tabprev after each file. It gets a bit messy, although I'm sure you could write a bash script that would make it cleaner and more usable: `vim +123 file1 +"tabnew +20 file2" +tabprev Commented Aug 28, 2013 at 2:56
  • You could also use +tabfirst. I've updated my answer to reflect this. Commented Aug 28, 2013 at 3:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .