vim: preserve cursor position when switching between buffers with :bn

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`.

Tags:

Vim

Cursor

Line