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?

  • 2
    there does not exist one. You may be able to map the u key 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
    May 8, 2021 at 16:17
  • 4
    Possible to create one with TextChanged + undotree()
    – Mass
    May 8, 2021 at 16:24

1 Answer 1


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

augroup whatever
  autocmd TextChanged * call F()
augroup END

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

Your Answer

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

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