Is there a Vim equivalent to the Linux / Unix fold command?

I understand that there is a way to hide / collapse lines in Vim, but what I'm looking for is a way to select a block of text and have lines flow around Vim in or near column 80.

Basically, I want to use this in comments in situations where I add text to an existing comment that clicks on it for more than 80 characters. It would also be nice if he could insert a comment marker at the beginning of the line when it also wraps around. In addition, I would prefer that this solution is not intended to auto-update the entire file, since I have a specific convention that I use when it comes to ensuring that my structured code is under a string length of 80 characters.

This is mainly for Python code, but I'm also interested in learning a general solution to the problem in case I have to apply it to other types of text.

+6
python comments vim formatting textwrapping
source share
2 answers
gq 

It is controlled by the textwidth parameter, see ":help gq" for more information.

gq will work on the current line by default, but you can select a visual block with Ctrl + V and format several lines / paragraphs.

gqap contains the current β€œparagraph” of text.

+11
source share

Take a look at ": help =" and ": help 'equalprg"

 :set equalprg=fold 

and in normal mode == filters the current line through an external bend program. Or visually select something and press =

0
source share

All Articles