VIM - 用于替换/复制行的疯狂命令

Pat*_*ery 2 vim replace preg-replace duplicates

我有一个巨大的文件,我需要更新以创建一个列表(列出一个csv),但我只有一列.

我想用键/值对组合创建2列.

我有例如:

Key 1 is NICE
Key 2 is good
Key 3 is Awesome
Run Code Online (Sandbox Code Playgroud)

我需要:

key 1 is nice|Key 1 is NICE
key_2_is_good|key 2 is good
key_3_is_awesome|Key 3 is Awesome
Run Code Online (Sandbox Code Playgroud)

所以第一个将是_而不是空格的小写,第二个是普通的字符串

我到目前为止:

:%s/^\(.*\)$/\1|\1/
Run Code Online (Sandbox Code Playgroud)

哪个好,但我怎样才能将空间固定为_并且全部小写?

谢谢

rom*_*inl 5

宏可以比替换更直观:

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
Run Code Online (Sandbox Code Playgroud)

之后,选择下一行并执行

:'<,'>norm @q
Run Code Online (Sandbox Code Playgroud)