1

so my terminal window size on MAC OS is 100 columns and 30 rows.

When I open vim like this vim filename.txt I want the size to open to whatever size is specified in .vimrc (this works).

The size in my .vimrc is 200 columns and 40 rows. When I quit vim with :q I want the size of the window to go back to the terminal size (100 columns and 30 rows) but it remains 200 columns and 40 rows. Is there a way to go back to 100 coulmns and 30 rows automatically when vim closes?

2

You can use an autocmd with the event VimLeave to reset lines and columns before Vim closes. Add the following to your vimrc:

augroup term_size
    autocmd!
    autocmd VimLeave * set columns=100 lines=30
augroup END

The autocmd is executed once when Vim is about to exit and resets colums and lines.

I use a autocmd-group to prevent multiple definition of the autocmd when the vimrc is sourced multiple times (e.g. during testing Vim setup). The autocmd! clears the group before the autocmd for VimLeave is defined. See :help autocmd-groups.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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