Vim – Fixing Vim Not Remembering Last Position

12.04vivim

My Ubuntu LTS 12.04 has vim editor. If I open a file, move to a paragraph and reopen vim, then the cursor goes to beginning of the file always.

This is not the expected behavior. How the vim can remember last read position after closing a file?

I tried vi also, but the result is the same.

Best Answer

The file /etc/vim/vimrc already contains necessary feature. Just need to uncomment it:

" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

(Infact, you can refer to /usr/share/vim/vim73/vimrc_example.vim also)

Related Question