vim - 为什么 Vim 将缩进与括号/冒号对齐?
问题描述
我在 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
解决方案
正如马特所提到的,您可能不想使用cindent
不是 C 或类 C 语言的东西,因为它有很多关于 C 语法的硬编码知识,这些知识通常不适用于文本,甚至不适用于其他编程像 Python 或 Ruby 这样的语言。
你可以做的是这样的:
" For general usage.
set autoindent
autocmd FileType c setl cindent noautoindent
这将autoindent
用于不是 C 的东西,而是cindent
用于 C。如果您使用其他语言,您可以为cpp
、java
等添加额外的节。您还可以使用这种类型的autocmd
语句来执行诸如调整缩进级别之类的事情(通过ts
、sts
和sw
) 或在制表符和空格之间切换,具体取决于您使用的语言规范(例如,Ruby 的 2 个空格或 Go 的 8 个空格制表符)。
对于文本,您可能还需要调整formatlistpat
以调整构成列表标题的内容,当启用自动缩进时,确定是否应缩进下一行以继续列表。这可能是这里发生的事情的一部分。我用于该选项的值是^[.-*+•]\\+\\s\\+
,这不应该导致考虑冒号。
推荐阅读
- c# - C#中的Android Xamarin灰色菜单项
- javascript - 数组中未定义的元素,其中包含随机数
- javascript - 为什么我有错误加载资源失败:net::ERR_FILE_NOT_FOUND?
- javascript - window.open 是否阻塞了我的其他 javascript 行?
- c# - 基于列表的任务系统
- python - Matplotlib 堆叠直方图 numpy.ndarray 错误
- javascript - Vanilla Javascript 在预算应用程序上添加 This.Title, Value, Amount for Expense Form
- json - 在 Elasticsearch 中混合 DSL 和 URI 查询
- amazon-web-services - Amazon MQ RabbitMQ 连接
- android - Android实时数据库抛出错误:客户端离线但它不是