Keep the cursor column while swapping buffers in vim

Tag: vim Author: yanjie1314 Date: 2009-07-17

In vim, if you swap buffers with :bn and :bp, the cursor stays on the same line, but not on the same column. Is there a way to keep it on the same column as well ?

Best Answer

:set nostartofline

from the help: "In case of buffer changing commands the cursor is placed at the column where it was the last time the buffer was edited."

Other Answer1

Off the top of my head I don't think so. But Vim sets the mark " as the last position when exiting a buffer. So typing `" will get you back to that spot. You could try creating an auto-command to jump to that mark automatically on entering a buffer. Try something like

:au BufEnter  * :normal `"


it works! thanks! you changed my life.