Say I want to print the output of strftime("%D") in the current line, or to print the return of any user-defined function for that matter. What's the standard (one step?) way to do it?

I currently do this: :let @a=strftime("%D"), then "ap (two steps, but can be combined with mapping).


From command-line mode, use :put in combination with with the expression register "= (inserts after the current line):

:put =strftime('%d')<CR>

Or, in Insert mode, use Ctrlr (inserts before the cursor position, as if typed with no abbreviations or mappings):


Or, in Normal mode, use "= (inserts after the cursor position):


Relevant help:

:h quote=
:h :put
:h i_CTRL-R
:h quote
:h p
  • 2
    or in insert mode: <c-r>=strftime('%d') Oct 4 '20 at 18:28
  • 2
    Or normal mode "=strftime('%d')<cr>p
    – D. Ben Knoble
    Oct 5 '20 at 0:53
  • @Jake for some reason it requires \ before the two ". I like Christian's solution better cause it inputs the date in the current line after cursor. Oct 5 '20 at 4:43
  • 1
    @MahbubAlam all the ways suggested are equally valid depending on the context. I just mirrored what you said your current process was. Oct 5 '20 at 4:46
  • 1
    @MahbubAlam they can be used to start comments; it's odd that in this case single-quotes are required, as in most other places you could use double-quotes with no issue
    – D. Ben Knoble
    Oct 5 '20 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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