I like to open Vim with many buffers open, and switch between them using plugins. Because I work a lot in C++, I like to have a way to quickly switch between header files and their corresponding source files and vice-versa. With some work, I have created these two bindings which essentially do the same thing: find a buffer with the same name as the currently opened buffer, but with a .c*
extension if my current buffer is a header file, and with a .h*
extension if my current buffer is a source.
My puzzlement derives from the fact that the binding that opens the other file using a split generally executes instantly, while the one that replaces the current buffer takes a second or so before it terminates. However, running the :buffer
command manually is instant. Why does this happen?
This question seems similar to this one, but as far as I can see my bindings don't really shadow any control codes.
Here are the two bindings (the top one opens a split, the second one replaces):
nmap <silent><leader>v :execute 'vert sbuffer' '\<'.expand("%:t:s,\\v\\.h(..)?$,.X123X,:s,\\v\\.c(..)?$,.h,:s,.X123X$,.c,")<CR>
nmap <silent><leader>c :execute 'buffer' '\<'.expand("%:t:s,\\v\\.h(..)?$,.X123X,:s,\\v\\.c(..)?$,.h,:s,.X123X$,.c,")<CR>
nmap <leader>c
command on your system?<leader>cd
so I guess vim was trying to wait to see if I was going to type that one. Feel free to put that as an answer (or just the method to verify whether a map maps to more things) and I'll gladly mark it accepted. Thanks!!