How do I open a file and jump directly to a specific line or pattern?
Answer
:e +{line} {file}
Explanation
The :edit command accepts a +{cmd} prefix that executes an Ex command immediately after the file is loaded. The most common use is +{line} to jump to a line number, but any Ex command works — including searches, marks, and substitutions.
How it works
:e +100 foo.c— openfoo.cat line 100:e +/pattern foo.c— openfoo.cand jump to the first match ofpattern:e +$ foo.c— openfoo.cand jump to the last line:e +"call cursor(50,12)" foo.c— open at a specific line and column
The +{cmd} syntax also works with :split, :vsplit, :tabedit, and even the vim CLI (vim +100 file.txt).
Example
You see a compiler error referencing src/parser.c:247. Open straight to it:
:e +247 src/parser.c
Or jump to the definition of a function:
:e +/^int\ parse_token src/parser.c
Tips
- Chain with
:spand:vsto open files in splits at a specific position::sp +/TODO notes.txt - The
+{cmd}option can include any single Ex command; for multiple commands chain with|::e +"set ft=python | normal G" scratch.py - Useful for scripting workflows where you want to open related files at a known position