'formatoptions') gives the correct start of the line automatically. The same
happens with formatting and auto-wrapping. Opening a line after a line
starting with "/*" or "*" and containing "*/", will cause no comment leader to
be inserted, and the indent of the new line is taken from the line containing
the start of the comment.
E.g.: >
/*
* Your typical comment.
*/
The indent on this line is the same as the start of the above
comment.
All of this should be really cool, especially in conjunction with the new
:autocmd command to prepare different settings for different types of file.
Some examples:
for C code (only format comments): >
:set fo=croq
< for Mail/news (format all, don't start comment with "o" command): >
:set fo=tcrq
<
Automatic formatting *auto-format* *autoformat*
When the 'a' flag is present in 'formatoptions' text is formatted
automatically when inserting text or deleting text. This works nicely for
editing text paragraphs. A few hints on how to use this:
- You need to properly define paragraphs. The simplest is paragraphs that are
separated by a blank line. When there is no separating blank line, consider
using the 'w' flag and adding a space at the end of each line in the
paragraphs except the last one.
- You can set the 'formatoptions' based on the type of file |filetype| or
specifically for one file with a |modeline|.
- Set 'formatoptions' to "aw2tq" to make text with indents like this:
bla bla foobar bla
bla foobar bla foobar bla
bla bla foobar bla
bla foobar bla bla foobar
- Add the 'c' flag to only auto-format comments. Useful in source code.
- Set 'textwidth' to the desired width. If it is zero then 79 is used, or the
width of the screen if this is smaller.
And a few warnings:
- When part of the text is not properly separated in paragraphs, making
changes in this text will cause it to be formatted anyway. Consider doing >
:set fo-=a
- When using the 'w' flag (trailing space means paragraph continues) and
deleting the last line of a paragraph with |dd|, the paragraph will be
joined with the next one.
- Changed text is saved for undo. Formatting is also a change. Thus each
format action saves text for undo. This may consume quite a lot of memory.
- Formatting a long paragraph and/or with complicated indenting may be slow.
==============================================================================
7. Sorting text *sorting*
Vim has a sorting function and a sorting command. The sorting function can be
found here: |sort()|, |uniq()|.
*:sor* *:sort*
:[range]sor[t][!] [b][f][i][l][n][o][r][u][x] [/{pattern}/]
Sort lines in [range]. When no range is given all
lines are sorted.
With [!] the order is reversed.
With [i] case is ignored.
With [l] sort uses the current collation locale.
Implementation details: strcoll() is used to compare
strings. See |:language| to check or set the collation
locale. Example: >
:language collate en_US.UTF-8