23

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 5 '12 at 12:48
19

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

| improve this answer | |
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##*:}; }
| improve this answer | |
  • Sorry this is not accurate: What if you had a file called +11? You can, of course, use -- for that. – Sardathrion - against SE abuse Oct 5 '12 at 7:44
  • 2
    You can edit a +11 file by saying vim ./+11 – Julian Oct 5 '12 at 7:47
3

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

Plugin 'bogado/file-line'
| improve this answer | |
  • @Sardathrion: Which issues do you have? – Dorian Oct 14 '16 at 0:13
  • I moved to neovim and there are lots of issues that mark other modules (or whatever neovim calls them) as incompatible. – Sardathrion - against SE abuse Oct 14 '16 at 6:50
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"'
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.