I use alias lvim='vim -c "normal '\''0"' for reopen last files in my vim. But the questions is how exit vim without close any tabs or files, When I use :wq it close tab or files.

  • 4
    I'm not sure I understand your question, are you looking for :h views-sessions to preserve your views and open files?
    – statox
    Commented Oct 2, 2018 at 14:42
  • 1
    Alternatively, :suspending vim?
    – D. Ben Knoble
    Commented Oct 2, 2018 at 16:39

1 Answer 1


This code restores the exact state you were in on a newly opened vim (no arguments). That is if you remembered to exit vim using SQ(a newly defined key sequence). It also saves the files you were working on.

You might want to add this to your .vimrc:

nmap SQ <ESC>:mksession! ~/.vim/Session.vim<CR>:wqa<CR>

function! RestoreSession()
    if argc() == 0 && filereadable($HOME . '/.vim/Session.vim')  "vim called without arguments
        execute 'source ~/.vim/Session.vim'

autocmd VimEnter * call RestoreSession()

Taken from here with a minor change https://askubuntu.com/questions/28614/gvim-configuration-does-not-work-like-it-should

I hope this is the answer you were looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.