How do I insert current time into a file using vim

前端 未结 3 1332
终归单人心
终归单人心 2021-01-01 03:42

I\'m just logging some work as I do it, each line being an action, I will be trying to do this every few minutes. Is there a trick way of inserting date/time something like

相关标签:
3条回答
  • 2021-01-01 03:57

    This should help you: Insert current date or time

    0 讨论(0)
  • 2021-01-01 04:13

    See here

    Press F5 in normal mode or in insert mode to insert the current datestamp:

    :nnoremap <F5> "=strftime("%c")<CR>P
    :inoremap <F5> <C-R>=strftime("%c")<CR>
    
    0 讨论(0)
  • 2021-01-01 04:18

    I prefer to set an abbreviation for this like:

    iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>
    

    So when I type "Downloaded source code on xdate", vim automatically expands the "xdate" to "14/06/11 hrs:mins:secs". Being in insert mode and not having to disrupt my flow of typing to either get into normal mode or press a shortcut is useful at times. Also, you can set it to a shorter combination than "xdate" if you so wish.

    0 讨论(0)
提交回复
热议问题