Preface: Disambiguation of plugins called “AutoClose”
Plugins on vim.org: Two plugins with the name AutoClose are hosted on vim.org.
The AutoClose plugin #2009
by Thiago Alves which provides the command :AutoCloseoff
and the AutoClose plugin #1849
by Karl Guertin which does not.
Github repositories:
Thiago Alves has created a github repo for his AutoClose plugin: https://github.com/Townk/vim-autoclose.
Furthermore, the version on vim.org is mirrored by http://vim-scripts.org/ to https://github.com/vim-scripts/AutoClose--Alves and not to https://github.com/vim-scripts/AutoClose which again is the plugin by Karl Guertin.
Naive answer: Install into opt
of a vim8 packpath and load on-demand
The plugin AutoClose--Alves installs an autocmd which ensures the availability of its insert mode mappings all the time:
autocmd BufNewFile,BufRead,BufEnter * if !<SID>IsLoadedOnBuffer() | call <SID>CreateMaps() | endif
Furthermore, calling :AutoCloseOff
does not unmap them.
You can verify this by running :AutoCloseOff
and then call
:verbose imap (
i ( * <C-R>=<SNR>32_SetVEAll()<CR><C-R>=<SNR>32_InsertPair("(")<CR><C-R>=<SNR>32_RestoreVE()<CR>
Last set from ~/.vim/plugin/autoclose.vim line 181
:AutoCloseOff
just sets a variable which is taken into account when the mappings are evaluated.
This means it still overrides vim-latex.
A naive attempt to solve the problem would be:
Source Autoclose--Alves only for those filetypes you want to use it.
If you have vim8, you would install it into the opt
folder in a packpath, e.g.
~/.vim/pack/manual/opt/vim-autoclose/plugin/autoclose.vim
and add following to the vimrc
let blacklist = ['tex']
autocmd Filetype * if index(blacklist, &ft) < 0 | packadd vim-autoclose
However, this naive attempt does not actually solve the problem because as soon
as the autocmd is installed, it is also triggered for new or existing tex buffers.
The autocmd installation happens for example also for help buffers. This means even though
you edit only tex files but look into a vim help page with :h <topic>
, the autocmd gets still installed.
If we return from the help page to our tex file, the autocmd will be triggered and the vim-latex mappings are again overwritten.
This really ensures that the AutoClose--Alves mappings are always available.
We are back at square 1.
Final answer: use a different auto-close plugin or patch AutoClose--Alves
A "good plugin" should actually inform the user about situations where mappings are overwritten by using the vim feature map-<unique>
.
The way the plugin AutoClose--Alves is written it is not meant to be disabled for certain filetypes.
A possibility is to modify AutoClose--Alves itself to allow for an option which does not enable it for certain filetypes (see my second answer).
However, there are other plugins which have a similar feature set but IMHO are better vim plugin citizens which is why I recommend to use a different plugin.
For example, the plugins
have as well toggle functions but which actually unmap their own mappings. The remaining problem of the
first answer can here be resolved as the OP has done in the question:
augroup Myftevents
autocmd!
autocmd Filetype tex DelimitMateOff
augroup END
Btw, incompatibility between AutoClose--Alves and vim-latex has already been reported:
https://github.com/Townk/vim-autoclose/issues/82