126777Re: Cannot use gf to go to file, path seems set
- Nov 1 9:21 AMOn 2011-11-01, Dotan Cohen wrote:
> On Tue, Nov 1, 2011 at 17:24, Ben Fritz wrote:Right. Here's how I would approach it.
> > gf works also on a visual selection. Select just what you want to
> > find, relative to one of the directories in your path, in visual mode.
> > THEN press gf.
> > This is also the best way to use gf on filenames with spaces or other
> > special characters (not in 'isfname'), incidentally.
> Thanks. As there are no incidences of an absolute path in this or any
> other PHP application (in the name of portability), I am trying to
> overload gf to remove the leading slash if one exists. I am having a
> hard time with the regex as I am rather inexperienced in this. Are
> there any fine manuals that I should be reading? Also, I should be
> using nmap, right?
I know that in an ex command, <cfile> is a token that is replaced by
the name of the file under the cursor, so I would start there.
Then I know that the substitute() function will let me delete the
Finally, I know that the :find command is the ex equivalent of the
normal-mode gf command.
To help put those together into a mapping, there are overviews of
which I found by going to the table of contents for the user manual,
and searching for "map".
A very useful command for executing ex commands with variable
arguments is :execute:
Putting that all together, I came up with this:
nnoremap gf :exe 'find' substitute(expand('<cfile>'), '^/', '', '')<CR>
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
- << Previous post in topic Next post in topic >>