views:

83

answers:

2

Is it possible to have Vim always start at whatever line i was in last time i was working in that given file? And if so, how do i do that?

+4  A: 

Put this in your .vimrc:

" When editing a file, always jump to the last cursor position
 au BufReadPost *
       \ if ! exists("g:leave_my_cursor_position_alone") |
       \     if line("'\"") > 0 && line ("'\"") <= line("$") |
       \         exe "normal g'\"" |
       \     endif |
       \ endif

then you can use :let g:leave_my_cursor_position_alone=1 at runtime to deactivate the feature.

Marco Mariani
it's very unreadable, but does just what i need.
Hermann Ingjaldsson
did you find that somewhere or did you write it yourself?
Hermann Ingjaldsson
I have a long .vimrc, with stuff sedimented over time. I suggest you have a look at some of the general questions/blog posts about .vimrc and take what you please.
Marco Mariani
@Hermann Ingjaldsson this code comes from eval.txt vim help file, see `:h last-position-jump`. (except the `g:leave_my_cursor_position_alone` variable).
ZyX
+1  A: 

put this into your .vimrc

set viewoptions=cursor,folds

au BufWinLeave * mkview

au BufWinEnter * silent loadview
Sanek