How to set options for VIM?
Examples:
Setting | Explanation |
set paste | set options for commands that don't need parameters. |
set filetype=java | Directly set options for commands that accept parameters. |
set guioptions-=option | Remove a specific option from the configuration of a command. |
set guioptions+=option | Add a specific option to the configuration of a command. |
Basic concept
Sentence/Paragraph/Section: http://www.vim.org/htmldoc/motion.html#sentence
Text format
http://www.vim.org/htmldoc/change.html#formatting
Alignment
Setting | Explanation | Examples |
:[range]ce[nter] [width] | center lines | :.,+3 center 80 |
:[range]ri[ght] [width] | right alignment | :% right |
:[range]le[ft] [indent] | left alignment.(Unit of identation is space) | :left 4 |
Format
Command | Explanation | Examples | Note |
gq{motion} | Format lines that {motion} moves over. Cursor is put where {motion} moves to | gqap format a paragraph | Motion: http://www.vim.org/ htmldoc/motion.html |
gw{motion} | Format lines that {motion} moves over. Put cursor back to the original position. | gwj | |
gqgq gqq | Format current line | ||
{Visual}gq | Format highlighted text |
How to control formatting setting of gq command?
Formatting does not change empty lines, but it changes lines only containing white spaces.
(1) textwidth
This option controls length of every formatted line.
If option textwidth is 0, the formatted line length is the screen width (max value is 79).
(2) autoindent
If this option is on, Vim uses indent of the first line for the following lines.
(3) joinspaces (boolean)
Used when lines are joined together. By default, it is on. Use set nojoinspaces to turn it off.
(4) formatprg
Set an external program to format text. In this case, the textwidth and other options have no effect on text formatting.
(5) formatoptions
Most useful options:
t: Auto-wrap text using textwidth. (does not apply to comments)
c: Auto-wrap commens using textwidth.
q: Allow formatting of comments with gq command. When using gq command in comments, blank lines and lines only with comment leaders and white spaces are considered as paragraph delimiters.
r: auto insert comment leader after hitting 'Enter' in Insert mode.
o: auto insert comment leader after hitting 'o' or 'O'.
a: auto format paragraphs when text is inserted or deleted.
w: A trailing non white space ends a paragraph.
Note: Formatting would be applied anyway no matter whether the paragraphs are delimited correctly.
You can use set formatoptions-=a to disable automatic formatting.
More options: http://www.vim.org/htmldoc/change.html#fo-table
(6) comments
This option controls how to format comments (usually in source code).
Default value is
"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-"s: start of a three-piece comment
s{digit}: add extra indent to middle part. Unit is space (not tab).
s-{digit}: remove extra indent to middle part. Unit is space (not tab).
m: middle part of a three-piece comment. Middle part is left adjusted with start part of the comment by default. This is controlled by option l.
b: blanks required after the specified string.
e: end of a three-piece comment
x: In C++ comment, just type / to end a comment when middle-comment string is inserted. The space between middle-part and / would be removed automatically.
n: recognize numbered list(see below for details)
More options: http://www.vim.org/htmldoc/change.html#format-comments
My setting is
set textwidth=79 set formatoptions=tcqron
How to format numbered lists?
This sometimes is really tricky.
See this post: http://objectmix.com/editors/332035-vim-how-create-bullet-list-numbered-list.html
Usually, textwidth must be set and formatoptions must include nwt.
Also see option formatlistpat(flp) for how to set list header. That is used by vim to recognize numbered lists.
No comments:
Post a Comment