sponsor Vim development Vim logo Vim Book Ad

basic Tip #865: Easy buffer switching

 tip karma   Rating 6/17, Viewed by 2005 

created:   February 3, 2005 9:42      complexity:   basic
author:   Anonymous      as of Vim:   5.7

Add to your .vimrc.

"buffer switching
nmap > :bn<CR>
nmap < :bp<CR>


Open few buffers and press < > (buffer previous, buffer next).


 rate this tip  Life Changing Helpful Unfulfilling 

<< Windows: make arrow keys work in visual mode | Cut/Copy(All)/Paste with Ctrl-X/C(A)/V >>

Additional Notes

Anonymous, February 4, 2005 5:30
Unfortunatelly, this disables commands >> and <<, which I often use...
Hasanali Dhorajiwala, February 4, 2005 11:18
You can use the , prefix and the shift is not needed

,, is << without shift

nmap ,, :bn<CR>  
nmap ,. :bp<CR>
Amna Makhi Fatubai, February 4, 2005 11:22
I use this in my _vimrc, whenever I do vim *.*
(more than 5 files I got into browse mode).

if argc() > 5
        :map <c-n>  :bn<CR>
        :map <c-p>  :bp<CR>
       " other keys for browse mode.
endif    
Anonymous, February 8, 2005 3:49
I do this:
map <C-W>h :bp<CR>
map <C-W>l :bn<CR>

it will break moving between left/right between vsplit windows[which I don't use].  for details on what it breaks, look here :h CTRL-W_l or :h CTRL-W_h
tim@esselens#gmail.com, February 9, 2005 2:58
I do this in xterm:

.Xdefaults:

XTerm.VT100.translations: #override \
        :Shift<Key>Right: string(0x1b) string("O2C") \n\
        :Shift<Key>Left: string(0x1b) string("O2D") \n

.vimrc

map <S-Left> :bn<CR>
map <S-Right> :bp<CR>

This way it works like in most multi-tab terminals.
scott.vim@h4ck3r.net, February 10, 2005 0:39
I do this:

map <Right> :bnext<CR>
imap <Right> <ESC>:bnext<CR>
map <Left> :bprev<CR>
imap <Left> <ESC>:bprev<CR>

Aren't you using hjkl to move anyway?
Anonymous, February 19, 2005 7:08
I use <C-Right> for :bn and <C-Left> for :bp.

Looks like everyone has their own way of doing it?
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.
    stats
Sponsored by Web Concept Group Inc. SourceForge.net Logo