Wikia

Vim Tips Wiki

Changes: Easier buffer switching with buffer listing

Edit

Back to page

(Insert TipProposed template)
(merged to 873, see 200910)
 
Line 1: Line 1:
{{TipProposed
+
#REDIRECT [[Cycle through buffers including hidden buffers]]
|id=0
 
|previous=0
 
|next=0
 
|created=October 21, 2009
 
|complexity=basic
 
|author=
 
|version=7.0
 
|subpage=/200910
 
|category1=
 
|category2=
 
}}
 
Switching buffers in Vim is a little painful as you don't realize how many buffers you have opened. This is mostly true while browsing a large source tree with cscope.
 
 
Put the following function in your [[vimrc]] to get a visual feedback of all your buffers while switching buffers.
 
<pre>
 
function! DoBuff()
 
execute "bnext"
 
let buf = 1
 
echon " "
 
while buf <= bufnr("$")
 
echon "["
 
if bufloaded(buf)
 
echohl WarningMsg | echon bufname(buf) | echohl None
 
else
 
echon bufname(buf)
 
endif
 
echon "] "
 
let buf = buf + 1
 
endwhile
 
endfunction
 
map <Esc>e :call DoBuff()<CR>
 
</pre>
 
 
To change the key-mapping change map to a key of your choice (I use Esc-e)
 
 
Now using Alt-e will cycle between buffers and also provide a listing of your buffers while you switch.
 
 
[[File:shot.jpg]]
 
 
==Comments==
 
Thanks for the contribution. I don't know if you are aware but we have a number of tips relating to buffers, with the most relevant being [[Easier buffer switching]]. In general, we like to keep related information in one place (or, where too complex for one tip, a small number of places). That makes the tips more useful for readers and easier to manage for editors.
 
 
I haven't had a chance to think about the tip in detail yet, but I have a couple of preliminary thoughts:
 
#What happens when you have a lot of buffers? Many people have far more than 10 buffers open at once.
 
#The tip maps <tt><Esc>e</tt> but mentions Alt-e.
 
#Images can be useful but this one is too big since I think it is only the last line that is relevant. We can think about that later.
 
Later, we will discuss how best to handle the October proposed tips [[Vim Tips Wiki:New tips/200910|here]]. [[User:JohnBeckett|JohnBeckett]] 07:06, October 21, 2009 (UTC)
 
[[Category:buffers]]
 

Latest revision as of 07:05, April 27, 2010

  1. REDIRECT Cycle through buffers including hidden buffers

Around Wikia's network

Random Wiki