2

My vimrc about wrap is set like this:

set wrap "Wrap lines
set breakindent " indent after line wrapped

But the wrapped lines are not equal in length, such as:

line 1:   some contents ..... <end>
          continued line ..... other contents <end>
line 2: ....

The line 1 and its wrapped line does not agree in length, and neither of them is as long as the longest length the window provides.

Sometimes when I write Chinese characters, the line just wrapped at the position of space even though it is not finished, like this:

1.<space>
地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地
地地地地地地地地地地地地地地地地地地地地寺地

or like this:

line 1: 地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地地寺地
        地地地地地地地地地地地地地地地地地地地地地地地地地地地<space>
        地地地地地地地地地地地地地地地地地地地地地地地地地
line 2: ...

How could I make the wrapped lines the same length, and thus make the paragraph a shape of rectangular?

4
  • 2
    Possible duplicate of Can I justify text in Vim?
    – Herb
    Commented Jan 24, 2018 at 4:53
  • @HerbWolfe Sorry, I did not see explicit relation between that question and mine. Would you make it clearer?
    – CoinCheung
    Commented Jan 24, 2018 at 10:11
  • What you are asking for is called full justification.
    – Herb
    Commented Jan 24, 2018 at 12:05
  • 1
    @HerbWolfe I know, and how about my second problem about Chinese characters or a combination of Chinese and English? The wrap points fall on the wrong places of where spaces are in stead of the Chinese word at the length of the line.
    – CoinCheung
    Commented Jan 24, 2018 at 12:37

2 Answers 2

2

Since 8.2.3198 vim has breadkindentopt with list:-1:

'breakindentopt' 'briopt' string (default empty)
            local to window
            {not available when compiled without the |+linebreak|
            feature}
    Settings for 'breakindent'. It can consist of the following optional
    items and must be separated by a comma:

....

        list:{n}    Adds an additional indent for lines that match a
                numbered or bulleted list (using the
                'formatlistpat' setting).
        list:-1     Uses the length of a match with 'formatlistpat'
                for indentation.

Which you can use like:

set breakindent breakindentopt=sbr,list:-1 linebreak
" this should be set up per filetype probably
let &formatlistpat = '^line\s\+\d\+:\s*'

enter image description here

And without linebreak it looks more "rectangular"

set breakindent breakindentopt=sbr,list:-1
" this should be set up per filetype probably
let &formatlistpat = '^line\s\+\d\+:\s*'

enter image description here

0

For the second problem, try set formatoptions+=m.

Also see this for reference.

1
  • 4
    Welcome to Vi and Vim! A little explanation via edit would go a long way, especially to avoid link-rot.
    – D. Ben Knoble
    Commented Apr 13, 2021 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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