How to stop line breaking in vim

前端 未结 11 2021
执笔经年
执笔经年 2020-12-12 10:06

I like that the long lines are displayed over more than one terminal line; I don’t like that vim inserts newlines into my actual text. Which part of .vimrc I should change?

相关标签:
11条回答
  • 2020-12-12 10:49

    I personnally went for:

    • set wrap,
    • set linebreak
    • set breakindent
    • set showbreak=ͱ.

    Some explanation:

    • wrap option visually wraps line instead of having to scroll horizontally
    • linebreak is for wrapping long lines at a specific character instead of just anywhere when the line happens to be too long, like in the middle of a word. By default, it breaks on whitespace (word separator), but you can configure it with breakat. It also does NOT insert EOL in the file as the OP wanted.
    • breakat is the character where it will visually break the line. No need to modify it if you want to break at whitespace between two words.
    • breakindent enables to visually indent the line when it breaks.
    • showbreak enables to set the character which indicates this break.

    See :h <keyword> within vim for more info.

    Note that you don't need to modify textwidth nor wrapmargin if you go this route.

    0 讨论(0)
  • 2020-12-12 10:52

    You may find set lbr useful; with set wrap on this will wrap but only cutting the line on whitespace and not in the middle of a word.

    e.g.

    without lbr the li
    ne can be split on
    a word
    

    and

    with lbr on the
    line will be
    split on 
    whitespace only
    
    0 讨论(0)
  • 2020-12-12 10:52

    Its strange that such a simple setting would require this amount of 'hocus-pocus' to work.

    To answer your question now, for me it seemed to work with the combination of the following:

    :set wrap linebreak nolist
    

    (this seems to prevent existing lines from breaking, just wrap.)

    AND

    set formatoptions=l
    

    (this prevents new/edited lines from breaking, while += does not do it for me as other settings/plugins seem to find space and add their own options which override mine.)

    0 讨论(0)
  • 2020-12-12 10:54

    I'm not sure I understand completely, but you might be looking for the 'formatoptions' configuration setting. Try something like :set formatoptions-=t. The t option will insert line breaks to make text wrap at the width set by textwidth. You can also put this command in your .vimrc, just remove the colon (:).

    0 讨论(0)
  • 2020-12-12 10:54

    :set tw=0

    VIM won't auto-insert line breaks, but will keep line wrapping.

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