Vim从最后一次关闭的光标开始

Her*_*son 4 vim position cursor

当我上次退出给定文件时,如何使Vim始终从我所处的线开始?

Mar*_*ani 6

把它放在.vimrc中:

" When editing a file, always jump to the last cursor position
 au BufReadPost *
       \ if ! exists("g:leave_my_cursor_position_alone") |
       \     if line("'\"") > 0 && line ("'\"") <= line("$") |
       \         exe "normal g'\"" |
       \     endif |
       \ endif
Run Code Online (Sandbox Code Playgroud)

然后您可以:let g:leave_my_cursor_position_alone=1在运行时使用此功能来停用该功能.

  • @Hermann Ingjaldsson这段代码来自eval.txt vim帮助文件,参见`:h last-position-jump`.(除了`g:leave_my_cursor_position_alone`变量). (3认同)