VIM sessions
By chys on March 21st, 2009This post basically provides the same info as Reference [1] does.
I’m tired of typing tabe many times every time I continue with a project that has many files.
Sure, there is no reason for an omnipotent editor* not to support sessions. Command :mksession (mks) saves the session info to a file (Session.vim by default) that can be source‘d the next time we use VIM. Tell VIM what should or should not be saved by using set sessionoptions.
I’m too lazy to type all these commands once and again, so I added the following lines to ~/.vimrc:
set sessionoptions=sesdir,folds,tabpages
com SL source Session.vim
com SX call SessionSaveAndExit()
function SessionSaveAndExit()
wa
mks!
qa
endfunction
Every time I decide to continue with working, I start VIM and type :SL. When I’m finished, I type :SX and VIM saves all my files and exits.
I dislike to define too many keyboard shortcuts since I frequently press the wrong keys and have no idea what’s just happened (fortunately we are using VIM instead of the original Vi and we can undo and redo easily), so I use com (abbr. command) instead of nmap.
* I don’t mean to offend Emacsers – Emacs is an OS rather than an editor…
References
[1] lambda.oasis: Vim Sessions
[2] VIM on-line help, of course (e.g. type :help sessionoptions in VIM)
Related posts:
Tags: VIM
