如何在vim中的所有缓冲区中转到最后一个编辑位置? [英] How to go to the last edit location across all buffers in vim?

查看:30
本文介绍了如何在vim中的所有缓冲区中转到最后一个编辑位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很容易转到当前缓冲区中的最后一个编辑位置.请参阅如何返回到 Vim 中最后一行之前编辑的行?更改列表是本地缓冲区,每个缓冲区都有自己的更改列表.然而,我从最近编辑的缓冲区导航到另一个缓冲区是很常见的,并且以某种方式返回到原始缓冲区中的最后一个编辑位置会很好.有没有办法回到上次插入或修改的地方?

It is easy to go to the last edit location in the current buffer. See How to go back to lines edited before the last one in Vim? The changelist is buffer local, each buffer has it's own changelist. However it is very common that I navigate away from that recently edited buffer to an other buffer, and it would be nice to somehow get back to the last edit location in the original buffer. Is there a way to go back to the place where the last insert or modify has happened?

推荐答案

你可以把以下内容放到你的 vimrc 中

You can put the following in your vimrc

autocmd InsertLeave * execute 'normal! mI'

然后按 `-I 跳回到您离开插入模式的位置.由于 I 是大写字母,因此它可以跨缓冲区工作.

and press `-I to jump back to the position where you left your Insert mode. Since I is an uppercase, it works across buffers.

附录(评论后)

阅读@Garbor Marton 的评论后,

After reading @Garbor Marton's comment,

我自己写了一个函数

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'

我喜欢使用原始的 I 寄存器专门用于插入模式更改,因此这里我使用 M 寄存器进行任何修改,包括 r,x,d,y AND 最后插入模式.

I liked using the original I register specifically for the insert mode change, so here I use a M register for any modification including r,x,d,y AND last insert mode.

这篇关于如何在vim中的所有缓冲区中转到最后一个编辑位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆