I love g;, but often I find myself repeatedly doing g; until the screen changes. The reason for this is that I am often editing in two different places in the file. If I think ahead, I should set marks at the two places, but I usually forget to do this. Also, I don't know how many edits I made at the current "screen" so I can't just do ng; for some n. An alternative workflow would be to split the screen and edit in two places that way, but I just haven't gotten used to that workflow and even in that case, I think I would still find this functionality useful. Finally, I often use '' but it often doesn't do what I want since I commonly search different parts of the file and I really want to jump to the last part of the file (that's not on the current screen) where I made a change.

How can I make a command that will essentially repeat g; until the screen changes?

  • 1
    You could try C-o instead, though it navigates differently than g;
    – D. Ben Knoble
    Sep 3, 2022 at 20:49
  • C-o is indeed nice! But I think it navigates through the jumplist where I want to navigate through the changelist.
    – scottkosty
    Sep 4, 2022 at 2:39

1 Answer 1


Seems pretty straightforward

nnoremap <expr>g; DeltaChange()

func! DeltaChange() abort
  let ch = getchangelist()
  let delta = 1
  let top = line('w0')
  let bot = line('w$')
  while delta <= ch[1]
    let lnum = ch[0][ch[1] - delta].lnum
    if lnum < top || lnum > bot
      return delta..'g;'
    let delta += 1
  return ''

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.