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

Discovering the path of a sourced plugin

Expand Messages
  • David JH
    Hi All, I m trying to write a vim plugin mostly in ruby. To that end, I have a very simple .vim file that exists to load an accompanying ruby file. The
    Message 1 of 3 , Jun 30, 2008
    • 0 Attachment
      Hi All,

      I'm trying to write a vim plugin mostly in ruby. To that end, I have
      a very simple .vim file that exists to load an accompanying ruby
      file. The problem I'm having is that I can't figure out how to
      cleanly load the ruby file.

      I'd hoped that $LOAD_PATH would be set such that I could just load
      files relative to ~/.vim/plugin. Failing that, I'd hoped __FILE__
      might refer to the plugin file (i.e. the .vim file). $LOAD_PATH seems
      unaltered by vim, and __FILE__ is, quite reasonably, set to eval (at
      least for the ruby << EOF and ruby commands).

      So my short-sighted question is, "from a .vim file in ~/.vim/plugin,
      how can I find the path to that file when it's sourced?" although my
      real goal is just to write a vim plugin in ruby so if I'm going about
      this in a particularly braindead way, please do correct me. Polite
      requests to RTFM are certainly welcome, if someone could point out
      which part of the FM I need to R (thus far I've been completely
      unsuccessful looking through :help and googling).

      I could, of course, just try to use an absolute path of something like
      '~/.vim/plugin/my_file.rb', but I'd rather my plugin was capable of
      being installed in some site-wide location (and I also worry that such
      an approach may have portability issues).


      Absent some lucky googling or a clever suggestion from someone on this
      list, I see only two possible approaches:

      1 - scan 'runtimepath' for the name of my .vim file, when I find it,
      File.dirname that path
      2 - add every path listed in 'runtimepath' to $LOAD_PATH

      Does anybody have a better idea or see a problem with either of the
      above approaches?

      Thanks in advance for your time
      -djh
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Gary Johnson
      ... Example: let this_file = expand( :p ) HTH, Gary --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use
      Message 2 of 3 , Jun 30, 2008
      • 0 Attachment
        On 2008-06-30, David JH <davidjh@...> wrote:
        > Hi All,
        >
        > I'm trying to write a vim plugin mostly in ruby. To that end, I have
        > a very simple .vim file that exists to load an accompanying ruby
        > file. The problem I'm having is that I can't figure out how to
        > cleanly load the ruby file.
        >
        > I'd hoped that $LOAD_PATH would be set such that I could just load
        > files relative to ~/.vim/plugin. Failing that, I'd hoped __FILE__
        > might refer to the plugin file (i.e. the .vim file). $LOAD_PATH seems
        > unaltered by vim, and __FILE__ is, quite reasonably, set to eval (at
        > least for the ruby << EOF and ruby commands).
        >
        > So my short-sighted question is, "from a .vim file in ~/.vim/plugin,
        > how can I find the path to that file when it's sourced?" although my
        > real goal is just to write a vim plugin in ruby so if I'm going about
        > this in a particularly braindead way, please do correct me. Polite
        > requests to RTFM are certainly welcome, if someone could point out
        > which part of the FM I need to R (thus far I've been completely
        > unsuccessful looking through :help and googling).

        :help <sfile>

        Example:

        let this_file = expand("<sfile>:p")

        HTH,
        Gary


        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • David JH
        ... Awesome Gary. That s exactly what I need. Thanks very much -djh --~--~---------~--~----~------------~-------~--~----~ You received this message from the
        Message 3 of 3 , Jun 30, 2008
        • 0 Attachment
          >    :help <sfile>
          >
          > Example:
          >
          >    let this_file = expand("<sfile>:p")
          >
          > HTH,
          > Gary

          Awesome Gary. That's exactly what I need.

          Thanks very much
          -djh
          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        Your message has been successfully submitted and would be delivered to recipients shortly.