Duplicate each line in VI

前端 未结 3 1991
失恋的感觉
失恋的感觉 2021-01-31 18:22

I have a file with these lines:

aa
bb
cc
dd

I want to convert this into:

aa
aa
bb
bb
cc
cc
dd
dd

Is this poss

3条回答
  •  甜味超标
    2021-01-31 18:34

    Use the global command g to operate on every line in the file:

    :g/^/norm yyp
    

    The g command will operate on all lines that match a pattern. ^ is a pattern which will match any line. norm executes the command yyp, which yanks the current line, and pastes it. :g/^/norm Yp will also work.

    See :help global for more details about the command, and see also this vim wiki page on g.

提交回复
热议问题