c - 如何在vim中仅用一个制表符自动缩进分割线?

标签 c vim

启用 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 have autoindent on.

:help autoindent also mentions two alternative settings: cindent and indentexpr, both of which make vim ignore the value of smartindent.

我想从那里你应该使用以下选项

:set autoindent
:set nosmartindent

也许

:set noindentexpr

关于c - 如何在vim中仅用一个制表符自动缩进分割线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48968779/

相关文章:

c - 二维实时绘图与 C

python ctypes 返回零作为数组中的第一个元素?

python - 如何在 vim 正则表达式中保留相同的子字符串

php - 用于 Web 开发的 vim 的最佳配置是什么?

vim - 在Vim中移动行

vim - 在 fzf.vim 中使用带有标志的 Ripgrep

c - 在 C 中替换数组的元素

c - 无法在/usr/share中创建目录

c - 流和 llvm 错误

django - 仅为 Django 项目配置 Django SnipMate 片段