views:

267

answers:

2

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.

+7  A: 

Use the 'gf' shortcut. Move your cursor on the beginning of a path and then press gf in command mode, or Ctrl-o gf in insert mode. GF stands for "goto file". From help 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 command mode.

Thanks! This works great, except for when I open one file and then open another file . . I can't get back to the original. Still would be nice to be able to open into a new tab, but this is an improvement over the way I was working.
CMB
Great :) As glenn jackman said, to open the file in new window the gf shortcut should be proceeded by ctrl-w.
actually, ctrl+w gf opens the file in a new tab, exactly as CMB requested.
glenn jackman
You're right, I was thinking about tab when writing window. Thanks for correction.
+3  A: 

Put the cursor on the filename, then "Ctrl+w gf"

:he ctrl-w_gf

glenn jackman