方永、南天紫雲

道亦有道

vim自动跳到上次离开的光标位置
2012年03月30日

vim自动跳到上次离开的光标位置

在SUSE 企业版中看到的一段,

; Only do this part when compiled with support for autocommands.
if has(autocmd)
; When editing a file, always jump to the last known cursor position.
; Don't do it when the position is invalid or when inside an event handler
; (happens when dropping a file on gvim).
autocmd BufReadPost * 
    \ if line("'\"") > 0 && line("'\"") <= line("$") | 
    \   exe "normal g`\"" | 
    \ endif 
endif