Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 245
Joe Holloway Avatar asked Feb 05 '09 15:02

Joe Holloway


People also ask

Is vim a Unix command?

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.

What is Unix Vim?

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.

How do you fold in Linux?

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.

How do you wrap lines in Linux?

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.


1 Answers

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.

like image 200
Philip Reynolds Avatar answered Sep 22 '22 02:09

Philip Reynolds