我有一个文本文件,里面有一个列表:
dateformatfile.ext
dateformatfile.ext
dateformatfile.ext
...
Run Code Online (Sandbox Code Playgroud)
我需要在每个末尾添加一个填充数字,如下所示:
dateformatfile.ext 00001
dateformatfile.ext 00002
dateformatfile.ext 00003
...
Run Code Online (Sandbox Code Playgroud)
有很多,所以我需要有一个命令以某种方式这样做.
提前致谢.
假设您要对文件中的每一行执行此操作,您可以使用如下行号:
:execute "% normal A \<C-R>=printf(\"%05d\", line(\".\"))\<CR>"
Run Code Online (Sandbox Code Playgroud)
哪里
execute(...) 将字符串作为命令运行% normal 在文件的每一行上运行一个普通命令A 附加到该行<C-R>= 插入命令的结果printf("%05d", ...) 将第二个参数格式化为五位数line(".") 获取当前行的编号<CR>完成<C-R>=插入