Quickly switching buffers in Vim normal mode

{count}CTRL-^ switches to the count numbered buffer.


The way I usually switch between buffers is to use the :buffer command with the built-in autocompletion, e.g. :b prof<Tab> to switch to folder/path/LoginProfileFactory.php.

You can just start typing any part of the file name of the buffer you need, which is nice.

Less often, I actually remember the numbers of the buffers I want and I use something like :b 3 or :3b. I see you mention you don't like :buf 3 though, so Rumple Stiltskin has an alternative to the :3b style that you may prefer.


I have the following lines in .vimrc:

nnoremap  <silent>   <tab>  :if &modifiable && !&readonly && &modified <CR> :write<CR> :endif<CR>:bnext<CR>
nnoremap  <silent> <s-tab>  :if &modifiable && !&readonly && &modified <CR> :write<CR> :endif<CR>:bprevious<CR>

Now a Tab let you go to the next buffer and a Shift-Tab to the previous.


Add this to your .vimrc

map gn :bn<cr>
map gp :bp<cr>
map gd :bd<cr>  

Note that you are remapping gp and gd, but maybe you don't care about that (:help gp, :help gd).

For more information on how to map key strokes see :help map-overview and :help map.txt.

Btw, I personally use <leader> instead of g in the mapping. My <leader> is set to ;. This puts my <leader> key on the home row which makes me willing to map all kinds of stuff using <leader>. :help mapleader if you want to change your <leader> key.

Tags:

Vim