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")
> au BufEnter * call Test()
> then: I type `vim -u test.vim'
> and I get
> "test.vim" 1 line, 19 characters
> /home/joze/function Test
> 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:
let Test_file = expand("<sfile>:p")
call confirm(Test_file, "&Continue")
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@...
\ \ Vim: http://www.vim.org
ICCF Holland: http://www.vim.org/iccf