Is there any WORKING plugin for Vim 7.4 that would automatically close brackets ('{}', '[]', '()') and maybe insert some carriage returns (for '{}' at least)?
I know this question has been asked quite a few times but none of the answers either do not seem to work in vim 7.4 or the plugin has not been updated or something.
So far I've tried vim-smartinput, autoclose and delimitmate and NONE of these have managed to insert any closing characters even though I have enabled the plugins and they otherwise seem to be active. I don't know if there has been some changes in vim that somehow breaks these plugins. None of these plugins seem to be updated in a ~year at least. Any working solutions that would work with vim 7.4?
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.
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.
来源:https://stackoverflow.com/questions/21316727/automatic-closing-brackets-for-vim