Konstantin Weitz
Konstantin Weitz

Reputation: 6422

Automatically Break/Merge Lines in Vim

I'm creating a document in latex and I would like all lines to be broken at roughly 80 characters. This is easy to do manually when writing new text, but the editing of old text often leads to lines that are longer or shorter. Fixing it leads to other lines that need to be changed and so on.

Is there an automatic way in vim to break lines after 80 characters and merge them if possible?

Upvotes: 1

Views: 246

Answers (2)

FDinoff
FDinoff

Reputation: 31419

To make lines be only 80 characters long you can use textwidth

Assuming your latex file has the extension .tex you can add the following line to your vimrc

autocmd BufReadPost *.tex setlocal textwidth=80

To format the current paragraph you can use gqap

Upvotes: 2

chris
chris

Reputation: 5018

I use the following setup.

set textwidth=80

(either manually or in your ~/.vimrc). Then if I have a block of text in a file that I want to format I first mark it in visual mode (i.e., shift-V to switch to visual line mode and than mark all the lines you want to format) and then use gq. See also :help gq.

Upvotes: 1

Related Questions