CMB
CMB

Reputation: 4145

Easily open include filenames in vim?

Basically, I'm editing files that have include file names and I want a quick way of opening the file without having to type the path/filename:

include('inc/doctype.inc.php');

Is there an easy way to do this? (Ideally, I'd like to use :tabnew to open the file in a new tab.)

Thanks.

Upvotes: 5

Views: 4851

Answers (2)

anon
anon

Reputation:

Use the gf shortcut. Move your cursor on a path string, the exact cursor position is not important and then press gf in normal mode. gf stands for "goto file".
See vims help page with :h gf:

Uses the 'isfname' option to find out which characters are supposed to be in a file name. Trailing punctuation characters ".,:;!" are ignored. Uses the 'path' option as a list of directory names to look for the file. Also looks for the file relative to the current file. Uses the 'suffixesadd' option to check for file names with a suffix added. If the file can't be found, 'includeexpr' is used to modify the name and another attempt is done.

To get back, use Ctrl-o in normal mode.
Note: This command brings the cursor position to older positions in the jump list. The opposite command is Ctrl-i which brings the cursor to newer positions in the jump list.

Upvotes: 15

glenn jackman
glenn jackman

Reputation: 246877

Put the cursor on the filename, then Ctrl+wgf

:h ctrl-w_gf

Upvotes: 5

Related Questions