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

Re: question on gf and path

Expand Messages
  • Tim Chase
    ... Assuming you have /var/www/html in your path, the following pairing should help you out: nnoremap gf :exec e .
    Message 1 of 7 , Dec 1, 2006
    • 0 Attachment
      > Is there a way to make gf open "some.file" from this line?
      >
      > Include("/includes/some.file");
      >
      > where the file is actually sitting under web server root, like
      >
      >
      > /var/www/html/includes/some.file
      >
      > I tried adding "/var/www/html" to the :set path but vim will
      > not recognize it. /var/www/html/; was the same. Basically I'm
      > looking for a way to add "prefixes".

      Assuming you have "/var/www/html" in your path, the following
      pairing should help you out:


      nnoremap <silent> gf :exec 'e ' .
      findfile(substitute(expand('<cfile>'), '^/*','',''))<cr>

      nnoremap <silent> <c-w>f :exec 'sp ' .
      findfile(substitute(expand('<cfile>'), '^/*','',''))<cr>

      The findfile() function also takes an extra parameter if you want
      to refrain from munging your actual path, you could do something like

      findfile(..., &path.',/var/www/html')

      > On the same note, would it be possible to let gf open
      >
      > /var/www/html/includes/some.file
      >
      > when I gf on this string
      >
      > http://somehost.com/includes/some.file
      >
      > or by defining a new command (say wf)?

      A similar transformation could tweak the previous, something like

      substitute(expand(...), '^\(http://[^/]/\)\=/*','','')

      would strip off leading slashes and leading protocol+host. (that
      regexp/substitute() is untested, but should be approx. correct,
      save for possible needs to escape the "\" characters)

      Alternatively, you could map it to <leader>gf and <leader><c-w>f
      to maintain the original meanings, but create new mappings to
      provide the additional functionality.

      HTH,

      -tim
    • Marc Weber
      ... That s exactly where you can use my little script (which will isntall some dependencies, too) ... noremap gf :call
      Message 2 of 7 , Dec 1, 2006
      • 0 Attachment
        On Fri, Dec 01, 2006 at 10:30:26AM -0600, Ben K. wrote:
        > Is there a way to make gf open "some.file" from this line?
        >
        > Include("/includes/some.file");
        >
        > where the file is actually sitting under web server root, like
        >
        > /var/www/html/includes/some.file
        >
        > I tried adding "/var/www/html" to the :set path but vim will not recognize
        > it. /var/www/html/; was the same. Basically I'm looking for a way to add
        > "prefixes".
        >
        > On the same note, would it be possible to let gf open
        >
        > /var/www/html/includes/some.file
        >
        > when I gf on this string
        >
        > http://somehost.com/includes/some.file
        >
        > or by defining a new command (say wf)?

        That's exactly where you can use my little script (which will isntall
        some dependencies, too)

        Just add this into your ftplgugin/filetype.vim file:

        ------ >8 ------ >8 filetype_sourced.vim -- >8 ------ >8 ------ >8
        noremap gf :call vl#ui#navigation#gfHandler#HandleGF()<cr>
        call vl#ui#navigation#gfHandler#AddGFHandler("[matchstr(expand('<cWORD>'),'Include(\"\\zs[^\"].*\\ze\")')]")
        ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8<

        and source the installer file
        http://www.mawercer.de/marcweber/vim/vimlib/installers/vimlib_gfhandler_installer_sourceme.vim
        (Don't be afraid. The installer will ask for confirmation before doing
        anything.)
        I would suggest saving it to another directory (eg ~/.vimlib or
        ~/.vim_gf) and adding this folder to your runtimepath.
        set runtimepath+=~/.vimlib
        Then its easy to remove it again if you don't like it.
        I think you can see that [matchstr ... does the interesting thing which
        is getting the file from under the cursor by calling expand('<cWORD>')
        and remvoving the Include text. You
        have to adjust it the way you like. You have to write your own code
        which removes /includes and adds /var/www/html/includes/ which would
        look like this:
        call vl#ui#navigation#gfHandler#AddGFHandler("['/var/www/html/includes'.matchstr(expand('<cWORD>'),'Include(\"/includes\\zs[^\"].*\\ze\")')]")

        You can even add different include directories:
        call vl#ui#navigation#gfHandler#AddGFHandler("['/var/www/html/includes1'....
        call vl#ui#navigation#gfHandler#AddGFHandler("['/var/www/html/includes2'....
        call vl#ui#navigation#gfHandler#AddGFHandler("['/var/www/html/includes3'....

        Then you'll be asked which file to open if it doesn't exist.

        Unfortunately the documentation
        (http://www.mawercer.de/marcweber/vim/vimlib/docs/vl_ui_navigation_gfHandler_vim.html)
        isn't up to date because vim segfaults while creating it and I don't
        have the time to find the code causing it.

        If something doesn't work drop me a mail.

        HTH
        Marc Weber
      • Marc Weber
        ... Do I have missed something or would set nocompatible first line in your .vimrc ! set hidden prevent vim from saving the file on gf ?? Marc
        Message 3 of 7 , Dec 1, 2006
        • 0 Attachment
          > Include("includes/some.file")
          >
          > it's somewhat OK, but gf requires me to actually save the source file
          > before it will accept the change from "/includes..." to "includes".

          Do I have missed something or would
          set nocompatible "first line in your .vimrc !
          set hidden
          prevent vim from saving the file on gf ??

          Marc
        • Ben K.
          Thanks. ... Regards, Ben K. Developer http://benix.tamu.edu
          Message 4 of 7 , Dec 4, 2006
          • 0 Attachment
            Thanks.

            On Sat, 2 Dec 2006, Marc Weber wrote:

            > On Fri, Dec 01, 2006 at 10:30:26AM -0600, Ben K. wrote:
            >> Is there a way to make gf open "some.file" from this line?
            >>
            >> Include("/includes/some.file");
            >>
            >> where the file is actually sitting under web server root, like
            >>
            >> /var/www/html/includes/some.file
            >>
            >> I tried adding "/var/www/html" to the :set path but vim will not recognize
            >> it. /var/www/html/; was the same. Basically I'm looking for a way to add
            >> "prefixes".
            >>
            >> On the same note, would it be possible to let gf open
            >>
            >> /var/www/html/includes/some.file
            >>
            >> when I gf on this string
            >>
            >> http://somehost.com/includes/some.file
            >>
            >> or by defining a new command (say wf)?
            >
            > That's exactly where you can use my little script (which will isntall
            > some dependencies, too)
            >
            > Just add this into your ftplgugin/filetype.vim file:
            >
            > ------ >8 ------ >8 filetype_sourced.vim -- >8 ------ >8 ------ >8
            > noremap gf :call vl#ui#navigation#gfHandler#HandleGF()<cr>
            > call vl#ui#navigation#gfHandler#AddGFHandler("[matchstr(expand('<cWORD>'),'Include(\"\\zs[^\"].*\\ze\")')]")
            > ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8<
            >
            > and source the installer file
            > http://www.mawercer.de/marcweber/vim/vimlib/installers/vimlib_gfhandler_installer_sourceme.vim
            > (Don't be afraid. The installer will ask for confirmation before doing
            > anything.)
            > I would suggest saving it to another directory (eg ~/.vimlib or
            > ~/.vim_gf) and adding this folder to your runtimepath.
            > set runtimepath+=~/.vimlib
            > Then its easy to remove it again if you don't like it.
            > I think you can see that [matchstr ... does the interesting thing which
            > is getting the file from under the cursor by calling expand('<cWORD>')
            > and remvoving the Include text. You
            > have to adjust it the way you like. You have to write your own code
            > which removes /includes and adds /var/www/html/includes/ which would
            > look like this:
            > call vl#ui#navigation#gfHandler#AddGFHandler("['/var/www/html/includes'.matchstr(expand('<cWORD>'),'Include(\"/includes\\zs[^\"].*\\ze\")')]")
            >
            > You can even add different include directories:
            > call vl#ui#navigation#gfHandler#AddGFHandler("['/var/www/html/includes1'....
            > call vl#ui#navigation#gfHandler#AddGFHandler("['/var/www/html/includes2'....
            > call vl#ui#navigation#gfHandler#AddGFHandler("['/var/www/html/includes3'....
            >
            > Then you'll be asked which file to open if it doesn't exist.
            >
            > Unfortunately the documentation
            > (http://www.mawercer.de/marcweber/vim/vimlib/docs/vl_ui_navigation_gfHandler_vim.html)
            > isn't up to date because vim segfaults while creating it and I don't
            > have the time to find the code causing it.
            >
            > If something doesn't work drop me a mail.
            >
            > HTH
            > Marc Weber
            >

            Regards,

            Ben K.
            Developer
            http://benix.tamu.edu
          • Ben K.
            It worked and I appreciate the simpleness. Thanks. ... Regards, Ben K. Developer http://benix.tamu.edu
            Message 5 of 7 , Dec 4, 2006
            • 0 Attachment
              It worked and I appreciate the simpleness. Thanks.


              On Fri, 1 Dec 2006, Tim Chase wrote:

              >> Is there a way to make gf open "some.file" from this line?
              >>
              >> Include("/includes/some.file");
              >>
              >> where the file is actually sitting under web server root, like
              >>
              >>
              >> /var/www/html/includes/some.file
              >>
              >> I tried adding "/var/www/html" to the :set path but vim will
              >> not recognize it. /var/www/html/; was the same. Basically I'm
              >> looking for a way to add "prefixes".
              >
              > Assuming you have "/var/www/html" in your path, the following
              > pairing should help you out:
              >
              >
              > nnoremap <silent> gf :exec 'e ' . findfile(substitute(expand('<cfile>'),
              > '^/*','',''))<cr>
              >
              > nnoremap <silent> <c-w>f :exec 'sp ' . findfile(substitute(expand('<cfile>'),
              > '^/*','',''))<cr>
              >
              > The findfile() function also takes an extra parameter if you want
              > to refrain from munging your actual path, you could do something like
              >
              > findfile(..., &path.',/var/www/html')
              >
              >> On the same note, would it be possible to let gf open
              >>
              >> /var/www/html/includes/some.file
              >>
              >> when I gf on this string
              >>
              >> http://somehost.com/includes/some.file
              >>
              >> or by defining a new command (say wf)?
              >
              > A similar transformation could tweak the previous, something like
              >
              > substitute(expand(...), '^\(http://[^/]/\)\=/*','','')
              >
              > would strip off leading slashes and leading protocol+host. (that
              > regexp/substitute() is untested, but should be approx. correct, save for
              > possible needs to escape the "\" characters)
              >
              > Alternatively, you could map it to <leader>gf and <leader><c-w>f
              > to maintain the original meanings, but create new mappings to
              > provide the additional functionality.
              >
              > HTH,
              >
              > -tim
              >
              >
              >
              >
              >

              Regards,

              Ben K.
              Developer
              http://benix.tamu.edu
            Your message has been successfully submitted and would be delivered to recipients shortly.