简体   繁体   中英

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). (Tab is 2 spaces for me.) Then, when I type } (still in column 3), I want } to shift to column 1.

When I do this in a .cpp file, the cursor moves automatically to column 1.

When I do this in another file ( .wiki in my case), it does not move. The } appears in column 3.

I thought this was controlled by 'autoindent' and 'smartindent', both of which are set in case of wiki file. 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?

(Edit for clarity: I am using the '.wiki' filetype defined in vimwiki plugin.)

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. To insert a new list marker, the plugin redefines a few mappings, they are mentioned in :help vimwiki-lists . Namely, o and O in normal mode, and <CR> in insert mode. 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 ). This works because deindentation, as per :help smartindent , happens only if the closing brace is the first thing you type on the line.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM