SteveDeFacto
SteveDeFacto

Reputation: 1367

How can I get a vim plugin's directory from within that plugin?

I need to copy a file from my plugin's directory but I don't know how to get a string containing the plugin's directory? I know where I have the plugin installed on my machine but I want the plugin to work on other people's machines including Windows. How do i do this?

Upvotes: 3

Views: 1889

Answers (1)

FDinoff
FDinoff

Reputation: 31459

To get the plugin directory's full path you can use the following to get the directory when the plugin is sourced and store it in a variable.

let s:plugindir = expand('<sfile>:p:h:h')

The latter you would just use the variable to get the plugin directory.

expand() expands the the wildcards into a string.
<sfile> is the file being sourced.
:p makes the name a full path when it is expanded.
:h removes the file name.
:h remove the filename again (in this case should be the plugin directory)

Take a look at :h filename-modifiers and :h expand()

Upvotes: 8

Related Questions