WezM.net Menu

Open Paths With Line Numbers in Vim

Published on Sun, 20 September 2015

I regularly encounter paths that have line numbers attached such as, ./spec/features/cases/edit_spec.rb:112, or src/fetcher.rs:543, and want to view or edit the file at the given line. For far too long I’ve been opening the file in vim and then jumping to the relevant line. This week I wrote a shell (zsh) function that does this automatically. It is simply called v and is used in place of vim to edit a file. E.g.

Animated GIF of v function in action


The source of the function is below. It was written for zsh but should be easy to adapt for other shells.

Comment icon Something to Add?

Contact me by email or Twitter if you have a comment, correction or just want to get in touch.