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

前端 未结 11 574
刺人心
刺人心 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:14

    Vim does this very easy (break lines at word boundaries).

    gq{motion} % format the line that {motion} moves over
    {Visual}gq % format the visually selected area
    gqq        % format the current line
    ...
    

    I'd suggest you check out :help gq and :help gw.

    Also setting textwidth (tw) will give you auto line break when exceeded during typing. It is used in gq too, though if disabled gq breaks on window size or 79 depending on which comes first.

    :set tw=80
    

    By setting format options to include text width vim will automatically break at the tw setting.

    :set fo+=t
    

提交回复
热议问题