1

When I open a file of a given filetype I want it to split into two windows with the cursor in the bottom window. I can get this to work when opening the file from an existing vim session. But when I open the file in vim from the command line the cursor always starts in the top window.

I made a simple file, split.vim, to demonstrate what is happening (in my real case I use autocmd FileType but this simpler case also reproduces it:

botright split

If I open vim with vim -u split.vim it splits as expected, but the cursor is in the top window.

However, if vim is already running and I do :source split.vim it does the same split, but the cursor is in the bottom window.

How can I get vim to split with the cursor in the bottom window, even when first opening vim?

I've also tried adding wincmd j after making the split, but the result is the same.

Again, my actual use case uses autocmd for a given filetype, but the above is easier to test with no vimrc. The autocmd case has the same results. If I open a file when opening vim the cursor remains in the top window. But if I open a file of the specified filetype the cursor jumps to the bottom window.

4
  • what about vim -c "botright split"?
    – Maxim Kim
    Aug 6 at 18:49
  • 2
    if I add to my vimrc au VimEnter * botright split then when I start vim I get 2 split wins and cursor is on the bottom one.
    – Maxim Kim
    Aug 6 at 18:54
  • I'm actually doing this for a specific filetype, whether opened from the command line, or in an existing session (edited to call that out earlier). Though maybe I could set a flag that au VimEnter checks before doing the split...
    – Rob Mosher
    Aug 6 at 19:58
  • 2
    Most autocommands allow you to specify the (extension of the) file type to which they apply so ... autocmd VimEnter *.py botright split ... for python files, for example.
    – B Layer
    Aug 6 at 20:28
0

With help from the commenters I came up with the following solution.

au FileType tsv botright split   " split in any case a .tsv is opened
au VimEnter *.tsv wincmd j       " workaround to move window if opened from cli

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.