8

If you have set wrap, sometimes you can see something like this:

5.  A soft-wrapped line with an *
    italic* word.

I would prefer Vim to not soft-wrap before or after asterisks, and so the same line should be wrapped as follows:

5. A soft-wrapped line with an
   *italic* word

What I need to do to fix this?

(linebreak is already turned on, of course.)

0

1 Answer 1

7

If you use the use 'soft wrap' and 'line break`

i.e.

set wrap
set linebreak
set textwidth=0  " To avoid confusion with hard wrap

Then Vim splits the lines only at the breakat character.

If you would Vim not to break at * make sure * is not part of breakat

set breakat-=*

If you use the use 'soft wrap' but not 'line break`

set wrap
set nolinebreak
set textwidth=0  " To avoid confusion with hard wrap

Then Vim splits the lines at the exact screen border

:help linebreak

'linebreak' 'lbr'   boolean (default off)
            local to window
            {not available when compiled without the |+linebreak|
            feature}
    If on, Vim will wrap long lines at a character in 'breakat' rather
    than at the last character that fits on the screen.  Unlike
    'wrapmargin' and 'textwidth', this does not insert <EOL>s in the file,
    it only affects the way the file is displayed, not its contents.
    If 'breakindent' is set, line is visually indented. Then, the value
    of 'showbreak' is used to put in front of wrapped lines. This option
    is not used when the 'wrap' option is off.
    Note that <Tab> characters after an <EOL> are mostly not displayed
    with the right amount of white space.

Remark: For 'hard wrap' i.e.

set textwidth=80

Vim introduces a new line at the WORD boundaries (i.e. <space>, <tab>)

4
  • 1
    Thanks Rich for your suggestions I have incorporated them into the solution. Aug 25 at 12:03
  • 1
    @Rich, you are more than welcome. Answering these question is for me a way to learn others but also to learn Vim ;-) Aug 25 at 12:15
  • 1
    In set breakat= ^I!@-+,;./?, the ^I needs to be an actual Tab character, this should be probably called out in part of the answer. Also, there's a leading space there, that might be hard to see (or someone might think it's a typo or a small mistake), but of course it's important to keep it, probably best to call that out too. Or maybe just skip that explicit setting altogether, set breakat-=* is much simpler and effective, and someone who might want to fully set 'breakat' explicitly will probably know what they're doing anyways!
    – filbranden
    Aug 25 at 16:56
  • You are right. The solution of @Rich is fitting with the original demand and as you said less confusing to explain. Aug 25 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.