如何获取正在执行的当前vimscript的路径
发布时间:2020-12-15 09:23:57 所属栏目:安全 来源:网络整理
导读:在我的vim插件中,我有两个文件: myplugin/plugin.vimmyplugin/plugin_helpers.py 我想从plugin.vim(使用vim python支持)导入plugin_helpers,所以我相信我首先需要把我的插件的目录在python的sys.path。 我如何(在vimscript)获得当前执行脚本的路径?在pyt
在我的vim插件中,我有两个文件:
myplugin/plugin.vim myplugin/plugin_helpers.py 我想从plugin.vim(使用vim python支持)导入plugin_helpers,所以我相信我首先需要把我的插件的目录在python的sys.path。 我如何(在vimscript)获得当前执行脚本的路径?在python中,这是__file__。在ruby中,它是__FILE__。我找不到类似的vim通过谷歌,可以做到吗? 注意:我不是在寻找当前编辑的文件(“%:p”和朋友)。 " Relative path of script file: let s:path = expand('<sfile>') " Absolute path of script file: let s:path = expand('<sfile>:p') " Absolute path of script file with symbolic links resolved: let s:path = resolve(expand('<sfile>:p')) " Folder in which script resides: (not safe for symlinks) let s:path = expand('<sfile>: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('<sfile>:p')),':h') 我使用最后一个经常,因为我的?/ .vimrc是一个符号链接到Git存储库中的脚本。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |