Make vim remember last location

Asked by U N Gaitonde

I am unable to find a setting that makes vim remember the line where it was the last time a file was edited.

For example:
Action 1: Open a file 'file1' in vim. Do some editing. Note that the cursor is in line 'nnn' at end of editing session. Save a quit using either ZZ or :wq.

Action 2: After some time, open the same file 'file1' in vim.
Note that the cursor is on line 1, column 1.
Prefer to have the cursor anyone on line 'nnn'.

Any help will be appreciated!

My Ubuntu is 8.10.
Vim version info is as follows:
VIM - Vi IMproved 7.1 (2007 May 12, compiled Jul 21 2008 13:41:18)
Included patches: 1-314
Compiled by <email address hidden>

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu vim Edit question
Assignee:
No assignee Edit question
Solved by:
Dominik Stadler
Solved:
Last query:
Last reply:
Revision history for this message
Best Dominik Stadler (dominik-stadler) said :
#1

Incidentially I was looking for this myself, a quick look around lead to the following two options:

1. Edit the file /etc/vim/vimrc with:

 sudo vi /etc/vim/vimrc

and remove the quote character (") for the few lines of the block starting at line 26.

2. Take a look at the Wiki for VIM at http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session

The first one is the easier ones, the second seems to store more than just the edit position, I did not test this one, though.

There are a few other very useful options described in /etc/vim/vimrc, just remove the quote character to enable any of them.

Revision history for this message
U N Gaitonde (gaitondeun) said :
#2

Thanks, Dominik! The recommendation at 1 (edit vimrc) worked.
Will explore 2 (Wiki for VIM) later.

2009/1/12 Dominik Stadler <email address hidden>

> Your question #57047 on Ubuntu changed:
> https://answers.launchpad.net/ubuntu/+question/57047
>
> Status: Open => Answered
>
> Dominik Stadler proposed the following answer:
> Incidentially I was looking for this myself, a quick look around lead to
> the following two options:
>
> 1. Edit the file /etc/vim/vimrc with:
>
> sudo vi /etc/vim/vimrc
>
> and remove the quote character (") for the few lines of the block
> starting at line 26.
>
> 2. Take a look at the Wiki for VIM at
>
> http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session
>
> The first one is the easier ones, the second seems to store more than
> just the edit position, I did not test this one, though.
>
> There are a few other very useful options described in /etc/vim/vimrc,
> just remove the quote character to enable any of them.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/ubuntu/+question/57047/+confirm?answer_id=0
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+question/57047
>
> You received this question notification because you are a direct
> subscriber of the question.
>

Revision history for this message
U N Gaitonde (gaitondeun) said :
#3

Thanks Dominik Stadler, that solved my question.