Best way to insert timestamp in Vim?

前端 未结 10 1855
轮回少年
轮回少年 2020-11-30 18:25

EditPad Lite has a nice feature (CTRL-E, CTRL-I) which inserts a time stamp e.g. \"2008-09-11 10:34:53\" into your code.

10条回答
  •  执念已碎
    2020-11-30 18:50

    :r! date

    You can then add format to the date command (man date) if you want the exact same format and add this as a vim alias as well

    :r! date +"\%Y-\%m-\%d \%H:\%M:\%S"

    That produces the format you showed in your example (date in the shell does not use \%, but just %, vim replaces % by the name of the current file, so you need to escape it).

    You can add a map in your .vimrc for it to put the command automatically, for instance, each time you press F3:

    :map  :r! date +"\%Y-\%m-\%d \%H:\%M:\%S"
    

    (Edited the from above :) ) (Edit: change text part to code, so that

     
    

    can be displayed)

提交回复
热议问题