Vim : Open multiples files on different lines

Here's a way : vim +6 file1 +"sp +3 file2". Change sp to tabnew if you prefer tabs.

But it would be really useful only if someone could make a script with it...


I just wrote https://gist.github.com/xim/6123691

Thanks to Pikrass for the idea =)

EDIT:

As claferri says, using '+tabnew ...' limits you to 10 files. Updated the gist to use -S.

The vim function will build a string ($script) containing a vim script that opens the files, at appropriate lines, in tabs. Explaining using an example, this is done by changing vim -R file1:42 file2 file3:1337 to vim -S <script> -R file1 file2 file3 – containing a vim script, in this case:

tab all
tablast
1337
tabprev
tabprev
42

So: we are opening the files normally, then executing the script: Jumping to the last tab, then jumping to the appropriate line for each file while moving towards the first file.

This hack is only moderately tested, comment on any errors.

RE-EDIT:

Fixed the script so even a crazy example like vim -R 1:3 "a file" foo -- -- "some other file":34 -R works as expected.


Another option would be using a script like utl, automatically creating a file full of hyperlinks to the file / line numbers based on the output of gcc (this should be trivial with sed).

A link would be formatted like this with utl: <url:error.c#line=10>

EDIT: linked to a more appropriate vim linking script.


vim can read your gcc output and create a quickfix list that allows you to navigate easily though all the errors in your code. You can read an existing error file using vim -q or if your project uses a Makefile then you can use the :make command to execute make from within vim and capture its output.

Tags:

Vim