phux / vim-keypress-analyzer

vim-keypress-analyzer parses a vim keypress log file and aggregates key press counts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vim Keypress Analyzer

vim-keypress-analyzer parses vim keypress log files generated by (n)vim -w <a_log_file> and aggregates key press counts and some antipattern analysis.

Note: this is not delivering accurate numbers yet, check TODOs

Table of contents

Example output

$ vim-keypress-analyzer --file ~/.nvim_keylog --limit 10 --enable-antipatterns

Vim Keypress Analyzer

Key presses per mode (total: 104281)
│─────────────────│───────│───────────│
│ IDENTIFIER (4)  │ COUNT │ SHARE (%) │
│─────────────────│───────│───────────│
│ insert          │ 46.2K │     44.32 │
│ normal          │ 43.7K │     41.98 │
│ command         │  7.4K │      7.11 │
│ visual          │  6.8K │      6.58 │
│─────────────────│───────│───────────│

Key presses excluding [insert, command] modes (total: 50642)
│──────────────────│───────│───────────│
│ IDENTIFIER (10)  │ COUNT │ SHARE (%) │
│──────────────────│───────│───────────│
│ w                │  7.9K │     14.01 │
│ <space>          │  4.3K │      8.51 │
│ j                │  3.4K │      6.78 │
│ k                │  2.9K │      5.91 │
│ b                │  2.4K │      4.83 │
│ d                │  1.5K │      3.15 │
│ e                │  1.4K │      2.93 │
│ i                │  1.3K │      2.62 │
│ l                │  1.2K │      2.54 │
│ <esc>            │  1.2K │      2.45 │
│──────────────────│───────│───────────│

Found Antipatterns
│───────────────│───────│───────────────────│─────────────────────────│
│ PATTERN (16)  │ COUNT │ TOTAL KEY PRESSES │ AVG KEYS PER OCCURRENCE │
│───────────────│───────│───────────────────│─────────────────────────│
│ www+          │   559 │              3.6K │ 5.48                    │
│ bbb+          │   306 │              1.5K │ 4.97                    │
│ ko            │   195 │               390 │ 2.00                    │
│ jjj+          │   148 │               777 │ 5.25                    │
│ li            │   145 │               290 │ 2.00                    │
│ kkk+          │   140 │               794 │ 5.67                    │
│ eee+          │   126 │               734 │ 5.83                    │
│ jO            │    52 │               104 │ 2.00                    │
│ lll+          │    37 │               398 │ 10.76                   │
│ xxx+          │    31 │               131 │ 4.23                    │
│ hhh+          │    28 │               137 │ 4.89                    │
│ dddd+         │    23 │               102 │ 4.43                    │
│ ha            │     7 │                14 │ 2.00                    │
│ WWW+          │     2 │                12 │ 6.00                    │
│ BBB+          │     2 │                 6 │ 3.00                    │
│ XXX+          │     1 │                 6 │ 6.00                    │
│───────────────│───────│───────────────────│─────────────────────────│

Features

  • count total keys pressed by mode (NORMAL, INSERT, VISUAL, COMMAND)
  • count key presses for each key (excludable modes, e.g. don't show insert mode key presses)
  • detect repetitive key sequences as antipatterns (e.g. jjj or dddd)
    • detect repetitive multi key sequences like dwdwdwdw

Install

Binary from GitHub release

  1. Download the archive for your OS (OSX and Linux, OSX is not tested yet) from the releases page
  2. Extract the binary vim-keypress-analyzer to a directory in your $PATH

Usage

Collecting keypresses in vim/nvim

  1. start vim with the -w <path/to/logfile> flag (see :h -w) to tracking your key presses
  2. edit files/text
  3. quit vim. This will create or append the <path/to/logfile> with the keys you have pressed in the session

Helpful alias to always log your keys:

alias n='nvim -w ~/.nvim_keylog "$@"'
# or
alias v='vim -w ~/.vim_keylog "$@"'

If you want to split the logs per day, to track progress for example:

# necessary once
mkdir ~/.vim_logs

# automatically write to ~/.vim_logs/YYYY-MM-DD.log
alias n='nvim -w ~/.vim_logs/$(date -Idate).log "$@"'
# or
alias v='vim -w ~/.vim_logs/$(date -Idate).log "$@"'

Analyzing logfiles

There is only a single mandatory option: -f`--file` to the log file generated in the previous step.

$ vim-keypress-analyzer -f <a_log_file>

Optional flags

Flag Description Possible values Default
-l, --limit limit the number of key presses displayed any positive int 0 (unlimited)
-a, --enable-antipatterns boolean flag, enable a rudimentary antipattern analysis flag is present or not false
-e, --exclude-modes comma separated list of modes to be excluded from the key press list insert,normal,command,visual insert,command

Motivation

  • be able to see the ratio of typing in insert mode vs. other modes
    • if you are typing 99.9% of the time in insert mode, there is not much reason to use vim
  • count the characters you type in vim (e.g. per day)
  • identify your most pressed keys in non-insert modes, to check for example for optimization potential
  • identify antipatterns in your editing habit. Antipatterns means repetitive or inefficient key strokes. For example, pressing eight times j repetitively is considered an antipattern. Similarly, pressing A<cr> can be done as well by o

TODO

  • improve motion detection - e.g. ciw
  • command & insert mode shares seem to high - check
  • rewrite antipattern detection [WIP]
    • configurable via yaml file
  • option to store results in a structured format (json e.g.)
  • (maybe) <leader><key> detection? - the numbers are otherwise not 100% correct
  • (maybe maybe) build a vim plugin that logs keys on the fly to a structured log format

About

vim-keypress-analyzer parses a vim keypress log file and aggregates key press counts.


Languages

Language:Go 100.0%