if has("autocmd")
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event
" handler (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
endif
Update:
А еще лучше использовать следующий код:
if has("autocmd")Он помимо курсора еще и фолдинги восстанавливает (спасибо за подсказку lyn4ed).
set viewoptions=cursor,folds
au BufWinLeave * mkview
au BufWinEnter * silent loadview
endif