可以轻松转到当前缓冲区中的最后一个编辑位置.请参阅如何返回Vim中最后一行之前编辑的行? changelist是缓冲本地的,每个缓冲区都有自己的更改列表.然而,我从最近编辑的缓冲区导航到另一个缓冲区是很常见的,以某种方式回到原始缓冲区中的最后一个编辑位置会很好.有没有办法回到最后一次插入或修改发生的地方?
您可以将以下内容放入 vimrc 中
autocmd InsertLeave * execute 'normal! mI'
Run Code Online (Sandbox Code Playgroud)
并按`-I跳回您离开插入模式的位置。由于I是大写,因此它可以跨缓冲区工作。
附录(评论后)
阅读@Garbor Marton 的评论后,
我自己写了一个函数
let g:detect_mod_reg_state = -1
function! DetectRegChangeAndUpdateMark()
let current_small_register = getreg('"-')
let current_mod_register = getreg('""')
if g:detect_mod_reg_state != current_small_register ||
\ g:detect_mod_reg_state != current_mod_register
normal! mM
let g:detect_mod_reg_state = current_small_register
endif
endfunction
" Mark I at the position where the last Insert mode occured across the buffer
autocmd InsertLeave * execute 'normal! mI'
" Mark M at the position when any modification happened in the Normal or Insert mode
autocmd CursorMoved * call DetectRegChangeAndUpdateMark()
autocmd InsertLeave * execute 'normal! mM'
Run Code Online (Sandbox Code Playgroud)
我喜欢使用原始I寄存器专门用于插入模式更改,因此在这里我使用M寄存器进行任何修改,包括r,x,d,yAND 最后插入模式。