here's a piece of my ~/.vimrc file:
autocmd VimEnter * : call ReadSession()
autocmd VimLeave * : call SaveSession()
function SaveSession()
execute 'mksession! ' . getcwd() . '/.session.vim'
endfunction
function ReadSession()
let session_file = getcwd() . "/.session.vim"
if filereadable( session_file )
execute "so " . session_file
if bufexists(1)
for l in range(1, bufnr('$'))
if bufwinnr(l) == -1
exec 'sbuffer ' . l
endif
endfor
endif
endif
endfunction
So it will reload a session even if I don't want it to
For example I call "vim 1.cpp" in a dirctory I once worked in(editing 2.cpp), then it will first show me 2.cpp
Can I modify the .vimrc so that if I pass parameters to vim, it won't read the session file? thanks!
EDITING:
I added a line
if (argc() > 0)
exec 'bfirst'
endif
but it still don't work.
Checking argc()
is indeed the way to go. You can skip the execution of ReadSession()
when parameters are passed:
autocmd VimEnter * if argc() == 0 | call ReadSession() | endif
Or put the condition into the ReadSession()
function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.