Code Yarns ‍👨‍💻
Tech Blog ❖ Personal Blog

How to make Vim jump to last position on reopening file

📅 2013-Jan-25 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ jump, remember, vim ⬩ 📚 Archive

It is bit frustrating when you reopen a file and Vim positions itself at the top of the file again. It would be nice if Vim remembered where you were the last time you opened this file and jumped to that position right away.

This functionality can be enabled in Vim by placing these lines in your vimrc file:

if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

This and many other such tricks can be found in /etc/vim/vimrc

Tried with: Vim 7.3 and Ubuntu 12.04.1 LTS