I want to configure vim to open a file at the same place I left off at.
I want to configure vim to open a file at the same place I left off at.
From Ubuntu's /etc/vim/vimrc file, this example is commented out:
" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal! g'\"" | endif
endif
If this doesn't work, a common problem is not having ownership of your ~/.viminfo file. If this is the case, then run:
sudo chown user:group ~/.viminfo
where user is your username and group is often the same as your username.
If you don't mind trading automation for simplicity, just press the keystroke '" (apostrophe, followed by double quotes) on opening a file, you'll jump to where you were. This is essentially what @marcog's answer is doing.
:h views-sessions
You can place this in your .vimrc:
autocmd BufWinLeave *.* mkview
autocmd BufWinEnter *.* silent loadview
the views will be placed in .vim/view. You probably need to create these directories.
You can start vim without specifying a file name using
vim
Next press CTRL+O twice to move to the last location in any file you worked on.