Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
    
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 Aug 27 '13 at 22:10
    
By the way, 3 files would look like this: vim +123 file1 +"tabnew +456 file2" +"tabnew +789 file3" –  user74094 Aug 27 '13 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 –  Andrew White Aug 28 '13 at 2:56
    
You could also use +tabfirst. I've updated my answer to reflect this. –  Andrew White Aug 28 '13 at 3:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.