tags:

views:

416

answers:

3

I want to configure vim to open a file at the same place I left off at.

+9  A: 

From ubuntu's /etc/vim/vimrc file, this example is commented out:

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

If this doesn't work, a common problem is not havng ownership of your ~/.viminfo file. If this is the case, then run:

sudo chown user:group ~/.viminfo

where user is your username and group is often the same as your username.

marcog
The autocmd comes straight out of the vim doc. See :help last-position-jump
+2  A: 
  :h views-sessions

You can place this in your .vimrc :

  au BufWinLeave * mkview
  au BufWinEnter * silent loadview

the views will be placed in $HOME/.vim/view. You probably need to create these directories.

Oli
A: 

If you don't mind trading automation for simplicity, just press the keystroke '" (apostrophe, followed by double quotes) on opening a file, you'll jump to where you were. This is essentially what @marcog's answer is doing.

sykora