Vim has a
gg=G
Format code directives.
How do I customize this custom rule?
Reply content:
Vim has a gg=G
format code directive.
How do I customize this custom rule?
This question is a bit big, it's not too realistic to say it all, say some basic concepts for reference:
The first thing that you want to know, gg=G
is only the =
key, the rest is just to help =
determine the role
Range only.
=
The working mechanism is this:
- First it looks for the user-specified external indent tool and, if any, uses the tool to indent the target range. The option
to specify an external indent tool is EQUALPRG
, you should look at the documentation for it, and
Vimcasts has a video showing an instance in which Drew Neil demonstrates how to use Par to
Format plain text, followed by an example that shows the formatting of HTML with Pandoc. Although the two examples are
using formatprg
and formatexpr
parameters (corresponding to GQ
instead of =
, formatting
Rather than indentation), but the principle and usage are interlinked.
- However, the
EQUALPRG
default value is empty, and if you do not have the appropriate external indent tool, Vim uses the built-in
Indent function c-indenting and ' Lisp ' , You'd better take a look at both of these documents. In addition, if you use the
Vim compile without the built-in indentation function, you will use the self-contained indent ()
function to work--
This is the last resort, the document is also worth a look (you can use to write your own indentation script). Another important setting for
- is
indentexpr
. Just said that if EQUALPRG
is not set, =
uses the
c-indenting and Lisp features, but if you set the Indentexpr
, the
generation of the preceding and all other built-in indent expressions (indent-expression) are taken.
If you equalprg
indentexpr
are not clear about and silly, it is simple: the former only affects =
the effect of
The latter determines all indentation functions, such as in addition to the use of the =
adjustment indentation, in the INPUT mode
The line feed Vim also automatically adjusts the indentation. So indentexpr
the scope of the impact is even greater, and it is used to define
The main way to indent rules (and one that is also indentkeys
useful, both of which are more well-documented).