Open Vim to a specific line
Sometimes I find it useful to open a file in Vim from my terminal to a specific line. Perhaps I know the line number in question because a colleague was referencing it. Or maybe I saw it in a stack trace. Vim can do this out of the box:
vim myfile.js +10– Opens myfile.js, jumps to line 10
vim +10 myfile.js– Same! Argument order doesn’t matter
This alone can be a useful trick. It works everywhere and requires no plugins. Yet it is still one keystroke more than just calling
:10 after the file opens to jump to the line.
If you’ve ever read a stack trace, you’ve probably seen file paths and line numbers written like this:
You may even see a column position amended like this:
Several solutions exist for opening a file to a specific line and column number when written in these formats. The one I use is called Vim-fetch and it supports both of these formats, and many more. Here’s a gif showing both methods, with and without plugin, in action:
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?