2

I have line to split window at start:

au VimEnter * vsplit

But sometimes it's annoying because I'm opening vim in small terminal, in this case I'd like to not split my window. I've tried this construction but it's not executing at start

if winwidth('%') >= 100
  au VimEnter * vsplit
endif

Is there a way to execute spit window depending on window size?

2 Answers 2

7

Try moving the if into the autocommand:

au VimEnter * if winwidth('%') >= 100 | vsplit | endif
7

You need to check the 'winwidth' result at the time the hook is run, not when it's defined. You can do this by putting it in a new function and calling that from the hook:

function Widevsplit()
  if winwidth('%') >= 100
    vsplit
  endif
endfunction

au VimEnter * call Widevsplit()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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