EDIT: REAL ANSWER: see https://stackoverflow.com/questions/9625028/vim-buffer-position-change-on-window-split-annoyance
TLDR: This behavior only happens on the first time a new window is created. If you close the window and do it again, the cursor in the new buffer is the same as in the old buffer. The answer on there was to do something useless that opens then closes a window, and then to do your vertical split.
Here's another .vimrc
mapping that wraps the answer from stackoverflow to do that for you:
map <C-S-O> :tabnew<CR>bwipeout<CR>:vs<CR>
So when you press ctrl-shift-o
it will open a new blank tab (:tabnew<CR>
), delete the buffer (:bwipeout<CR>
) and then do your vertical split (:vs<CR>
)
Hope this is better - works perfectly for me. Thanks for making me want to figure out something usable to work around this annoying behavior!
This happens all the time to me! I recently came up with an answer that works most of the time (better than nothing though). Put this in your .vimrc
:
map <C-S-O> mmH:vs<CR>`m<C-W>l`m<C-W>h
Everytime you press ctrl+shift+o
it should do a vertical split and put the cursor on the same line and column you had it in the original buffer before you split.
The behavior in vim
that this tries to get around is when the buffer you are editing is larger than can be currently displayed. Depending on where the cursor is in the buffer (exactly in the middle, upper-half, lower-half), once you do a :vs
(vertical split), it will scroll the new buffer down or up to where it thinks best.
The .vimrc
mapping above is doing:
map <C-S-O> map ctrl-shift-o to run this mm mark the current cursor position H move the cursor to the top of the buffer :vs<CR> do a vertical split `m move to line and column of mark <C-W>l move focus to the right to the original buffer `m move the cursor in the orig buffer back to the marked position <C-W>h move back to the new buffer on the left
Again, it works most of the time for me, not sure why it doesn't work all the time. Anyways, hope this helped some