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

Re: weird

Expand Messages
  • Bram Moolenaar
    ... Interesting, Vim expands to function Text . Then the :p inserts /home/joze/ , which is meaningless. ... The inside a function
    Message 1 of 2 , Feb 16, 2000
    • 0 Attachment
      Johannes Zellner wrote:

      > I've a problem. I reduced it to two files:
      >
      > " test.vim
      > so $HOME/test2.vim
      >
      > " test2.vim
      > fun Test()
      > let file = expand("<sfile>:p")
      > call confirm(file, "&Continue")
      > endfun
      > au BufEnter * call Test()
      >
      >
      > then: I type `vim -u test.vim'
      > and I get
      >
      > "test.vim" 1 line, 19 characters
      > /home/joze/function Test
      > (C)ontinue:
      >
      > where the files live in my home directory (/home/joze)

      Interesting, Vim expands "<sfile>" to "function Text". Then the ":p" inserts
      "/home/joze/", which is meaningless.

      > Or: I'd like <sfile>:p expanding to /home/joze/test2.vim
      > (or to wherever test2.vim lives)

      The "<sfile>" inside a function gives the name of the function being called.
      If you want the name of the file which defined the function, you must expand
      <sfile> outside of the function. Example:

      " test2.vim
      let Test_file = expand("<sfile>:p")
      fun Test()
      call confirm(Test_file, "&Continue")
      endfun
      au BufEnter * call Test()

      --
      hundred-and-one symptoms of being an internet addict:
      4. Your eyeglasses have a web site burned in on them.

      /-/-- Bram Moolenaar --- Bram@... --- http://www.moolenaar.net --\-\
      \ \ Vim: http://www.vim.org ICCF Holland: http://www.vim.org/iccf / /
    Your message has been successfully submitted and would be delivered to recipients shortly.