Automatic closing brackets for Vim [closed]

大兔子大兔子 提交于 2019-11-27 06:37:40

For those of us, who want a vanilla vim:

inoremap " ""<left>
inoremap ' ''<left>
inoremap ( ()<left>
inoremap [ []<left>
inoremap { {}<left>
inoremap {<CR> {<CR>}<ESC>O
inoremap {;<CR> {<CR>};<ESC>O

This autocomplete in insert mode, provided set paste is not set. Keep it in the vimrc to avoid typing it every time and when we don't want the mapping, we need to escape it using ctrl + v before typing the mapped char like ( { etc.

romainl

I've just tested ClosePairs, AutoClose, DelimitMate and AutoClose in Vim 7.4.131 on Ubuntu, using Pathogen.

Not surprisingly at all, all of them work.

Your question should be rephrased since you are not searching for "an auto closing plugin that works in 7.4"… because all of them do. What you should ask is "Here is my setup, how come none of the "auto closing" plugins work for me?".

A question one could answer with: "It's a mess. Start by commenting out everything before line 95."

Also, Vim is a very stable environment: "not being actively worked" on doesn't mean "not worth trying". Quite the contrary, actually.

Giving a vote for delimitMate before angry mods close the question for being opinion-based.

Adding a new candidate: there's a plugin called lexima. It was introduced in October 2014, so it's rather new. According to the author, it features high customizability and dot-repeatability. It can also be customized to auto-close def - end pairs as in ruby.

Here's the presentation by the author in the VimConf held in Japan, which compares different ways to achieve auto-closing functionalities.

I'm answering my own question because I figured out why none of the plugins seemed to work for me. It seems the problem is related to the mksession feature in vim, I was only trying out these plugins within a saved session and for some reason that seems to prevent the plugins from working for some unknown reason. The plugins seem to be installed and "working" fine (as in the commands from the plugin are found etc.). Without opening a saved session at least delimitMate started working for me.

xptemplate is a snippets plugin that includes an option for autocompleting brackets/braces/etc. Install it and set

let g:xptemplate_brace_complete = '([{'

in your .vimrc. They start on the same line but if you hit enter it positions them correctly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!