computingFreedom | Build | Picolisp | Picolisp Machine | Pil Sources | Linux | BASH | C-Programmming | Operating Systems | Javascipt | Emacs | vim | Pharo Smalltalk | Computer Security | Python | The Compiler | Identifiers | Literals | storage_linkage | emacs | computing | vim notes
Goto line Vim
You your program crashes on line 282, how do you get there quickly?
If your in the file already use:
method 1
282G
method 2
282gg
method 3
:282<CR>
If you need to open the file on the command line, use:
$ vim +282 file
you can even try
$ vim +/symbolName file
and it will get you to the first place symbolName is found in the file.
The plain idea and why it matters
Jumping to a specific line is one of the most common things you do in an editor, especially when a compiler or stack trace says “error on line 282”. Vim gives you several quick ways to get there, both from inside the file and when first opening it, so you never scroll hunting for a line number.
The methods, explained
282Gand282ggboth jump to line 282.Gon its own goes to the end of the file,ggto the top; prefix either with a number to land exactly there.:282then Enter is the command-line way, the same mechanism scripts and plugins use.vim +282 fileopens the file already sitting on line 282, perfect straight from an error message.vim +/symbolName fileopens the file at the first match ofsymbolName, handy when you know what broke but not where.
A tip that pairs with these: turn on line numbers with :set number (or relative numbers with :set relativenumber), so the counts a compiler reports line up with what you see.
An everyday analogy
It is the difference between flipping through a book page by page and simply saying “page 282” to a librarian who opens it there instantly. The line number is the page number; these commands are how you tell Vim the page.
How it connects
- Vikid’s Vim Notes: the rest of my Vim tips.
- Linux: where you will most often meet Vim, on remote servers.
The truth revealed: the fastest way through a file is never to travel it at all, but to name your destination, and a good editor should take you straight there.
