diff options
Diffstat (limited to 'lua/vim/userregs/impl/timestamp.lua')
-rw-r--r-- | lua/vim/userregs/impl/timestamp.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lua/vim/userregs/impl/timestamp.lua b/lua/vim/userregs/impl/timestamp.lua new file mode 100644 index 0000000..517dd43 --- /dev/null +++ b/lua/vim/userregs/impl/timestamp.lua @@ -0,0 +1,22 @@ +local userregs = require("vim.userregs") + +-- Get format from g:timestamp_register_format or use fallback +local function get_timestamp_format() + return vim.g.timestamp_register_format or "%Y-%m-%d %H:%M:%S" +end + +local function generate_timestamp() + local ok, result = pcall(os.date, get_timestamp_format()) + if not ok then + vim.notify("[userregs] Invalid timestamp format", vim.log.levels.WARN) + return os.date("%Y-%m-%d %H:%M:%S") + end + return result +end + +userregs.register_handler('\20', { + put = function() + return generate_timestamp() + end, + yank = nil, -- read-only +}) |