2

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.

1 Answer 1

2

Vim has a internal strftime function 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']])) by vim.fn.strftime("%H:%M").

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately it doesn't work. It puts only fix time - the time of open buffer file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.