1

enter image description here

I spent a bit of time getting my vim the way it looks like in the attached picture. My question, is there a way to get this settings as default when I open my vim? A explorer at the upper left corner, a terminal at the bottom left corner, and the editor at the right. Should I edit anything such as the .vimrc file?

1 Answer 1

0

Run :mksession ~/.vim/session.vim to save the current session in a vimscript file.
If you get this error message:

E189: "~/.vim/session.vim" exists (add ! to override)

Append a bang to :mksession:

:mksession! ~/.vim/session.vim
          ^

You can control what Vim will write in it with the 'sessionoptions' option. The latter is a comma separated list of items.

FWIW, here is how I set the option:

set sessionoptions=help,tabpages,winsize

In particular, I don't include the items options and localoptions, because when I source back a session, I want to start with sane option values/mappings, no matter what experiments I was performing when running :mksession. For the same reason, I only include the minimum of items I need (i.e. help, tabpages, winsize); you may need more or less.


Now that you have a session file, you can close everything with:

:sil! tabonly | sil! only | enew
      │              │      │
      │              │      └ load a new unnamed buffer
      │              └ close all windows except the current one
      └ close all tab pages except the current one

And you can get your session back by running:

:so ~/.vim/session.vim

When starting Vim from the shell, you can get your session back with the -S argument:

$ vim -S ~/.vim/session.vim
      ^^

You can automate the sourcing of the session file like this:

augroup my_session
    au!
    au VimEnter * ++nested call s:load_session_on_vimenter()
augroup END

fu s:load_session_on_vimenter() abort
    let file = $HOME.'/.vim/session.vim'
    if filereadable(file)
    \ && ! argc()
    \ && &errorfile is# 'errors.err'
        so ~/.vim/session.vim
    endif
endfu

For more information, see:

:h 'ssop
:h :mksession
:h :so
:h -S

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .