How to get path to the current vimscript being executed

后端 未结 3 1814
无人及你
无人及你 2020-12-02 08:33

In my vim plugin, I have two files:

myplugin/plugin.vim
myplugin/plugin_helpers.py

I would like to import plugin_helpers from plugin.vim (u

3条回答
  •  萌比男神i
    2020-12-02 09:05

    " Relative path of script file:
    let s:path = expand('')
    
    " Absolute path of script file:
    let s:path = expand(':p')
    
    " Absolute path of script file with symbolic links resolved:
    let s:path = resolve(expand(':p'))
    
    " Folder in which script resides: (not safe for symlinks)
    let s:path = expand(':p:h')
    
    " If you're using a symlink to your script, but your resources are in
    " the same directory as the actual script, you'll need to do this:
    "   1: Get the absolute path of the script
    "   2: Resolve all symbolic links
    "   3: Get the folder of the resolved absolute file
    let s:path = fnamemodify(resolve(expand(':p')), ':h')
    

    I use that last one often because my ~/.vimrc is a symbolic link to a script in a git repository.

提交回复
热议问题