Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jumping to a file that is listed in Vim

Tags:

vim

In Vim you can use the [I command to list all of the locations where a specified function, class or struct is declared or used. Is there a simple shortcut to open one of the files in this resulting list in Vim? I'd prefer not to have to type in the full filename and line number.

like image 790
user809409 Avatar asked Jun 21 '11 23:06

user809409


People also ask

How do I navigate to a file in Vim?

You can also use keyboard arrow keys for navigation in a file. You can also repeat the operation for N times in Vim. For example, if you want to move down by 5 lines, then write '5j'. Vim also allows users to navigate in a file to other positions instead of only the upward or download.

How do I go to a previous match in vim?

Basic searching Type ggn to jump to the first match, or GN to jump to the last.

How do I jump to a specific line in Vim?

If we are in the vim editor, then simply do this, “Press the ENTER key, write the Line number, and press Shift+ g”: Again the output is the same.


1 Answers

I remembered the old gF trick, that works great.

Shameless rip from vim tips:

The following commands open the file with the cursor on the specified line number:

gF   open in the same window
<c-w>F   open in a new window (Ctrl-w F)
<c-w>gF  open in a new tab (Ctrl-w gF)

When such file-name/line number pairs are the result of compiling code, the following commands are also useful:

:help :cn
:help :cl
:help :cfile

The file:line plugin allows you to use combinations of file name and line number, like global.h:123, as an argument to Vim. When you open file:line, the script checks if file exists and line is a number. If so, Vim opens file at the correct line line number.

like image 182
stefgosselin Avatar answered Oct 11 '22 03:10

stefgosselin