Delete first word of each line

前端 未结 7 2060
耶瑟儿~
耶瑟儿~ 2021-02-01 16:45

How do I delete first word of each line in Vim?

How about a pattern on each line?

相关标签:
7条回答
  • 2021-02-01 17:38

    Going for cryptic here, in true vi style:

    1Gq10dwjq100000@1
    

    Randy fixed this up in the comments to work on more than 100000 lines:

    ggqqdwj@qq@q
    

    For those starting out with Vim, this breaks down to:

    gg    - Go to first line
    qq    - Record a macro into register 'q'
    dwj@q - The macro:
                dw - delete word at cursor
                j  - go down one line
                @q - run the macro in register 'q'
    q     - Stop recording the macro
    @q    - Execute the macro in register 'q'
    

    In essence, the macro is recursive - it deletes a word, moves down a line, then calls itself again, repeating for each line until end of file. The final '@q' is the initial (manual) call needed to set the macro off on every line.

    0 讨论(0)
提交回复
热议问题