Automatic formatting of paragraphs
From Vim Tips Wiki
This tip is deprecated for the following reasons:
You CERTAINLY DON'T need to install Cream as this tip suggests. This feature is built into Vim without Cream!
Tip 440 Previous Tip • Next Tip
Created: March 10, 2003 Complexity: intermediate Author: Stanislav Sitar Minimum version: 6.0 Karma: 44/17 Imported from: Tip#440
When I use Vim to create plain-text files (like mail messages) I like the feature that automatically makes lines XY characters long. I simply type ':set tw=60' on the command line, and as I type lines are broken (auto wrapped) before they reach 60 characters length. The problem is, when I latter decide to edit the paragraph. When I delete or add some words, the paragraph looks broken.
The solution is to type '<Esc>gqap' to format a paragraph or make a mapping for this command. However, it annoys me to do it repeatedly.
There is a better solution.
1. Go to http://cream.sourceforge.net/vim.html and download the latest patched Vim
2. Install the program.
3. See :help auto-format.
I will not repeat the docs here. For the impatient, set fotmatoptions to aw2tq ':set fo=aw2tq' and start typing.
The text flows automagically between lines as you type text inside the paragraph.
[edit] Comments
Not bad, but if you do
set linebreak set breakat=\ set nolist
and place a mapping:
"move one 'corsor-line' line instead of one 'code-line' up/down nnoremap j gj nnoremap k gk vnoremap j gj vnoremap k gk
you can also type and edit paragraphs, and will never need to format it (because it will keep one long line :)
Keeping paragraphs as a one long line is a pretty bad idea if the text is to be read by other people, with other tools.
This is double-edge settings. I found it is a disaster for editing scripts, such as vimrc and jsp, but very good for editing free-style text file.
To get the best of both worlds, I used the following:
au BufEnter *.txt setl tx ts=4 sw=4 fo+=n2a
Only all *.txt files will use this auto thing.
Categories: Review | Deprecated | VimTip
