VIM: Remember cursor position

Posted by jason on Jan. 27, 2012, 6:43 a.m.
Tags: centos config linux vim

For those who like how vim under CentOS remembers the previous cursor position when you open a file, here's the relevant code from /etc/vimrc. Just put it in your ~/.vimrc file:

if has("autocmd")
    augroup redhat
        "When editing a file, always jump to the last cursor position
        autocmd BufReadPost *
        \ if line("'\"") > 0 && line ("'\"") <= line("$") |
        \   exe "normal! g'\"" |
        \ endif
    augroup END