Wednesday, November 2, 2011

Re: Cannot use gf to go to file, path seems set

On Tue, Nov 1, 2011 at 18:21, Gary Johnson <garyjohn@spocom.com> wrote:
> 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>
>

Gary, I am still a bit stuck in creating my own remap, so I am using
yours in production until I learn the method. It works perfect. Thank
you for both giving to me the tools to teach myself and also the
solution to learn from and to be productive in the meantime. Your help
and advice is greatly appreciated!


--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com

--
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