首页 > 代码库 > vim中的缩进
vim中的缩进
缩进
缩进的设置
- autoindent (ai)
Copy indent from current line when starting a new line (typing
in Insert mode or when using the “o” or “O” command). If you do not
type anything on the new line except or CTRL-D and then type
, CTRL-O or , the indent is deleted again.
简单来讲就是产生的新行的缩进值与上一行保持一致。
- smartindent (si)
An indent is automatically inserted:
- After a line ending in ‘{‘.
- After a line starting with a keyword from ‘cinwords‘.
- Before a line starting with ‘}‘ (only with the “O” command).
When typing ‘}‘ as the first character in a new line, that line is
given the same indent as the matching ‘{‘.
在autoindent的基础上更加smart了:对编程中{}的相关缩进做了较好的支持。
- cindent (ci)
Enables automatic C program indenting.
对C程序适配的自动缩进。并且与“cinkeys”、“cinwords”、“cinoptions”配合产生效果。
- indentexpr (inde)
Expression which is evaluated to obtain the proper indent for a line.
It is used when a new line is created, for the |=| operator and
in Insert mode as specified with the ‘indentkeys‘ option.
When this option is not empty, it overrules the ‘cindent‘ and
‘smartindent‘ indenting. When ‘lisp‘ is set, this option is
overridden by the Lisp indentation algorithm.
更加个性化的指定缩进的设置。还可以用Lisp的缩进设置哦~
- 这几种缩进设置之间的关系
There are in fact four main methods available for indentation, each one
overrides the previous if it is enabled, or non-empty for ‘indentexpr‘:
‘autoindent‘ uses the indent from the previous line.
‘smartindent‘ is like ‘autoindent‘ but also recognizes some C syntax to increase/reduce the indent where appropriate.
‘cindent‘ Works more cleverly than the other two and is configurable to different indenting styles.
‘indentexpr‘ The most flexible of all: Evaluates an expression to compute the indent of a line. When non-empty this method overrides the other ones. See |indent-expression|.
- paste
当开启了以上的那些xxindent之后,从其他窗口粘贴到vim时会因为缩进出现格式的错乱,为了避免这种现象,可以通过开启paste选项使得各种indent失效,保持原文的缩进。完成之后再将其关闭。当paste选项开启时,当切换到插入模式时,下方的状态栏会有提示:insert (paste)
vim中的缩进