1

I want to run an autocommand to restore cursor position after undoing with u. After reading the documentation for event, I cannot find a event that is specified for undoing. Which event should I be using?

3
  • 2
    there does not exist one. You may be able to map the u key Commented May 8, 2021 at 16:17
  • There's no autocmd for undo. The way you would usually hook into the "undo" operation is by creating a mapping for the u key, so that it will trigger whatever code you'd like to run around that operation.
    – filbranden
    Commented May 8, 2021 at 16:17
  • 4
    Possible to create one with TextChanged + undotree()
    – Mass
    Commented May 8, 2021 at 16:24

1 Answer 1

3

Based on @Mass's comment, you might be able to get started with

augroup whatever
  autocmd!
  autocmd TextChanged * call F()
augroup END

function F() abort
  const undotree = undotree()
  if undotree.seq_cur is# undotree.seq_last
    " no undos
    return
  endif
  " your work here…
endfunction
1
  • 1
    This is awesome. Thanks Commented May 8, 2021 at 23:23

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.