> On Tue, Nov 1, 2011 at 17:24, Ben Fritz wrote:
> > 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?
Right. Here's how I would approach it.
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.
:help <cfile>
Then I know that the substitute() function will let me delete the
leading /.
:help substitute()
Finally, I know that the :find command is the ex equivalent of the
normal-mode gf command.
:help :find
To help put those together into a mapping, there are overviews of
mapping here:
:help 05.3
:help 40.1
which I found by going to the table of contents for the user manual,
:help toc
and searching for "map".
A very useful command for executing ex commands with variable
arguments is :execute:
:help :execute
Putting that all together, I came up with this:
nnoremap gf :exe 'find' substitute(expand('<cfile>'), '^/', '', '')<CR>
Regards,
Gary
--
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
No comments:
Post a Comment