[英]How to autoindent closing brace in vim
I want to type 我要输入
tag {
}
When I hit 'enter' after {
, my cursor is 2 spaces indented (in column 3). 当我在{
之后点击'enter'时,我的光标缩进了2个空格(在第3列中)。 (Tab is 2 spaces for me.) Then, when I type }
(still in column 3), I want }
to shift to column 1. (选项卡对我来说是2个空格。)然后,当我输入}
(仍在第3列)时,我希望}
移至第1列。
When I do this in a .cpp
file, the cursor moves automatically to column 1. 当我在.cpp
文件中执行此操作时,光标会自动移动到第1列。
When I do this in another file ( .wiki
in my case), it does not move. 当我在另一个文件(本例中为.wiki
中执行此操作时,它不会移动。 The }
appears in column 3. }
出现在第3列中。
I thought this was controlled by 'autoindent' and 'smartindent', both of which are set in case of wiki file. 我以为这是由'autoindent'和'smartindent'控制的,这两个都是在Wiki文件的情况下设置的。 What am I missing? 我想念什么?
What other configuration information can I provide to help debug? 我还可以提供哪些其他配置信息来帮助调试? How can I compare the configuration options between cpp file and wiki file? 如何比较cpp文件和wiki文件之间的配置选项?
(Edit for clarity: I am using the '.wiki' filetype defined in vimwiki plugin.) (为清楚起见,请编辑:我使用的是vimwiki插件中定义的'.wiki'文件类型。)
The problem comes from the way the plugin handles lists' editing. 问题出在插件处理列表编辑的方式上。 Which is surprising, because the tag { }
construct probably shouldn't be treated as one. 令人惊讶的是,因为tag { }
构造可能不应该被视为一个。 To insert a new list marker, the plugin redefines a few mappings, they are mentioned in :help vimwiki-lists
. 要插入一个新的列表标记,该插件重新定义了一些映射,它们在:help vimwiki-lists
中提到。 Namely, o
and O
in normal mode, and <CR>
in insert mode. 即, o
和O
在正常模式下, <CR>
在插入模式下。 Things they are mapped to have more-or-less the same behaviour when it comes to interaction with smartindent
: they disable deindenting by inserting and deleting a dummy character on the new line (see, for example, here ). 与smartindent
进行交互时,它们映射为具有几乎相同的行为:通过在新行上插入和删除虚拟字符来禁用去凹入(例如,参见此处 )。 This works because deindentation, as per :help smartindent
, happens only if the closing brace is the first thing you type on the line. 之所以可行,是因为::in :help smartindent
缩排仅在大括号是您在行中键入的第一行时才发生。
This can be disabled by removing relevant mappings, but doing so will also break the lists system of the plugin. 可以通过删除相关映射来禁用此功能,但是这样做也会破坏插件的列表系统。 To fix that , you can duplicate those mappings using some other keys. 要解决此问题 ,您可以使用其他一些键来复制这些映射。
This might be worth discussing with the plugin's author, I don't think treating everything as a part of a list for indentation purposes is really what they indended. 这可能值得与插件的作者讨论,我不认为将所有内容都作为缩进目的视为列表的一部分确实是他们的意图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.