Suppose I'm editing a single file in buffer 1. When I open a new file with :CtrlP, instead of opening it in buffer 2, ctrlp opens buffer 3. If I try to open another file with :CtrlP now, buffer 4 would be opened.
That is to say, buffer 2 is skipped for some reason.
Here is the output of :buffers:
:buffers
1 "main.c" line 5
3 # "tags" line 20
4 %a "Makefile" line 10
However, buffer 2 is created as expected when I manually open files with :edit, so I think it might be a bug of ctrlp. Also, if I start vim without specifying any file, buffer 1, 3, 4, 5, ... would be created sequentially.
After some research, I think the function s:PrtExit() is very fishy. I guess it's used to disable autocommands which would close the buffers, since if I comment out these lines, buffer 3, 4, 5, ... would be created sequentially, skipping both buffer 1 and 2:
fu! s:PrtExit()
let bw = bufwinnr('%')
exe bufwinnr(s:bufnr).'winc w'
if bufnr('%') == s:bufnr && bufname('%') == 'ControlP'
" noa cal s:Close()
" noa winc p
els
" exe bw.'winc w'
en
endf
Did you miss anything there?
Version information
$ uname -a
Darwin 192.168.0.111 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Aug 26 2017 15:16:30)
MacOS X (unix) version
Included patches: 1-997
Compiled by Homebrew
Huge version without GUI. Features included (+) or not (-):
+acl +file_in_path +mouse_sgr +tag_old_static
+arabic +find_in_path -mouse_sysmouse -tag_any_white
+autocmd +float +mouse_urxvt -tcl
-balloon_eval +folding +mouse_xterm +termguicolors
-browse -footer +multi_byte +terminal
++builtin_terms +fork() +multi_lang +terminfo
+byte_offset -gettext -mzscheme +termresponse
+channel -hangul_input +netbeans_intg +textobjects
+cindent +iconv +num64 +timers
-clientserver +insert_expand +packages +title
+clipboard +job +path_extra -toolbar
+cmdline_compl +jumplist +perl +user_commands
+cmdline_hist +keymap +persistent_undo +vertsplit
+cmdline_info +lambda +postscript +virtualedit
+comments +langmap +printer +visual
+conceal +libcall +profile +visualextra
+cryptv +linebreak +python +viminfo
+cscope +lispindent -python3 +vreplace
+cursorbind +listcmds +quickfix +wildignore
+cursorshape +localmap +reltime +wildmenu
+dialog_con -lua +rightleft +windows
+diff +menu +ruby +writebackup
+digraphs +mksession +scrollbind -X11
-dnd +modify_fname +signs -xfontset
-ebcdic +mouse +smartindent -xim
+emacs_tags -mouseshape +startuptime -xpm
+eval +mouse_dec +statusline -xsmp
+ex_extra -mouse_gpm -sun_workshop -xterm_clipboard
+extra_search -mouse_jsbterm +syntax -xterm_save
+farsi +mouse_netterm +tag_binary
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o vim -lncurses -liconv -framework Cocoa -mmacosx-version-min=10.12 -fstack-protector-strong -L/usr/local/lib -L/usr/local/Cellar/perl/5.26.0/lib/perl5/5.26.0/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc -F/usr/local/opt/python/Frameworks -framework Python -lruby.2.4.1 -lobjc
dotfile
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last change: 2008 Dec 17
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" vim-plug, Minimalist Vim Plugin Manager
" https://github.com/junegunn/vim-plug
" You'll need to call `:PlugInstall` to install the plugins
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-sensible' " https://github.com/tpope/vim-sensible
Plug 'ctrlpvim/ctrlp.vim' " https://github.com/ctrlpvim/ctrlp.vim
Plug 'vim-airline/vim-airline' " https://github.com/vim-airline/vim-airline
Plug 'bling/vim-bufferline' " https://github.com/bling/vim-bufferline
Plug 'xolox/vim-misc' " https://github.com/xolox/vim-misc
Plug 'xolox/vim-easytags' " https://github.com/xolox/vim-easytags
Plug 'majutsushi/tagbar' " https://github.com/majutsushi/tagbar
Plug 'skywind3000/asyncrun.vim' " https://github.com/skywind3000/asyncrun.vim
call plug#end()
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file
endif
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
" Molokai colorscheme
syntax enable
let g:rehash256 = 1
colorscheme molokai
" Define tab as 4 spaces
" Taken from http://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces
set tabstop=4 " The width of a TAB is set to 4.
" Still it is a \t. It is just that
" Vim will interpret it to be having
" a width of 4.
set shiftwidth=4 " Indents will have a width of 4
set softtabstop=4 " Sets the number of columns for a TAB
set expandtab " Expand TABs to spaces
" Set a 80-column indication line
" https://stackoverflow.com/a/3305790/5399734
highlight OverLength ctermbg=darkred ctermfg=white guibg=#FFD9D9 guifg=white
match OverLength /\%>79v.\+/
" Highlight the current line
set cursorline
" Airline
" https://github.com/vim-airline/vim-airline
let g:airline_powerline_fonts = 1
let g:airline#extensions#tagbar#enabled = 0
" Bufferline
" https://github.com/bling/vim-bufferline
let g:bufferline_echo = 0
autocmd VimEnter *
\ let &statusline='%{bufferline#refresh_status()}'
\ .bufferline#get_status_string()
let g:bufferline_rotate = 1
let g:bufferline_fixed_index = 0
let g:bufferline_solo_highlight = 0
" Tagbar
" https://github.com/majutsushi/tagbar
nmap <F8> :TagbarToggle<CR>
let g:tagbar_autoclose = 1
let g:tagbat_autofocus = 1
let g:tagbar_compact = 1
let g:tagbar_autoshowtag = 1
" Speed up tagbar updating
" https://github.com/majutsushi/tagbar/issues/413
set updatetime=500
" vim-easytags
" https://peterodding.com/code/vim/easytags/
let g:easytags_async = 1
set tags=./tags; " this `;` means recurses upwards
set cpoptions+=d
let g:easytags_dynamic_files = 2
let g:easytags_always_enabled = 1
let g:easytags_auto_highlight = 0
let g:easytags_include_members = 1
let g:easytags_resolve_links = 1
augroup vimrc
" Auto rebuild C/C++ project when source file is updated, asynchronously
autocmd BufWritePost *.c,*.cpp,*.h
\ let dir=expand('<amatch>:p:h')
\ | if filereadable(dir.'/Makefile') || filereadable(dir.'/makefile')
\ | execute 'AsyncRun -cwd=<root> make'
\ | endif
" Auto toggle the quickfix window
autocmd User AsyncRunStop
\ if g:asyncrun_status=='failure'
\ | execute('call asyncrun#quickfix_toggle(8, 1)')
\ | else
\ | execute('call asyncrun#quickfix_toggle(8, 0)')
\ | endif
augroup END
let g:airline_section_warning = airline#section#create_right(['%{g:asyncrun_status}'])
Problem description
Suppose I'm editing a single file in buffer 1. When I open a new file with
:CtrlP
, instead of opening it in buffer 2, ctrlp opens buffer 3. If I try to open another file with:CtrlP
now, buffer 4 would be opened.That is to say, buffer 2 is skipped for some reason.
Here is the output of
:buffers
:However, buffer 2 is created as expected when I manually open files with
:edit
, so I think it might be a bug of ctrlp. Also, if I startvim
without specifying any file, buffer 1, 3, 4, 5, ... would be created sequentially.After some research, I think the function
s:PrtExit()
is very fishy. I guess it's used to disable autocommands which would close the buffers, since if I comment out these lines, buffer 3, 4, 5, ... would be created sequentially, skipping both buffer 1 and 2:Did you miss anything there?
Version information
dotfile