30

Several tools such as grep, py.test, etc ... use the pattern <FileName>:<line number>: to point to errors. For example:

; grep -Hn Common setup.cfg
setup.cfg:11:    Common

How can I modify vim and gvim so that I can invoke them like so:

gvim setup.cfg:11:

instead of

gvim setup.cfg +11

I know that I can write a small shell script that would parse things but I wonder if there is an easier way.

  • 2
    This isn't exactly analogous, but vim does have a feature to load the output from grep or (for example) compiler errors from make, and navigate between them. See `:help quickfix` for more info. – Random832 Oct 05 '12 at 12:48

4 Answers4

20

You can use the file:line plugin available here, which does exactly what you want...

mmigdol
  • 316
  • 2
  • 3
  • 1
    It sure does and with the added bonus that you can use [vundle](https://github.com/vim-scripts/vundle) to install it. – Sardathrion - against SE abuse Jun 25 '15 at 06:53
  • 3
    The references [file-line](https://github.com/bogado/file-line) plugin has some issues, including brokeness when tab pages are in use. [vim-fetch](https://github.com/kopischke/vim-fetch) does what file-line does, but better. – Lekensteyn Jul 16 '15 at 09:06
9

There isn't a way, and I think a script is the only way. The reason being, what if you had a file called setup.cfg:11 and wanted to edit it?

Here is a quick script that does what you want as a oneliner...

editline() { vim ${1%%:*} +${1##*:}; }
Julian
  • 899
  • 5
  • 5
3

With Vundle.vim, add this to your .vimrc:

Plugin 'bogado/file-line'
Dorian
  • 131
  • 4
0

You can also use such alias:

alias gd 'set number=`echo \!:1 | perl -pe "s/([0-9]*:)?(.+)[,:]([0-9]+).*/\3/"`; set file=`echo \!:1 | perl -pe "s/([0-9]*:)?(.+)[,:]([0-9]+).*/\2/"`; eval "if ($number == $file) then \\
   gvim $file \\
else \\
   gvim $file +$number \\
endif"'