我正在尝试从m / d / yyyy 2016/7/1转换日期格式
每行一次发生到YYYY-mm-dd 00:00:00
我的搜索和参数部分正常工作,可以交换订单等,
但是我想使用vim的printf做到这一点,并提出了以下建议...
%s/\(\d\+\)\/\(\d\+\)\/\(\d\+\)/\=printf('%d-%02d-%02d 00:00:00', \3, \1, \2)/
我知道了
E15: Invalid expression: \3, \1, \2)
E116: Invalid arguments for function printf('%d-%02d-%02d 00:00:00', \3, \1, \2)
有任何想法吗?
您需要使用submatch()
功能:
:%s/\(\d\+\)\/\(\d\+\)\/\(\d\+\)/\=printf('%d-%02d-%02d 00:00:00', submatch(3),
submatch(1), submatch(2))/
:help submatch()
submatch({nr}[, {list}]) submatch() Only for an expression in a :substitute command or substitute() function. Returns the {nr}'th submatch of the matched text. When {nr} is 0 the whole matched text is returned. Note that a NL in the string can stand for a line break of a multi-line match or a NUL character in the text. Also see sub-replace-expression.(...)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句