I figured out how to solve this problem, more or less. I had a similar issue with some CursorMoved
autocommands that were rendering CtrlP
unusable; the author claims that when CtrlP is opened all autocommands are disabled but it seems the suite of Cursor*
autocommands are not included in this list.
Here is my workaround:
function! EIoff()
set eventignore=
endfunction
function! EIon()
set eventignore=CursorHold,CursorHoldI,CursorMoved,CursorMovedI,TextChanged,TextChangedI
endfunction
function! EImap()
nnoremap <silent> <buffer> <Esc> :q<CR>:EIoff<CR>
nnoremap <silent> <buffer> <C-c> :q<CR>:EIoff<CR>
endfunction
command! EIon call EIon()
command! EIoff call EIoff()
command! EImap call EImap()
nnoremap <silent> <C-p> :EIon<CR>:CtrlP<CR>:EImap<CR>
let g:ctrlp_map=''
augroup eirestore
au!
au BufEnter * call EIoff()
augroup END
Basically, we override the default <C-p>
mapping. The EImap
command sends a mapping to the CtrlP buffer (notice it comes after the :CtrlP
), so that if we re-enter the original buffer, the Cursor*
autocommands are turned back on. Cancelling CtrlP completion and re-entering the original buffer does not seem to trigger the BufEnter
autocommand. But if you open a new file, the BufEnter
autocommand will indeed be triggered (hence the new autocommand).
Using simply :noautocmd CtrlP
did not work. Using the enter/exit CtrlP functions (for example, let g:ctrlp_buffer_func={'enter':'EIon', 'exit':'EIoff'}
; see documentation) did not work. Using nnoremap <C-p> :CtrlP<CR>:setlocal eventignore=CursorMoved,CurHold...<CR>
did not work for me because one of my autocommands was triggered right away upon entering the CtrlP buffer, resulting in an immediate error. Entering the buffer-local map of <Esc>
as part of my <C-p>
map à la nnoremap <C-p> :CtrlP<CR>:nnoremap <Esc> <stuff>
also doesn't work because the <Esc>
wants to be interpreted literally by the "parent" map of <C-p>
.
It was a pretty challenging/perplexing problem.