diff options
Diffstat (limited to 'lua/vim/userregs/impl/dirname.lua')
-rw-r--r-- | lua/vim/userregs/impl/dirname.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lua/vim/userregs/impl/dirname.lua b/lua/vim/userregs/impl/dirname.lua new file mode 100644 index 0000000..503601d --- /dev/null +++ b/lua/vim/userregs/impl/dirname.lua @@ -0,0 +1,27 @@ +--- Dirname Register: returns the direction for the filename. +--- +--- This is similar to the "%" register (full filename), but returns only +--- the the directory. +--- +--- This register is read-only and assigned to the character '<C-d>'. + +local userregs = require("vim.userregs") +local api = vim.api + +---@type table<string, fun(regname: string): any> +local handler = {} + +--- Return the current buffer's basename without extension. +--- Equivalent to `expand('%:t:r')` +function handler.put(regname) + return vim.fn.expand('%:p:h') .. '/' +end + +-- Make this register read-only by omitting the yank handler. +handler.yank = nil + +-- Register this handler under the user register '<C-d>'. +userregs.register_handler('\4', handler) + + +return {} |