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

Configure goto file command

Expand Messages
  • Fabien Meghazi
    when doing web development, in views, I deal with a lot with references to absolute urls. Eg: My goal is to put my cursor over the
    Message 1 of 4 , Jul 2, 2014
      when doing web development, in views, I deal with a lot with references to absolute urls. Eg:

          <script src="/foo/bar.js" />

      My goal is to put my cursor over the /foo/bar.js and type ` gf `

      But /foo/bar.js is an absolute path, and my paths may vary from project to project.

      When opening a file in vim, I always autocmd :lcd to the project's root

      So given that my static files could be in  <project>/static/foo/bar.js for a project but it could also be <project>/module_foo/static/foo/bar.js (the place can change from project to project)

      So how can I configure vim so  the  ` gf ` command will find the good file ?
      Is it possible to hook a python function in place of isfname in order to return the good filename or somthing like this ?


      --
      Fabien Meghazi

      Website: http://www.amigrave.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

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/d/optout.
    • Conner McDaniel
      You should be able to use the includeexpr option to achieve this. See ... - Conner ... -- -- You received this message from the vim_use maillist. Do not
      Message 2 of 4 , Jul 2, 2014
        You should be able to use the 'includeexpr' option to achieve this. See
        :h 'includeexpr'.

        - Conner


        On Wed, Jul 02, 2014 at 04:21:10PM +0200, Fabien Meghazi wrote:
        >when doing web development, in views, I deal with a lot with references to
        >absolute urls. Eg:
        >
        > <script src="/foo/bar.js" />
        >
        >My goal is to put my cursor over the /foo/bar.js and type ` gf `
        >
        >But /foo/bar.js is an absolute path, and my paths may vary from project to
        >project.
        >
        >When opening a file in vim, I always autocmd :lcd to the project's root
        >
        >So given that my static files could be in <project>/static/foo/bar.js for
        >a project but it could also be <project>/module_foo/static/foo/bar.js (the
        >place can change from project to project)
        >
        >So how can I configure vim so the ` gf ` command will find the good file ?
        >Is it possible to hook a python function in place of isfname in order to
        >return the good filename or somthing like this ?
        >
        >
        >--
        >Fabien Meghazi
        >
        >Website: http://www.amigrave.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
        >
        >---
        >You received this message because you are subscribed to the Google Groups "vim_use" group.
        >To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        >For more options, visit https://groups.google.com/d/optout.

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

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/d/optout.
      • David Fishburn
        ... This is what I put in my .vimrc: augroup MyProjectName au! Set a default web root directory for use later When using Vims gf command, includeexpr can
        Message 3 of 4 , Jul 2, 2014

          On Wed, Jul 2, 2014 at 10:21 AM, Fabien Meghazi <agr@...> wrote:
          when doing web development, in views, I deal with a lot with references to absolute urls. Eg:

              <script src="/foo/bar.js" />

          My goal is to put my cursor over the /foo/bar.js and type ` gf `

          But /foo/bar.js is an absolute path, and my paths may vary from project to project.

          When opening a file in vim, I always autocmd :lcd to the project's root

          So given that my static files could be in  <project>/static/foo/bar.js for a project but it could also be <project>/module_foo/static/foo/bar.js (the place can change from project to project)

          So how can I configure vim so  the  ` gf ` command will find the good file ?
          Is it possible to hook a python function in place of isfname in order to return the good filename or something like this ?


          This is what I put in my .vimrc:


          augroup MyProjectName
              au!
              " Set a default web root directory for use later
              " When using Vims 'gf' command, includeexpr can manipulate the file to be
              " opened (via gf) and change it in an appropriate way.  In this case, we
              " need to replace '/myroot' with the filesystem location (projectWebDir).
              autocmd BufRead */dev/rem/web/*
                          \ setlocal sw=4 expandtab tabstop=4|
                          \ let projectWebDir = substitute(fnamemodify(expand("<afile>"), ':p:h'), 'rem\(\\\|\/\)web\zs.*', '', '')|
                          \ setlocal includeexpr=substitute(v:fname,'^/myroot/',substitute(g:projectWebDir,'\\','/','g').'/','/')
          augroup end

          The BufRead allows me to specific a specific directory for this augroup to function over as like you I will have many projects.


          You may have to mess around with the paths and how you specify the includeexpr, you can add something like this as well:
                          \ setlocal includeexpr=substitute(v:fname,'^/myroot/',substitute(g:projectWebDir,'\\','/','g').'/','/')|
                          \ echo 'includeexpr:'.substitute(v:fname,'^/myroot/',substitute(g:projectWebDir,'\\','/','g').'/','/')

          To see what it was set to, then modify and try again.

          HTH,
          David

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

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/d/optout.
        • Fabien Meghazi
          On Wed, Jul 2, 2014 at 4:55 PM, David Fishburn ... Thanks a lot David ! This is exactly what I need !!! -- Fabien Meghazi Website:
          Message 4 of 4 , Jul 2, 2014
            On Wed, Jul 2, 2014 at 4:55 PM, David Fishburn <dfishburn.vim@...> wrote:
                autocmd BufRead */dev/rem/web/*
                            \ setlocal sw=4 expandtab tabstop=4|
                            \ let projectWebDir = substitute(fnamemodify(expand("<afile>"), ':p:h'), 'rem\(\\\|\/\)web\zs.*', '', '')|
                            \ setlocal includeexpr=substitute(v:fname,'^/myroot/',substitute(g:projectWebDir,'\\','/','g').'/','/')

            HTH,
            David


            Thanks a lot David ! This is exactly what I need !!! 


            --
            Fabien Meghazi

            Website: http://www.amigrave.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

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/d/optout.
          Your message has been successfully submitted and would be delivered to recipients shortly.