I realize there's a way in Vim to hide/fold lines, but what I'm looking for is a way to select a block of text and have Vim wrap lines at or near column 80.
Mostly I want to use this on comments in situations where I'm adding some text to an existing comment that pushes it over 80 characters. It would also be nice if it could insert the comment marker at the beginning of the line when it wraps too. Also I'd prefer the solution to not autowrap the entire file since I have a particular convention that I use when it comes to keeping my structured code under the 80 character line-length.
This is mostly for Python code, but I'm also interested in learning the general solution to the problem in case I have to apply it to other types of text.
Available both as a command line interface and as a standalone program with a GUI, Vim is a text editor that is a modal version of the vi editor created for Unix in the 1970s; Vim stands for vi improved.
On Unix-like operating systems, vim, which stands for "Vi Improved", is a text editor. It can be used for editing any kind of text and is especially suited for editing computer programs.
To use the fold command, simply specify the name of a file whose lines you wish to wrap. If no file is specified, fold will read from standard input. Old Unix terminals have a max length of 80 characters. Therefore, by default, the fold command will output 80 characters for each line before wrapping to the next.
fold command in Linux wraps each line in an input file to fit a specified width and prints it to the standard output. By default, it wraps lines at a maximum width of 80 columns but this is configurable. To fold input using the fold command pass a file or standard input to the command.
gq
It's controlled by the textwidth option, see ":help gq"
for more info.
gq
will work on the current line by default, but you can highlight a visual block with Ctrl+V and format multiple lines / paragraphs like that.
gqap
does the current "paragraph" of text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With