I would like to find out what are the most common patterns I'm using during coding. So I'm looking for a way to record all my keyboard input while I'm in Vim, preferably with timestamps. Then I could do some analysis on the most recent used patterns/motions what time does an action take, and find out things to optimize.

Is there an idiomatic way to do this in Vim? Shall I try and write a plugin for this? What would be the performance implications of doing something like this?


  • 1
    You should start looking at the -w flag when you start vim. You can record every keystrokes with it.
    – nobe4
    Commented Sep 3, 2015 at 13:10
  • 4
    Related blog post (link). It shows you how to record your input (vim -w file.log) and provides a haskell script to parse the file into separate commands which you can then analyse. No timestamps though.
    – tokoyami
    Commented Sep 3, 2015 at 13:10
  • Thank you @Nobe4 this looks usefull and almost I was looking for. I still wonder if the time is somehow collectible. Maybe not timestamps, but time diffs between the keystrokes. This could help with finding out the speed of how things go.
    – 6D65
    Commented Sep 3, 2015 at 13:23
  • Actually that was a question for both of you. It just didn't allow me to specify to mentions in one comment.
    – 6D65
    Commented Sep 3, 2015 at 13:48
  • Here is an idea how to capture the timestamp: Use the following script and call vim like this: vim -w <(./test-io.py > log) (vim -w <(tee raw-log | ./test-io.py > log) if you want the raw output, too) (*nix only). This should write all your input with timestamps, one byte per row, in log. What I have noticed is that vim doesn't output the commands one by one but flushes them.
    – tokoyami
    Commented Sep 3, 2015 at 14:00

1 Answer 1


Vim allows logging all input when the -w command line option is passed with a file:

-w {scriptout} All the characters that you type are recorded in the file {scriptout}, until you exit Vim. This is useful if you want to create a script file to be used with "vim -s" or ":source!". If the {scriptout} file exists, characters are appended.

Now that we have access to the input we can redirect it where we want. The following way for instance (*nix systems only):

vim -w >(./timestamper.py > log)
vim -w >(tee raw-log | ./timestamper.py > log) # If we want the raw log, too

Where timestamper.py is the following short python script:

#!/usr/bin/env python

import sys
import datetime

while True:
    if (sys.stdin.closed):
        sys.stdout.write("Input closed\n")

    a = sys.stdin.read(1)
    if (not a):
    sys.stdout.write("[{}]: {}\n".format(datetime.datetime.now(), a))

The script can be replaced with any other programme that takes input if you want to do something more sophisticated.

NOTE: After some short testing I found out that vim seems to keep a buffer of the inputs that it flushes at some point and on exit. This makes the timestamps fairly unreliable.

  • Yeah. I wonder if I could raise a neovim issue for this. Maybe guys are interested in providing this feature. Or I could dive head first and try to patch it myself if permitted, though i probably won't have the time.
    – 6D65
    Commented Sep 3, 2015 at 15:31
  • @6D65 I think you can suggest to the neovim project an input debug log feature where every input from the user is shown with a timestamp. I've seen them often temporarily patching code to try and debug :terminal issues related to input so it should be an useful feature. I'm not familiar with the remote plugin API they have, but that might also have some way to get the input in real time.
    – tokoyami
    Commented Sep 4, 2015 at 6:34
  • 1
    Or don't do it in Vim - use a system keyboard logger (started/stopped from Vim) and parse that output.
    – VanLaser
    Commented Sep 4, 2015 at 11:35

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.