[英]only auto-reload session when I start vim with no parameter
here's a piece of my ~/.vimrc file: 这是我的〜/ .vimrc文件的一部分:
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 例如,我在曾经工作过的目录中称“ vim 1.cpp”(编辑2.cpp),然后它将首先显示2.cpp
Can I modify the .vimrc so that if I pass parameters to vim, it won't read the session file? 我可以修改.vimrc以便如果我将参数传递给vim时,它将不会读取会话文件吗? 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. 检查
argc()
确实是一种方法。 You can skip the execution of ReadSession()
when parameters are passed: 传递参数时,可以跳过
ReadSession()
的执行:
autocmd VimEnter * if argc() == 0 | call ReadSession() | endif
Or put the condition into the ReadSession()
function. 或将条件放入
ReadSession()
函数中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.