5

I work almost exclusively in the terminal, and very often I need to view files that appear in error stacktraces. A very common format is /some/file:99, where 99 is the line number. I'd like to be able to copy that line, and open goto that line easily in vim.

What I'm looking for is the ability to do :e /some/file:99, and vim automatically opens that file at line 99. Does something like this exist? If not, is it possible to write a plugin for it?

Suan
  • 34,563
  • 13
  • 47
  • 61

4 Answers4

6

The edit command can take options, so try this:

:e +99 /some/file

Just found this link:

http://vim.runpaint.org/basics/opening-files/

You may prefix the filename with +linenumber to instruct Vim to jump to the given line after opening. For example, vim +7 todo.list or :e +100 treatise.txt. If you omit linenumber, i.e. you prefix the filename with +, Vim will jump to the end of the file.

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
  • Would it be possible to remap `:e /some/file:99` to `:e +99 /some/file`? Or would there be a better way to go about this? Though your solution is clean, its not much of an improvement for my use case over just opening the file then doing `:99` – Suan Aug 22 '11 at 22:02
  • Is the gf command what you're looking for? http://vim.wikia.com/wiki/Open_file_under_cursor – Luke Girvin Aug 22 '11 at 22:10
2

If you can redirect /some/file:99 to a file then you can jump to /some/file at line 99 by just pressing gF when you cursor is on file's name.

dimba
  • 26,717
  • 34
  • 141
  • 196
1

Where does this /some/file:99 comes from ? Is it the output of some external command ? If so, you should read the documentation related to the quickfix mode. (:h quickfix).

Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83
  • error/stacktrace outputs seem to have a pretty standard format of filepath:linenumber, that's where I got it from – Suan Aug 22 '11 at 21:57
  • @Suan: do you mean you have a file containing compilation errors open in Vim, and you want to jump to the relevant line of the file? – Luke Girvin Aug 22 '11 at 22:15
  • Then you'd better properly configure `'makeprg'`, and call `:make`. No need to use any plugin. This is a builtin feature. – Luc Hermitte Aug 22 '11 at 22:45
1

This plugin was designed with this specific purpose in mind: file:line

Randy Morris
  • 39,631
  • 8
  • 69
  • 76