In Vim, the
'formatoptions'
setting controls how automatic text formatting is performed. It accepts
a string of single-character flags, each enabling a specific behavior.
You can view the current value in your Vim session with the command :set fo? or get a detailed explanation of all flags using the Vim help documentation via :help fo-table. The common and widely recognized
formatoptions flags are:t: Auto-wrap text at the width specified by the'textwidth'option.c: Auto-wrap comments at'textwidth', automatically inserting the current comment leader character(s) (defined by'comments'or'commentstring').q: Allow formatting with thegqoperator.r: Automatically insert the current comment leader after pressing<Enter>in Insert mode.o: Automatically insert the current comment leader after pressingoorOin Normal mode.n: Recognize numbered lists when formatting, using the pattern defined in'formatlistpat'. This helps avoid joining list items into a single paragraph.b: Auto-wrap text (backwards) when a line grows longer than'textwidth'. The line is broken at the last white space before'textwidth'.v: Vi-compatible auto-wrapping (wraps at'textwidth'in Insert mode).j: Delete comment characters when joining lines using theJcommand.l: Leave long lines as they are when entering Insert mode; only format if a line explicitly exceeds'textwidth'due to typing.m: Join with a space between the joined lines if there isn't one already.p: Do not auto-wrap paste. When pasting text in Insert mode, do not apply auto-wrapping based on'textwidth'.u: Undo separate; make anundocommand revert one line at a time instead of the entire paragraph formatting operation.2: Keep the indent of the second line when a paragraph is formatted (useful for some programming styles).1: Do not break a line after a single character (e.g., prevent single-letter words from being alone on the next line).- a: Automatic formatting of paragraphs (changes are immediately reformatted).
The default value is typically
tcq. To add an option, you can use :set formatoptions+=<char>, and to remove one, use :set formatoptions-=<char>.
No comments:
Post a Comment