Limiting text width does not work properly unless pasted at end of line

I know we can use :set tw=80 to limit the width of the text. However, if we insert the text to the end, this function does not work at all.

For example, let's say we print "Want to get answers to your questions sent to you by email?"

If we keep typing after "?", tw works fine. But if we insert before the words "have", it does not interrupt the line, even if it exceeds the specified width of the text.

Is there any way to do this work in the latter case?

+4
source share
2 answers

This can be configured using formatoptions or formatexpr , but I'm not sure how.
Another solution is to manually format with gq when choosing a visual line, i.e. add a dividing line if the text width> = tw .

  • Enter any text that you like inside another block of text, thereby making it 80 characters wide.
  • Select text that you think will be incorrectly detected with V ( Shift v )
  • gq

From :h gq :

 Format the lines that {motion} moves over. Formatting is done with one of three methods: 1. If 'formatexpr' is not empty the expression is evaluated. This can differ for each buffer. 2. If 'formatprg' is not empty an external program is used. 3. Otherwise formatting is done internally. In the third case the 'textwidth' option controls the length of each formatted line (see below). If the 'textwidth' option is 0, the formatted line length is the screen width (with a maximum width of 79). The 'formatoptions' option controls the type of formatting fo-table. [..] 

For more information on how the text version of Vim works, see How to Use Vims Text Width as a Pro

+2
source

You can try

 :set fo+=a 

which reformatts your paragraph as you type.

See :h fo-table .

+4
source

Source: https://habr.com/ru/post/1483324/


All Articles