summaryrefslogtreecommitdiff
path: root/lua/vim/userregs/impl/timestamp.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2025-04-10 00:20:28 -0600
committerJosh Rahm <joshuarahm@gmail.com>2025-04-10 00:20:28 -0600
commitd2325e040e2a4c2ea9d0d8c57af57bc13f7aeae7 (patch)
tree42cdc551faf3b3abbeb998166f00f937747fa6b1 /lua/vim/userregs/impl/timestamp.lua
parentb3b09ff479510abc51ffb88743bb353bcc15e165 (diff)
downloadrneovim-userregs-d2325e040e2a4c2ea9d0d8c57af57bc13f7aeae7.tar.gz
rneovim-userregs-d2325e040e2a4c2ea9d0d8c57af57bc13f7aeae7.tar.bz2
rneovim-userregs-d2325e040e2a4c2ea9d0d8c57af57bc13f7aeae7.zip
Add some more user-defined registers:HEADmain
"| - file contents register " - visual selection register " - timestamp register " - uuid register " - dirname register
Diffstat (limited to 'lua/vim/userregs/impl/timestamp.lua')
-rw-r--r--lua/vim/userregs/impl/timestamp.lua22
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
+})