Removing a buffer from a vim session

Am I not deleting buffers correctly before saving a session? He seems to be peeking at every buffer that I opened. I use gvim with the standard commands :tabe and :tabnew .

  • Gvim clean start
  • I open several tabs with :tabe , do some work
  • :mksession! ~/session :mksession! ~/session to save session state
  • No buffer needed # 14 :14bd
  • :ls verified # 14 deleted
  • :mksession! ~/session :mksession! ~/session to save the session again
  • Ready to work during the day :qa
  • Download gvim the next day :so ~/session
  • Buffer 14 still exists !!
  • ???
  • NO PROFIT
+8
windows vim
source share
3 answers

Buffer numbers are not saved when saving / restoring sessions. Thus, if you have 15 open buffers and delete them, you will have 14 buffers. When the session is restored, these 14 buffers will be given numbers from 2 to 15, regardless of what numbers they had before (number 1 was taken by an unnamed buffer when starting vim, it will be closed by the session file). So, make sure that buffer # 14 created in the session file has the same file name as old buffer # 14.

Update: I checked the session file and found that the args command could cause problems. Is it correct that buffer # 14 was opened from the shell? Try creating the following command and using it instead of bd :

 command -nargs=? -bang BW :silent! argd % | bw<bang><args> 
+7
source share

You do it right - I do just that almost every day, and it works great for me. If you block the buffer with bd and keep the session, it should remain unregistered during recovery.

To find out what goes wrong, I recommend opening a session file and looking for "badd" (for example :g/badd to get a popup list). These badd are commands that load buffers back into the list of buffers with the correct index.

Also, I would probably save the second session under a different name and make vimdiff between the two files, just to make sure nothing happens.

Session files are pretty easy to read, and if you're stuck, you can always :h for a specific command.

+4
source share

Good: it annoyed me too. I have a team (Arch Linux: Krusader file manager)

 vim --remote 

which allows me to right-click a file in Krusader and open that file in Vim. I also save Vim sessions through 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, the files that I open externally through "vim -remote", for example,

 /mnt/Vancouver/Programming/scripts/chunk.sh 

persistently persist between sessions, even after doing the usual: BD,: bw, bw: bw! commands and / or deleting a vim session file.

Looking at the vim_session.vim file, I noticed the line "argadd" with an abusive, persistent file:

 argadd /mnt/Vancouver/Programming/scripts/chunk.sh 

So,

 :help arglist :argd /mnt/Vancouver/Programming/scripts/chunk.sh 

removes this argument.

Finally, after deleting this file from the buffer list (: bd) and restarting Vim, the previous session will be restored, minus this file.


Edit: if you don't want to enter long paths when executing the ": argd" command, and you don't need anything that is specified in ": arg", just do

 :argd* 
0
source share

All Articles