为什么 Vim 将缩进与 parentheses/colon 对齐?
Why does Vim align indentation to parentheses/colon?
我 运行 在 Vim 中遇到了一个不寻常的缩进问题,我想更好地理解它。下面几行描述了我正在输入的内容:
writing some words
manually indenting this line
this line got automatically indented
here's a line with a colon: some more words
this line is indented as expected
now I introduce (parentheses) and nothing happens
indented as expected
here it comes (parentheses and a colon): let the magic begin
why do parentheses+colon indent me to here?
为什么会这样,我怎样才能让它停止? :) 我总体上喜欢 cindent,所以我宁愿保留它 autoindent/smartindent。
我的 Vim 设置是:
清空 ~/.vimrc 除了 :set cindent expandtab
禁用所有插件
:verbose set ft? ai? si? cindent? indentkeys? cinkeys? cinoptions? indentexpr? formatoptions?
filetype=
noautoindent
nosmartindent
cindent
indentkeys=0{,0},0),0],:,0#,!^F,o,O,e
cinkeys=0{,0},0),0],:,0#,!^F,o,O,e
cinoptions=
indentexpr=
formatoptions=tcq
Last set from /usr/share/vim/vim81/debian.vim line 3
正如 Matt 提到的,您可能不想将 cindent
用于不是 C 或 C-like 语言的东西,因为它有很多关于 C 语法的硬编码知识' 通常适用于文本,甚至适用于 Python 或 Ruby.
等其他编程语言
你可以做的是这样的:
" For general usage.
set autoindent
autocmd FileType c setl cindent noautoindent
这将对非 C 的事物使用 autoindent
,但对 C 的事物使用 cindent
。如果您使用其他语言,则可以为 cpp
、[=15 添加额外的节=],等等。您还可以使用这种类型的 autocmd
语句来执行调整缩进级别(通过 ts
、sts
和 sw
)或在选项卡之间切换等操作和 spaces,具体取决于您使用的语言规范(例如,Ruby 的 2 spaces 或 Go 的 8-space 选项卡)。
对于文本,您可能还需要调整 formatlistpat
以调整构成列表的内容 header,当启用自动缩进时,它决定是否应缩进下一行以继续列表.这可能是这里发生的事情的一部分。我为该选项使用的值是 ^[.-*+•]\+\s\+
,这不应导致考虑冒号。
我 运行 在 Vim 中遇到了一个不寻常的缩进问题,我想更好地理解它。下面几行描述了我正在输入的内容:
writing some words
manually indenting this line
this line got automatically indented
here's a line with a colon: some more words
this line is indented as expected
now I introduce (parentheses) and nothing happens
indented as expected
here it comes (parentheses and a colon): let the magic begin
why do parentheses+colon indent me to here?
为什么会这样,我怎样才能让它停止? :) 我总体上喜欢 cindent,所以我宁愿保留它 autoindent/smartindent。
我的 Vim 设置是:
清空 ~/.vimrc 除了 :set cindent expandtab
禁用所有插件
:verbose set ft? ai? si? cindent? indentkeys? cinkeys? cinoptions? indentexpr? formatoptions?
filetype= noautoindent nosmartindent cindent indentkeys=0{,0},0),0],:,0#,!^F,o,O,e cinkeys=0{,0},0),0],:,0#,!^F,o,O,e cinoptions= indentexpr= formatoptions=tcq Last set from /usr/share/vim/vim81/debian.vim line 3
正如 Matt 提到的,您可能不想将 cindent
用于不是 C 或 C-like 语言的东西,因为它有很多关于 C 语法的硬编码知识' 通常适用于文本,甚至适用于 Python 或 Ruby.
你可以做的是这样的:
" For general usage.
set autoindent
autocmd FileType c setl cindent noautoindent
这将对非 C 的事物使用 autoindent
,但对 C 的事物使用 cindent
。如果您使用其他语言,则可以为 cpp
、[=15 添加额外的节=],等等。您还可以使用这种类型的 autocmd
语句来执行调整缩进级别(通过 ts
、sts
和 sw
)或在选项卡之间切换等操作和 spaces,具体取决于您使用的语言规范(例如,Ruby 的 2 spaces 或 Go 的 8-space 选项卡)。
对于文本,您可能还需要调整 formatlistpat
以调整构成列表的内容 header,当启用自动缩进时,它决定是否应缩进下一行以继续列表.这可能是这里发生的事情的一部分。我为该选项使用的值是 ^[.-*+•]\+\s\+
,这不应导致考虑冒号。