Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I just moved from RH/Fedora to Ubuntu 12.04. In RedHat, when I reopen a file with VIM, it opens with the cursor on the line it was on when I closed the file. However, what I am seeing now is that when I reopen a file, the cursor is always at the top, every time. As some of the files I am working with are 20k lines long, this gets a bit old quickly.

I installed the full version of VIM via apt-get on my new Ubuntu so that I could use the arrow keys in insert mode. The version that is printed out is VIM - Vi IMproved 7.3.

Any help at all would be gratefully welcomed.

share|improve this question

marked as duplicate by karel, Warren Hill, Jorge Castro, Eric Carvalho, Avinash Raj Apr 15 '14 at 14:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

If you want to open more file with the lines these files was opened earlier use :mksession . For further details see the help of :mksession and Managing Sessions – Arpad Horvath Oct 19 '12 at 8:19
up vote 16 down vote accepted

Add the following lines to your ~/.vimrc or global /etc/vim/vimrc

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

I have no idea why this works, though.

share|improve this answer

This is a default configuration in /etc/vim/vimrc as mentioned vim is not remembering last position

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

This is an auto command that looks for line numbers of the evaluated expressions. The g command jumps to the last position if it was recorded. Using :help commands for BufReadPost, line() and g` will explain the details of how this works.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.