I use a autocmd to display current tag via Tabgar plugin like this:

autocmd CursorHold * call TagbarCurrentTag

However, after I open CtrlP with :CtrlP for a while, the Tagbar's output No current tag will overwrite the input area of CtrlP.

So I need to identify if I am in a CtrlP buffer to avoid displaying current tag. Maybe use filetype?

Any ideas? Thanks very much!

  • Did you manage to figure out a solution?
    – Luke Davis
    Jun 1, 2018 at 22:00

2 Answers 2


The CtrlP buffer has the name ControlP, so you should just be able to check this:

autocmd CursorHold * if bufname("%") != 'ControlP' | call TagbarCurrentTag() | endif

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=
function! EIon()
  set eventignore=CursorHold,CursorHoldI,CursorMoved,CursorMovedI,TextChanged,TextChangedI
function! EImap()
  nnoremap <silent> <buffer> <Esc> :q<CR>:EIoff<CR>
  nnoremap <silent> <buffer> <C-c> :q<CR>:EIoff<CR>
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 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.

  • Could you elaborate on why g:ctrlp_buffer_func didn't work?
    – Rich
    Aug 1, 2018 at 15:10
  • @Rich No idea why. But after setting the variable as above, I had the same problems. Anyway now I use fzf.vim and my life is happier.
    – Luke Davis
    Aug 1, 2018 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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