Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make Vim take you back where you were when you last edited a file? [duplicate]

Tags:

vim

editor

Possible Duplicate:
In vim, how do I get a file to open at the same line number I closed it at last time?

How do you make Vim take you back where you were when you last edited a file?

My work computer has this feature, but not my home computer! How do you set Vim to remember in which part of a file you were when you last edited it?

EDIT: just to be more precise, I want this behavior when opening a new file, or on startup.

like image 560
static_rtti Avatar asked Nov 05 '09 18:11

static_rtti


4 Answers

I have this in my .vimrc and it works:

" go to the position I was when last editing the file
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\"" | endif
like image 77
the_karel Avatar answered Nov 15 '22 10:11

the_karel


This is done with the viminfo file. It should be sufficient simply to enable this feature (and ensure that the file is writable). I use:

set viminfo='25,\"50,n~/.viminfo

...which stores viminfo data into ~/.viminfo. You can read about the other customization options here.

like image 31
Ether Avatar answered Nov 15 '22 10:11

Ether


First, check that your .vimrc file is writable.

If that isn't sufficient, add this to your .vimrc:

if has("autocmd")
    autocmd BufReadPost *
    \ if line("\'") > 0 && line("\'") <= line("$") |
        \ exe "normal g`" |
    \ endif
endif
like image 21
TinaMarie Avatar answered Nov 15 '22 08:11

TinaMarie


'0 // (single quote followed by zero) take you to place you last edited

like image 22
JT. Avatar answered Nov 15 '22 09:11

JT.