Charles Roper
Charles Roper

Reputation: 20625

Is it possible to get gVim to remember window size?

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?

Upvotes: 39

Views: 18045

Answers (6)

Aaron P
Aaron P

Reputation: 51

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>

Upvotes: 3

Jeremy Sharpe
Jeremy Sharpe

Reputation: 375

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

Upvotes: 5

thegreatvalley
thegreatvalley

Reputation: 71

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!

Upvotes: 7

Andrej Mitrović
Andrej Mitrović

Reputation: 3342

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

Upvotes: 12

kajaco
kajaco

Reputation: 2567

gvim -geom 85x55

as in, putting this in your .bashrc:

alias G='gvim -geom 85x55'

Upvotes: 3

user55400
user55400

Reputation: 4029

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.

Upvotes: 17

Related Questions