Preface: Newish to vim so please excuse any rookie mistakes.

I normally use vim-latex/latex-suite to edit .tex files, and it works great. I've also started to use vim to edit scripts, and I use the autoclose plugin to help with that. Unfortunately, autoclose interferes with some of the imaps in latex-suite, so I'd like to disable it when editing tex files.

Currently, I've tried the following autocmd in my vimrc:

autocmd BufNewFile,BufRead *.tex AutoCloseoff

and it seems to work ok for the most part (it seems to correctly disable autoclose when I'm editing tex files). However, I'm not able to use the original imaps with latex-suite.

For example (the pipe represents the cursor)

Without autoclose installed (what I want):

(( turns into (|)<++>

With autoclose installed:

(( turns into ((|))

With autoclose installed but disabled:

(( turns into ((



2 Answers 2


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.


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 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

  • Thank you very much for your thorough answer!
    – Geoffroi
    Commented Mar 24, 2019 at 19:18

Patch AutoClose--alves to skip setup for selected filetypes

❯ git diff
diff --git a/plugin/AutoClose.vim b/plugin/AutoClose.vim
index d91ba8b..218206b 100644
--- a/plugin/AutoClose.vim
+++ b/plugin/AutoClose.vim
@@ -482,6 +482,9 @@ endfunction

 function! s:CreateMaps()
     silent doautocmd FileType
+    if index(exists("g:autoclose_blacklist")? g:autoclose_blacklist : [], &ft) >= 0
+        return
+    endif
     call s:DefineVariables()
     call s:CreatePairsMaps()
     call s:CreateExtraMaps()

Add to your vimrc to skip 'tex' files:

let g:autoclose_blacklist = ['tex']

Now Autoclose--alves should NOT create its mappings in tex files but in all other file types.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.