The VikiD Truth

Knowledge base / Computing / Tools & dev workflow

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.

back to vim notes

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

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

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.

Last edited · 4 revisions

Tags: #Computing