How do I preserve my cursor position within a line when switching buffers, with :bn for example?
Vim remembers which line my cursor was on, but always moves my cursor to the beginning of the line when I switch between buffers.
I'm not sure why Vim behaves this way, but fortunately, the exact position is stored in the '" mark (cp. :help 'quote).
The following :autocmd will attempt to restore the cursor to that position, using the g` command:
:autocmd BufEnter * silent! normal! g`"
Note: You can append positioning commands like zz (which positions the current line in the center of the window) or zv (which opens any folds) after the g`.
How about
Vim cursor jumps to beginning of the line after buffer switch
TL;DR
:set nostartofline
For me g`" messes with my quickfix position.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With