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:

  1. Just what I was looking for, cheers!!

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

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

    ReplyDelete
  4. Command was Very helpful.

    Thanks !!!

    ReplyDelete
  5. 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

    ReplyDelete