2

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).

4

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):

<C-r>=strftime('%d')<CR>

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

"=strftime('%d')<CR>p

Relevant help:

:h quote=
:h :put
:h i_CTRL-R
:h quote
:h p
| improve this answer | |
  • 2
    or in insert mode: <c-r>=strftime('%d') – Christian Brabandt Oct 4 at 18:28
  • 2
    Or normal mode "=strftime('%d')<cr>p – D. Ben Knoble Oct 5 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. – Mahbub Alam Oct 5 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. – Jake Grossman Oct 5 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 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.