Delete first word of each line

前端 未结 7 2063
耶瑟儿~
耶瑟儿~ 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:23

    I would use something like the following:

    :%s/^\w+\s+//
    

    The regular expression will match one or more "word" characters starting at the beginning of the line followed by at least one whitespace character. It will remove the word and any following whitespace. If a line can contain only a single word -- and you still want it removed -- you could use alternation to match either whitespace or the end of line.

    :%s/^\w+(\s+|$)//
    

提交回复
热议问题