Vim Tips Wiki
(Merge in 1075; reword; remove author+rating (this is not the original tip))
(link to using gf with spaces in the file name tip)
Line 19: Line 19:
   
 
If there are several files in your <tt>'path'</tt> that match the name under the cursor, <tt>gf</tt> opens the first, while <tt>2gf</tt> opens the second, and <tt>3gf</tt> opens the third, etc.
 
If there are several files in your <tt>'path'</tt> that match the name under the cursor, <tt>gf</tt> opens the first, while <tt>2gf</tt> opens the second, and <tt>3gf</tt> opens the third, etc.
  +
  +
It won't do it by default, but there are ways to [[Open_filenames_containing_spaces_with_gf|use gf to find files with spaces in the name]] as well.
   
 
You can return to the previous buffer using Ctrl-^ or Ctrl-o.
 
You can return to the previous buffer using Ctrl-^ or Ctrl-o.

Revision as of 15:01, 10 February 2009

Tip 299 Printable Monobook Previous Next

created August 6, 2002 · complexity basic · version 7.0


The following commands open the file name under the cursor:

  • gf    open in the same window ("goto file")
  • <c-w>f    open in a new window
  • <c-w>gf    open in a new tab

When writing a program, it is helpful to set the 'path' option to list the directories with your include files. Then you can easily open an include file.

If there are several files in your 'path' that match the name under the cursor, gf opens the first, while 2gf opens the second, and 3gf opens the third, etc.

It won't do it by default, but there are ways to use gf to find files with spaces in the name as well.

You can return to the previous buffer using Ctrl-^ or Ctrl-o.

References

Comments

You could list files in 'path' that match the name under under the cursor with:

:echo globpath(&path, expand('<cfile>'))

The plugin searchInRuntime overrides gf and CTRL-W_f to ask which file must be opened if several match. Alternatives for :sp and :vsp are also provided.