Vim Tips Wiki
(Move categories to tip template)
(Change <tt> to <code>, perhaps also minor tweak.)
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
 
|id=552
 
|id=552
 
|previous=551
 
|previous=551
|next=553
+
|next=554
|created=September 9, 2003
+
|created=2003
 
|complexity=basic
 
|complexity=basic
 
|author=Mark Stosberg
 
|author=Mark Stosberg
Line 34: Line 34:
   
 
==Comments==
 
==Comments==
Use <tt>%bdelete</tt> instead of <tt>1,999bdelete</tt>.
+
Use <code>%bdelete</code> instead of <code>1,999bdelete</code>.
   
 
----
 
----
 
That won't always work.
 
That won't always work.
   
<tt>%bdelete</tt> only deletes as many buffers as there are lines in the current buffer.
+
<code>%bdelete</code> only deletes as many buffers as there are lines in the current buffer.
   
 
----
 
----

Latest revision as of 05:35, 13 July 2012

Tip 552 Printable Monobook Previous Next

created 2003 · complexity basic · author Mark Stosberg · version 5.7


I use Vim's session file feature a lot to switch between projects. Preserving all that context is nice. Usually my process goes like this:

1. Save the current session:

:mks! ~/v/project1.vim

2. Quit vim

:xa

3. Restart with a different session file:

vim -S ~/v/project2.vim

I was exiting and re-opening vim because if I just loaded the second project file, a list of both project buffers would appear in my buffer list. That was not what I wanted -- I wanted to replace the first buffer list completely wtih the second.

There is a simple way to do this. At the top of a session file, add this:

1,999bdelete

That will delete the first 999 existing buffers, effectively allowing any new buffer definitions in the rest of the session file to replace what is currently there. Now you can switch directly to a new session without exiting. Just use:

:so ~/v/project2.vim

Comments[]

Use %bdelete instead of 1,999bdelete.


That won't always work.

%bdelete only deletes as many buffers as there are lines in the current buffer.


How about this:

:execute "1," . bufnr("$") . "bdelete"

That should delete all the buffers. When I say delete, it will only unlist them. The check this execute the above command then run this command.

:ls!