Am I not deleting buffers properly before saving my session? It seems to glom onto every buffer I've had opened. I use gvim with the standard :tabe
and :tabnew
commands.
- Clean start of gvim
- I open a number of tabs with
:tabe
, do开发者_JAVA技巧 some work :mksession! ~/session
to save my session state- Don't need buffer #14,
:14bd
:ls
confirms #14 was deleted:mksession! ~/session
to save session again- Done work for the day,
:qa
- Load up gvim the next day,
:so ~/session
- Buffer 14 still exists!!
- ???
- NO PROFIT
Buffer numbers are not preserved when saving/restoring sessions. Thus, if you have 15 opened buffers and delete one, you will have 14 buffers. When session restores, these 14 buffers will be given numbers from 2 to 15 no matter what numbers they had earlier (number 1 was taken by unnamed buffer on vim startup, it will be closed by session file). So, check whether #14 buffer created by session file has the same filename that old #14 buffer.
Update: I checked out session file and found that args
command is likely to be causing the trouble. Am I right that buffer #14 was opened from shell? Try to create the following command and use it instead of bd
:
command -nargs=? -bang BW :silent! argd % | bw<bang><args>
You are doing this properly - I do exactly this almost every day and it works fine for me. If you're unlisting the buffer using bd and saving the session, it should remain unlisted when you restore.
To find out what's going wrong, I'd recommend opening up the session file and searching for 'badd' (e.g. :g/badd
to get a popup list). These badd's are the commands that load the buffers back into the buffer list with the right index.
Also, I'd probably save the second session under a different name and do a vimdiff between the two files, just to make sure nothing is going wrong.
The session files are quite easy to read, and you if you get stuck you can always :h
for a particular command.
Ok: this was annoying me, too. I have a command (Arch Linux: Krusader file manager)
vim --remote
that enables me to right-click a file in Krusader and open that file in Vim. I also save Vim sessions via my ~/.vimrc:
" Save session on quitting Vim:
autocmd! VimLeave * mksession! ~/.vim/vim_session.vim
" mksession! overwrites old session
" Restore session on starting Vim:
autocmd! VimEnter * source ~/.vim/vim_session.vim
However, files that I open externally via 'vim --remote', e.g.
/mnt/Vancouver/Programming/scripts/chunk.sh
stubbornly persist between sessions, even after doing the usual :bd, :bw, :bw! etc. commands, and/or deleting the vim session file.
Looking at the vim_session.vim file, I noted an 'argadd' line with the offending, persistent file:
argadd /mnt/Vancouver/Programming/scripts/chunk.sh
So,
:help arglist
:argd /mnt/Vancouver/Programming/scripts/chunk.sh
deletes that argument.
Finally, after clearing that file from the buffer list (:bd) and restarting Vim -- the previous session is restored, minus that file.
Edit: If you don't want to type long paths when doing the ":argd" command, and you don't need anything listed with ":arg", just do
:argd*
精彩评论