Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make vim recognize line numbers at end of filenames?

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?

like image 821
Suan Avatar asked Aug 22 '11 21:08

Suan


People also ask

How do I turn on line numbers in vim?

Vim can display line numbers in the left margin: Press ESC key. At the : prompt type the following command to run on line numbers: set number. To turn off line numbering, type the following command at the : prompt set nonumber.

How do I find the current file name and number of lines in Vim?

Pressing ctrl-g will reveal the filename, current line, the line count, your current position as a percentage, and your cursor's current column number.


3 Answers

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.

like image 186
Luke Girvin Avatar answered Oct 15 '22 04:10

Luke Girvin


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.

like image 2
dimba Avatar answered Oct 15 '22 04:10

dimba


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

like image 1
Randy Morris Avatar answered Oct 15 '22 04:10

Randy Morris