Currently my vimrc has the following:
" Uncomment the following to have Vim jump to the last position when " reopening a file au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
This jumps to the last position when reopening a file, which is good. However, this position occasionally starts at the bottom of the screen. I often find myself using
zz immediately after to center the line in the window. How can I make this centering always happen automatically?
Based on Maxim Kim's answer, I tried the following:
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | exe "normal! zz" | endif. This works inconsistently. Sometimes the last-visited line is placed in the center, whereas other times it is placed at the bottom. It seems to be essentially random - I can't reproduce the behavior consistently. Note that this works more often than
exe "normal! g'\"zz" did.