Recently, I have tuned my .vimrc lot and loved the power and convenience that gives me :mksession . I currently have .vimrc for startup sessions:
function! LoadSession() if argc() == 0 && ! &diff let g:sessiondir = $HOME . "/.vim/sessions" . getcwd() let g:sessionfile = g:sessiondir . "/session.vim" if (filereadable(g:sessionfile)) exe 'source ' g:sessionfile else echo "No session loaded." + argc() + argv() endif else let g:sessionfile = "" let g:sessiondir = "" call ResCur() endif endfunction
Then I call this with au VimEnter * nested :call LoadSession() . This works great for most cases, except when vim reads with stdin . In this case, the session is still loaded, however I want this to not happen. I would have thought that the conditions argc() == 0 would be enough, but it seems that - , called by vim with a read from stdin , calls argc() so as not to return 0. Poop !;]
I tried all kinds of views from argv(0) (it is empty in this case - why?), Trying to find ways to determine what vim is reading from stdin (it shows a message saying that it does so, but I can not understand how to use it) etc., but so far no luck.
I'm sure I missed something terribly obvious here, but Googles and vim :help won't take me anywhere, so I hope some kind-hearted soul can shed some light on this for me.
source share