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?


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.

  • 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 Aug 28 '13 at 2:56
  • You could also use +tabfirst. I've updated my answer to reflect this. Aug 28 '13 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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