I have a custom command for stamping time in my log files. However, I would like that format to match the one of bash command date.

For example, I use this command:

:command InLog pu=strftime(\"\n***** IN:  %c\n\n\n\") | startinsert

which prints:

***** IN: Thu Sep 16 01:51:47 2021

However, I would want to have the same output as the date command in bash. Its output is:

Thu Sep 16 01:52:48 EDT 2021

Notice the EDT!

I would appreciate any help. :) Thank you in advance!

  • 1
    Why not use the shell command itself with system('date'). So your command would be something like :command InLog pu=printf("\n***** IN: %s\n\n\n", system('date')) | startinsert. (Unless you want to share this and need it to be portable...)
    – B Layer
    Sep 16, 2021 at 6:16
  • Part of the reason is because I am new to Vim so I did not know to do it the way you suggested. I like that method; however, there is an error. It says: Invalid arguments for function printf(
    – Vladimir
    Sep 16, 2021 at 6:20
  • Hmmm. Put backslashes in front of the " like in your original command...?
    – B Layer
    Sep 16, 2021 at 6:23
  • 4
    how about: :echo strftime('%a %b %d %T %Z %Y') Sep 16, 2021 at 6:27

2 Answers 2


While Christian Brabandt already gave the correct answer in a comment:

:echo strftime('%a %b %d %T %Z %Y')

I would like to add a few words.

The most important part from the help documentation:

The accepted {format} depends on your system, thus this is not portable! See the manual page of the C function strftime() for the format.

So the actual valid format depends on your operating system, as Vim just uses the strftime available in the C library. Also most format specifiers should be portable, there might be differences.

The format specifier %c you used is described in the linux man page as:

The preferred date and time representation for the current locale. ...

As that it doesn't need a timezone.

See :help strftime() (and your local C library documentation).

Windows strftime

Linux man page


I have these in my .zshenv

    export LANG=en_US.UTF-8
    export LC_TIME=zh_CN.UTF-8
    export TZ=Asia/Shanghai  # ref:   man tzselect

set -g status-right "#[fg=red,dim] %-d日 - %H:%M " in my tmux config file,

setl stl+=%{strftime('%H:%M')} in my init.vim

Then almost all time I see is in "Asia/Shanghai"'s timezone.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.