2

When I'm in the GUI, I like to have a large-ish vim window: 161 columns, so I can :vsplit it into two 80 column windows (with 1 extra column for the gutter.) This works perfectly fine if I do it by hand, but if I try to :vsplit in my .vimrc, I get a 40 column window and a 120 column window.

The appropriate part of my .vimrc is here:

if has("gui_running")
    " GUI is running or is about to start.
    set lines=51 columns=161
    set guioptions -=T
    set guifont=InputMono:h10
    " Split the window
    set equalalways
    vsplit
endif

Can anyone say what's going on here?

3

I guess that set columns=161 does not take effect immediately. Maybe not until Vim displays a window, which according to :h startup happens after the vimrc is read. The latter is processed in the third step of the documentation, while the windows are still not displayed in the 11th step:

  1. Open all windows When the |-o| flag was given, windows will be opened (but not displayed yet). When the |-p| flag was given, tab pages will be created (but not displayed yet).

In any case, try to delay :vsplit until VimEnter (12th and last step in the initialization process), so that you're sure that all the initializations have been performed, and a Vim window with the correct geometry is currently displayed:

au VimEnter * vsplit

Which gives:

if has('gui_running') && has('vim_starting')
    " GUI is running or is about to start.
    set lines=51 columns=161
    set guioptions -=T
    set guifont=InputMono:h10
    " Split the window
    set equalalways
    au VimEnter * vsplit
endif
| improve this answer | |
  • Putting autocommands in groups is usually better, though I guess you don’t really need it here – D. Ben Knoble Apr 28 at 22:53
1

I don't know exactly what causes this, but I would try the following workarounds if it's important to you to setup the splits on startup (it usually isn't for me—I either have a session with saved layouts, or I don't):

  1. Try wincmd = to equalize the windows after vsplitting them; or,
  2. Try execute (&columns / 2) "vsplit" to split in half

P.S. Usually, it's best to keep gui-related configuration in ~/.gvimrc or ~/.vim/gvimrc.

| improve this answer | |
  • My .vimrc is in need of a bit of cleanup and refactoring, for sure. – Sean McMillan Apr 29 at 13:08

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.