vim

Vim: get time of latest modification of buffer


Is there a way to get the last modification time of a buffer in Vim? I'm not interested in getftime(), which gets the modification time of the file (on disc).

What I'm looking for is more like b:changedtick.

When I undo and redo, I get messages like 1 change; after #39 10:45:00. Here, 10:45:00 is what I mean by "last modification time of a buffer"


Solution

  • AFAIK, at this point you can only emulate it by recording timestamp (:h localtime()) on the events TextChangedI and TextChanged.

    aug ChangedTime
      au!
      au TextChangedI,TextChanged * let b:changedtime = localtime()
    aug END
    

    Depending on your version of Vim these events or localtime() may not be available.