As title. Say I have a line to create an augroup located in file git.lua
. What I want to achieve is that that line will always create an augroup named git.lua
without hard-coding it by the string "git.lua", so I can renamed the file and no code needs to change. I did try calling nvim API like vim.fn.bufname
(and removing the prefix to get git.lua
) in git.lua
, but this resulted in an augroup of name plugins.lua
, since this is where git.lua
got imported/require
d. So what's the correct way to achieve this?
In short: I want to have a line of code to create an augroup, such that I can renamed that file and that line will always create an augroup as per the new name.
expand('%')
. See:h expand()
for the filename modifiers.expand('%:t')
but even if I put it ingit.lua
it created a augroup calledplugins.lua
, which is the file that importsgit.lua
. I want to create an augroup calledgit.lua
.let s:sname = expand('<sfile>:t')
. It has to be done at global file level. Not within a function! I leave plugin developers for nvim give you a nvim answer.