In VIM, how do I break one really long line into multiple lines?

前端 未结 11 559
刺人心
刺人心 2021-01-29 17:53

Say I have a super long line in the VIM editor (say around 300+ characters). How would I break that up into multiple lines so that the word boundaries roughly break at 80 chara

11条回答
  •  迷失自我
    2021-01-29 18:00

    For solid lines of text highlight the area using v in normal mode, then press

    :s/\v(.{80})/\1\r/g
    

    This will add a newline at the end of every 80th character.

    :s/       replaces within the current select
    \v        uses regular expressions
    (.{80})   selects 80 characters & placed them into group one
    \1\r      replaces group one with group one and a newline
    

提交回复
热议问题