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

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

Expand Messages
  • Jacobo de Vera
    ... I have a similar situation at work, where stuff is compiled inside a chrooted environment, yet editing happens outside, so full paths in files are really
    Message 1 of 10 , Nov 1, 2011
    • 0 Attachment
      On Tue, Nov 1, 2011 at 13:32, Dotan Cohen <dotancohen@...> wrote:
      > On Tue, Nov 1, 2011 at 01:06, Gary Johnson <garyjohn@...> wrote:
      >> The problem is that that last segment of the path name,
      >> /includes/functions_misc.php,  begins with a "/" which Vim
      >> understands to mean the beginning of an absolute path.  See
      >>
      >>    :help 'path'
      >>
      >
      > i see, Gary, that makes sense. Is there any workaround? This is a huge
      > (>80000 files) application, full of include()s and require()s.
      >
      > Thanks.
      >
      >

      I have a similar situation at work, where stuff is compiled inside a
      chrooted environment, yet editing happens outside, so full paths in
      files are really relative when editing. What I do is to visually
      select the path, excluding the initial slash, and then use gf, which
      will work on the selected text only.

      Perhaps there is a faster way to do this, I'd love to hear about it.

      Regards,

      --
      Jacobo de Vera
      http://www.jacobodevera.com
      @jovianjake

      --
      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
    • Dotan Cohen
      ... 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
      Message 2 of 10 , Nov 1, 2011
      • 0 Attachment
        On Tue, Nov 1, 2011 at 17:24, Ben Fritz <fritzophrenic@...> 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?

        Thanks.


        --
        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
      • Gary Johnson
        ... Right. Here s how I would approach it. I know that in an ex command, is a token that is replaced by the name of the file under the cursor, so I
        Message 3 of 10 , Nov 1, 2011
        • 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>

          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
        • Dotan Cohen
          ... Thank you thank you thank you! This is exactly what I need: to know _where_ to find the info, without starting In the beginning ... Thank you! ... I won t
          Message 4 of 10 , Nov 1, 2011
          • 0 Attachment
            On Tue, Nov 1, 2011 at 18:21, Gary Johnson <garyjohn@...> 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
            >

            Thank you thank you thank you! This is exactly what I need: to know
            _where_ to find the info, without starting "In the beginning"... Thank
            you!


            > Putting that all together, I came up with this:
            >
            >    nnoremap gf :exe 'find' substitute(expand('<cfile>'), '^/', '', '')<CR>
            >

            I won't look at that just yet! But I will compare notes after I piece
            mine together, or if I get too stuck.

            Again, thank you! I will figure this out and post back.


            --
            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
          • Dotan Cohen
            ... 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
            Message 5 of 10 , Nov 2, 2011
            • 0 Attachment
              On Tue, Nov 1, 2011 at 18:21, Gary Johnson <garyjohn@...> 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
            • Dotan Cohen
              ... A few posts back Gary outlined a remap just for this. It is an excellent post, I recommend going over it rather than just copying the end result here. --
              Message 6 of 10 , Nov 2, 2011
              • 0 Attachment
                On Tue, Nov 1, 2011 at 17:27, Jacobo de Vera <devel@...> wrote:
                > I have a similar situation at work, where stuff is compiled inside a
                > chrooted environment, yet editing happens outside, so full paths in
                > files are really relative when editing. What I do is to visually
                > select the path, excluding the initial slash, and then use gf, which
                > will work on the selected text only.
                >
                > Perhaps there is a faster way to do this, I'd love to hear about it.
                >

                A few posts back Gary outlined a remap just for this. It is an
                excellent post, I recommend going over it rather than just copying the
                end result here.

                --
                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
              Your message has been successfully submitted and would be delivered to recipients shortly.