I know how to set the initial window size in gVim, but how do I get it to automatically restore the window dimensions from last session? Is this even possible?
6 Answers
Edit: Corrected my answer. The mentioned winsize sessionoption only refers to the vim internal window layout, not the external dimensions.
If you use
:mksession
and load the session on vim startup with
gvim -S Session.vim
you can include the window position and size into the session by including winpos and resize in the sessionoptions, see
:help 'sessionoptions
With autocommands you could even automate the saving and restoring of the session on Vim entry and exit.

- 3,929
- 1
- 21
- 13
-
1Thanks for the answer! I'm still quite new to Vim, so I'm not terribly experienced with autocommands. How would I get them to fire on entry and exit? – Charles Roper Feb 27 '09 at 14:38
-
See :help autocommand, especially the GUIEnter, VIMEnter, VIMLeave events look promising. – user55400 Feb 27 '09 at 14:42
-
1Session saving also saves last opened files and tends to ignore these, when opening single files with Vim. There's a script in Wikia, which does it in a cleaner manner (i.e. without messing around with other session elements): http://vim.wikia.com/wiki/Restore_screen_size_and_position – Andrei Sosnin Sep 09 '11 at 13:39
These lines save and restore just the position and size:
set sessionoptions+=resize,winpos
autocmd VIMEnter * :source C:/session.vim
autocmd VIMLeave * :mksession! C:/session.vim

- 7,835
- 7
- 61
- 104

- 3,322
- 3
- 20
- 33
-
4This a nice idea, but session saving also saves last opened files and tends to ignore these, when opening single files with Vim. There's a script in Wikia, which does it in a cleaner manner (i.e. without messing around with other session elements): http://vim.wikia.com/wiki/Restore_screen_size_and_position – Andrei Sosnin Sep 09 '11 at 13:37
Additionally:
In your .vimrc
:
set ssop+=resize,winpos,winsize,blank,buffers,curdir,folds,help,options,tabpages
Then, use the script from this article. It works beautifully!

- 7,835
- 7
- 61
- 104

- 71
- 1
- 2
I had the same question, and to expand on the above answer, you can simply add the following to your .vimrc
to get the behaviour you want:
set sessionoptions+=resize,winpos
see :h ssop

- 9,402
- 6
- 46
- 53

- 345
- 1
- 3
- 12
gvim -geom 85x55
as in, putting this in your .bashrc:
alias G='gvim -geom 85x55'

- 2,547
- 3
- 24
- 33
If you just want vim to open to the same size every time, you can edit your user's vimrc in C:/Users/<yourUserName>/_vimrc
(this is preferred to editing the system _vimrc in your vim installation folder)
to include the line set lines=<yourHeight> columns=<yourWidth>

- 31
- 4