开发者

Deleting buffer from vim session

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.

  1. Clean start of gvim
  2. I open a number of tabs with :tabe, do开发者_JAVA技巧 some work
  3. :mksession! ~/session to save my session state
  4. Don't need buffer #14, :14bd
  5. :ls confirms #14 was deleted
  6. :mksession! ~/session to save session again
  7. Done work for the day, :qa
  8. Load up gvim the next day, :so ~/session
  9. Buffer 14 still exists!!
  10. ???
  11. 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*                                                                                     
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜