Last Updated: February 25, 2016
·
731
· ajh17

Returning to the last cursor position in Vim

Add this to your ~/.vimrc:

augroup line_return  " Return vim to the last known position
    au!
    au BufreadPost *
                \ if line("'\"") > 0 && line("'\"") <= line("$") |
                \   execute "normal! g'\"" |
                \ endif
augroup END

This snippet will return you to the last known cursor position when opening a file in vim. Very handy!

1 Response
Add your response

If you want to do this manually when you are already in a file, use gi. Very handy when 'scrolling' through a file and you last positions went off screen.

over 1 year ago ·