Tuesday, February 12, 2008

Super Fast way to open a file for vi at a given line

Sometimes, you know the line you want to edit in a file, and you just need to open the file and get to that line. For example, you just had done a grep -n, and found the line you want, say line 99 of a file.

Sure, you can vi the file, and then type 99G (capital G, that is), to get there.

A much faster way is enter this in the command prompt:

$ vi +99 some-file

The above opens some-file and go immediately to line 99.

5 comments:

Anonymous said...

Just what I was looking for, cheers!!

Anonymous said...

Good tip,
Saves some time in long run....
Will remember!!

Anonymous said...

Or just use the excellent vim script at http://www.vim.org/scripts/script.php?script_id=2184

Prashanth Y M said...

Command was Very helpful.

Thanks !!!

Mimouni Nataniel said...

Great ! Always wondered if there were a way to do this but never took time to look for it ... till today.
Glad I did.
Thanks