How to go to the last edit location across all buffers in vim?

后端 未结 3 1309
孤街浪徒
孤街浪徒 2021-01-18 09:09

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

相关标签:
3条回答
  • 2021-01-18 09:14

    Try doing ctrl-` (or ctrl-6).

    0 讨论(0)
  • 2021-01-18 09:19

    You can put the following in your vimrc

    autocmd InsertLeave * execute 'normal! mI'
    

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


    Addendum (after the comment)

    After reading @Garbor Marton's comment,

    I wrote a function myself

    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 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.

    0 讨论(0)
  • 2021-01-18 09:33

    You could do :windo normal`.

    That said, I usually just use C-o (repeatedly).

    If I "feel" that I will likely want to return to some point, I'll just hit mA (which records a cross-file/buffer mark) so I can just do `A from anywhere (even after restarting the editor).


    Slightly off-topic, I love :Obsession (by Tim Pope) for really long-lived sessions that do a lot of cross-reference navigation.

    0 讨论(0)
提交回复
热议问题