Loading ...
Sorry, an error occurred while loading the content.

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

Expand Messages
  • Gary Johnson
    Nov 1 9:21 AM
    • 0 Attachment
      On 2011-11-01, Dotan Cohen wrote:
      > 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>


      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
    • Show all 10 messages in this topic