I'm trying to create a snippet for vimwiki. The snippet must change __ to current time.
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return {
s(
{trig='__', desc="Insert current time", snippetType = "autosnippet"},
{t("_"), t(vim.fn.system([[date +"%H:%M" | tr -d '\n']])), t({'_', ''})},
{condition = line_begin}
),
}
Looks like it must work, but it past only fix time - the time of start of first vimwiki buffer. How to improve the snippet?
I tried to find in documentation how to do this, but have not find any solution.
Vim has a internal
strftimefunction to return a date/time formatted in a way you specify with a format string (see:help strftime).In your code, replace
vim.fn.system([[date +"%H:%M" | tr -d '\n']]))byvim.fn.strftime("%H:%M").