tags:

views:

56

answers:

2

Hi,

I'm having a problem when trying to make vim expand the file name under cursor. For example:

include("../path/file.php");

When the cursor is on file name and I type gf the file.php is opened just fine. However, when I remap the gf command in vimrc this way: map gf :tabnew <cfile><CR>, then instead of opening the file in a new tab gf just opens up an empty file.

Any idea what I am doing wrong?

EDIT: Sorry, I just found that SO is scrambling my map line and I couldn't figure how how to fix it. Instead of map gf :tabnew <cfile><CR> it should read map gf :tabnew cfile CR (where cfile and CR are enclosed in less/greater than signs.)

+2  A: 

It should be.

:nnoremap gf :exe 'tabnew '.expand('<cfile>')<cr>
Luc Hermitte
Thanks, Luc, but result is the same - blank file.
Amati
Luc Hermitte
Yes, that's what I finally figured out as well. I assumed that when you edit a file the current path is automatically set to the file path but obviously that's not the case. Only after I did `:cd /correct_path` manually the `gf` stared to work.
Amati
+1  A: 

If I have the following directory structure:

~
|- ./foo/
|     `-- bar.php
`- ./baz/
      `-- bang.php

..and in bang.php: <?php include('../foo/bar.php'); ?>

This mapping works fine for me: :nnoremap gf :tabe <cfile><cr> . The file ~/foo/bar.php is opened in a separate tab.

Randy Morris