I am looking for the idiomatic lua method to get a plugin’s install path, for example:
~/.config/nvim/<...>/myplugin/
- lua
- myplugin
- myplugin.lua
- plugin
From myplugin.lua what is the best way to get the path ~/.config/nvim/<...>/myplugin/?
In vimscript I could do something like expand("<sfile>:p:h") but <sfile> doesn’t seem to resolve to anything from lua.
You can get the full path of the myplugin.lua with
debug.getinfo(1).source:sub(2)
jharr
3
In a Neovim buffer opened on a file on my system:
:lua local d = debug.getinfo(1).source:sub(2)
:=d
- reports back “nil” - what’m I getting wrong here?
I’m resorting to these commands
:vim.cmd('cd %:p:h')
:vim.cmd('pwd')
In my vimfiles/nvim/lua/lazy/telescope.lua.
<sfile> doesn’t work from vim.fn.expand()?