我有一个巨大的文件,需要更新以创建列表(列出 csv),但我只有 1 列。
我想使用键/值对组合创建 2 列。
我有例如:
Key 1 is NICE
Key 2 is good
Key 3 is Awesome
我需要:
key 1 is nice|Key 1 is NICE
key_2_is_good|key 2 is good
key_3_is_awesome|Key 3 is Awesome
因此第一个将全部小写,并用_代替空格,第二个是普通字符串
到目前为止我已经:
:%s/^\(.*\)$/\1|\1/
这很好,但如何将空格修复为 _ 并全部小写?
谢谢
最佳答案
宏比替换更直观:
qq " start recording in register q then…
0 " go to the first column then…
y$ " yank from here to end of line then…
A| " append a pipe at the end of the line then…
<C-r>=substitute(@", " ", "_", "g")<CR> " insert text of first column with spaces replaced by underscores then…
<Esc> " get out of insert mode then…
q " stop recording
之后,选择到最后一行并执行
:'<,'>norm @q
关于VIM - 疯狂的命令来替换/重复行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19257358/