user3675188
user3675188

Reputation: 7409

How to open a file and anchor to dedicated line number with vim

My log always shows errors in this way:

lib/rails/rack/logger.rb:38

Can I copy the above line then open the file with vim and move to line 38?

Upvotes: 1

Views: 689

Answers (3)

Ingo Karkat
Ingo Karkat

Reputation: 172520

Have a look at the file:line - Allows you to open file:line and it does the right thing plugin; it sets up autocmds to handle those, so you can pass your path/to/file:lnum directly to Vim on the command line and :edit such, too!

Upvotes: 3

Gilles Quénot
Gilles Quénot

Reputation: 185025

You could put this function in your (bash ?) rc file :

vimtoline(){ IFS=: read -r f l <<< "$1"; vim "$f" +"$l"; }

then

vimtoline lib/rails/rack/logger.rb:38

will do the trick.

Thanks to chepner for the enhancement.

Upvotes: 0

Mureinik
Mureinik

Reputation: 311163

You can open a file in vim and jump to a specific line by using the + syntax:

vi lib/rails/rack/logger.rb +38

Upvotes: 3

Related Questions