Sunday, April 17, 2005

Have Vim remeber last cursor position

to have vim remeber the last cursor position of file edit, put in .vimrc:

set viminfo='10,\"100,:20,%,n~/.viminfo
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif

2 comments:

Anonymous said...

works like a dream. thank you !

Anonymous said...

In case other people stumble along this, here's the proper way to enable "last-position-jump" (as documented in the help):

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

No setting of 'viminfo' needed (and with unrelated, unnecessary options). No moving the cursor to the end of the first line when '" is past the end of the file.