启用 cindent 后,如果您在“不完整”语句中插入换行符,它会像这样自动缩进(来自 here 的示例):
a = b + 9 *
█
但是,如果您在任何带有括号的内容(例如函数调用或 if 语句)中执行此操作,它会自动缩进双倍的 'shiftwidth'
:
printf("%s %d\n", "this is a number"
█
我希望它只插入一个'shiftwidth'
,就像第一个示例中一样。
另外,+N
cinoption没有帮助:如果我这样做:set cinoptions+=+0
,尽管它停止自动缩进第一个示例,但它仍然在带有括号的情况下,将双倍我的'shiftwidth'
。
我的.vimrc
:
set ts=4 sw=4
set softtabstop=4
"set expandtab
color vim-material
set guifont=Consolas:h11:cANSI:qDRAFT
set nu
syntax on
set backspace=indent,eol,start
set ruler
set relativenumber
set hidden
set wildmenu
filetype plugin indent on
"set autoindent
set formatoptions-=cro
set rulerformat=%l,%v
set cinoptions+=:0
最佳答案
您错误地选择了 SO 站点。我从这里的信息中找到了答案https://vi.stackexchange.com/questions/5818/what-is-the-difference-between-autoindent-and-smartindent-in-vimrc
autoindent
essentially tells vim to apply the indentation of the current line to the next (created by pressing enter in insert mode or with O or o in normal mode.
smartindent
reacts to the syntax/style of the code you are editing (especially for C). When having it on you also should haveautoindent
on.
:help autoindent
also mentions two alternative settings:cindent
andindentexpr
, both of which make vim ignore the value ofsmartindent
.
我想从那里你应该使用以下选项
:set autoindent
:set nosmartindent
也许
:set noindentexpr
关于c - 如何在vim中仅用一个制表符自动缩进分割线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48968779/