Question

I want to know what is the best practice to format selected text, such that each column does not exceed N characters.

For example I had this text at the begging (Note the text doesn't exceed 80 columns):

    aaaaaaa aaaaa aaaaaa aaaaa aaaaaaa aaaaaaaaaaaaaaa aaaaaaaaa aaaaaaaa   
aaaaa aaaaaaa aaaaaa aaaaaaaaa a aaaa aaaaaaaaa aaaaaaa aaaaaaa aaaa                    
aaaaa aaaaaaa aaaaaaaaa aaaaaaaa aaaaaa aaaaaaaa aaaaa a aaaaaaaaaaaaaa                
aaaaaaa aaaa aaaaaaaaaaa aaaaaa aaaaaaaa aaaaaaa aaaaaaaaa aaaaaaaaaa                 
aaaaaa aaaaaaaaaa aaaaaaaaaaaa aaaaa aaaaa aaaaa aaaaaaaa aaaaa aaa aaaaa   

And then suddenly I had to change the first line and and text like:

BBBBBB BB B BBB BB BBB BBB BBB BBBB BBBBBBBBBBBB

Such the text will become similar to this:

    aaaaaaa aaaaa BBBBBB BB B BBB BB BBB BBB BBB BBBB BBBBBBBBBBBB aaaaaa aaaaa aaaaaaa aaaaaaaaaaaaaaa aaaaaaaaa aaaaaaaa  
aaaaa aaaaaaa aaaaaa aaaaaaaaa a aaaa aaaaaaaaa aaaaaaa aaaaaaa aaaa                      
aaaaa aaaaaaa aaaaaaaaa aaaaaaaa aaaaaa aaaaaaaa aaaaa a aaaaaaaaaaaaaa                 
aaaaaaa aaaa aaaaaaaaaaa aaaaaa aaaaaaaa aaaaaaa aaaaaaaaa aaaaaaaaaa          
aaaaaa aaaaaaaaaa aaaaaaaaaaaa aaaaa aaaaa aaaaa aaaaaaaa aaaaa aaa aaaaa

So what is the easiest way to format the text to kind force the limit on columns up to 80 characters?

P.S

I don't wan't to format every line manually.

Was it helpful?

Solution

See here.

Basically, :set tw=80, then use the gq command to reformat preexisting text. To auto-wrap the entire file, go to the first line and type gqG (note capital G).

OTHER TIPS

See this question.

Set textwidth to 80, move to the start of the file (can be done with Ctrl-Home or gg), and type gqG.

gqG formats the text starting from the current position and to the end of the file. It will automatically join consecutive lines when possible. You can place a blank line between two lines if you don't want those two to be joined together.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top