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/required. 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. – Luc Hermitte Nov 23 '22 at 17:06expand('%:t')but even if I put it ingit.luait created a augroup calledplugins.lua, which is the file that importsgit.lua. I want to create an augroup calledgit.lua. – NeoZoom.lua Nov 23 '22 at 17:12:auit should show some autocmd belonging togit.lua, notplugins.lua. Puttingexpand('%:t')in different files still resulting in a singlegit.luaaugroup, which is not what I want... – NeoZoom.lua Nov 23 '22 at 17:48let 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. – Luc Hermitte Nov 23 '22 at 19:21expand(<sfile>:t')that should give you the name of the script which you can then use later on. – Christian Brabandt Nov 24 '22 at 13:08