autoindent是vim中smartindent的子集?

Hab*_*wad 22 vi vim

:help autoindent:在开始新行时键入当前行的缩进(在"插入"模式下键入或使用"o"或"O"命令时)....

:help smartindent:开始换行时进行智能自动调整.适用于类似C的程序,但也可用于其他语言....

通常情况下,'autoindent'也应该在使用'smartindent'时打开. 缩进自动插入:

  • 在以'{'结尾的行之后.
  • 以"cinwords"中的关键字开头的一行后面.
  • 在以'}'开头的行之前(仅使用"O"命令).

    当输入'}'作为新行中的第一个字符时,该行将被赋予与匹配的'{'相同的缩进....

smartindent在开始换行时还会从当前行处理缩进.这意味着autoindent功能是smartindent功能的子集,如果smartindent打开则不需要autoindent,对吧?为什么自动缩进应该被打开?

rom*_*inl 44

smartindent是一个古老的剧本,当它被写成时,意味着是一个"聪明"的补充autoindent.从那时起,大多数语言都具有特定的缩进功能或使用cindent特定的选项.

一般来说,smartindent根本不应该使用.

以下几行通常足以处理缩进:

set autoindent
filetype plugin indent on
Run Code Online (Sandbox Code Playgroud)

autoindent 并非绝对必要,但在使用明文时最好使用它.