vim 插入时间戳的方法

这里主要说明用内置函数 strftime 来插入,而不用 :r!date 或类似方法。

  1. 用命令 "=strftime('%c')<Ret>p ,或<C-r>=strftime('%c')<Ret>。可以在当前光标位置插入timestamp.
  2. 用命令 :call append(line('.'), strftime('%c'))。这个命令会在当前行的下一行插入时间戳,可以用J(大写j)来合并。
  3. 用命令 :exe ":normal i" . strftime('%c') 或 :call feedkeys("i" . strftime('%c'))

说明:用来包括 %c 的单引号也可以换成双引号,这里统一用了单引号。%c 表示格式化输出字符串,可以选择其他的格式字串,可以用 :help strftime 来查看帮助。

参考来源:stackexchange

原文地址:https://www.cnblogs.com/feng-qi/p/3147533.html