vim: Jump to the last known cursor when file open
May 21st, 2010 mysurface Posted in gvim | Hits: 163489 | 2 Comments »
When dealing with source codes by using vim, I usually open and close the files repeatably. It will be good if vim can automatically jump me to the last known position when I reopen a file.
To have vim do so, you must have viminfo, which usually exist by default.
Add in the setting into your ~/.vimrc
if has("autocmd")
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
endif
Ok, I have no idea what how it does the magic, but I know if your vim editor have autocmd capability, it will do wonders.
P.S. For gvim users, you can edit the vimrc by accessing the menu Edit > Startup Settings from the gvim.







May 21st, 2010 at 10:04 pm
But, by this solution, it just jumps to the “line” but not the exact cursor position where you left.
May 22nd, 2010 at 10:51 am
Probably, but it is sufficient for me :)