How to make Vim jump to last position on reopening file

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

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

Tried with: Vim 7.3 and Ubuntu 12.04.1 LTS

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.