Note: Vim is a text editor popular among the developers. This channel is about specific idea related to Vim. If you are not already familiar with Vim, this channel is not targeted at you, only the hypothetical product of it is.Concept
Hello, fellow vimmers! I want to create a community dedicated to findings ways to make discovering Vim easier. I have an idea that could transform the way we do this, but it relies on the community. Here's a sketch.
It started when I accidentally discovered the logging feature of Vim
:h ch_logfile
. Looking at the information logged, I found that it contains "raw key presses" which sent my mind on a race. The ability to analyze individual usage patterns of Vim can allow for automatic suggestions for improvement (a la Clippy). You could also perform ad hoc analysis of your usage when deciding on a keys to choose for a mapping, for example.
Minimally Practical Implementation
Here's a minimally practical implementation for this idea. First, you need to enable logging. The most difficult problem before I knew about
:h ch_logfile
was separating Normal Mode key presses from Insert Mode ones. With these autocommands it is easily solved:
augroup VimSensei
autocmd!
" Log to analyze user behaviour
autocmd VimEnter * call ch_logfile($HOME . "/.vim/log-" . getpid())
autocmd InsertEnter * call ch_log("::Entering Insert Mode::")
autocmd InsertLeave * call ch_log("::Leaving Insert Mode::")
autocmd CmdwinEnter * call ch_log("::Entering command-line window::")
autocmd CmdwinLeave * call ch_log("::Leaving command-line window::")
autocmd CmdlineEnter * call ch_log("::Entering command-line mode::")
autocmd CmdlineLeave * call ch_log("::Leaving command-line mode::")
augroup END
You can drop this snippet into your .vimrc and start collecting the statistics. To cleanup the logs from irrelevant information use this vim script
" Questionable. I think command-line window's usage is very specific and
" doesn't usually involve a lot of editing, but it could include some Normal
" Mode commands usage patterns.
g/\d\+\.\d\+\s\+:\s\+::Entering command-line window::/.,/\d\+\.\d\+\s\+:\s\+::Leaving command-line window::/ d
g/\d\+\.\d\+\s\+:\s\+::Entering command-line mode::/.,/\d\+\.\d\+\s\+:\s\+::Leaving command-line mode::/ d
g/\d\+\.\d\+\s\+:\s\+::Entering Insert Mode::/.,/\d\+\.\d\+\s\+:\s\+::Leaving Insert Mode::/ d
" Leave only key presses
v/raw key input/d
" Remove strange terminal sequences inputs
g/".\{10,}/d
You can perform the cleanup from the command line like this
vim log-* -c 'silent argdo silent source /path/to/process-vim-log.vim' -c 'wqa'
And now you can interactively analyze your usage patters. Use this command to save a special pattern into the
a
register.
" Save a delimiter for searching consecutive keys
let @a = '"\n\s\+\d\+\.\d\+ : raw key input: "'
Now, let's try to find usages of
ddp
- a common Vim "sentence" used to swap the line under cursor with the one below. Start a search with a
/
and input the first key
d
, now press CTRL-R+a to paste in the pattern that matches everything separating consecutive key strokes. Now you can press a second key -
d
again. Input a separator. And finish the search query with
p
. This search will yield every usage of
ddp
in your log. You then can, for example, count the number of usages with
:%s///n
Future
The code above is basically un-tested, it
does contain bugs, but it works as a proof of concept. The future I envision for this concept is bright. The community around a stable implementation will share "advices", which will calculate some statistics based on the log and produce suggestions on how to improve the workflow if certain patterns are found. Users then can install a bunch of those and receive suggestions as they work.
- Did you just press
j
100 times? How about using these motions instead: ...? - You seem to be using
*N
a lot.. You could map *
to *``
instead! - Here are your top 10 3-key combos for this week!
Thoughts?
I made this post to gather thoughts of all the people interested in this idea. What future for Vim discoverability do you see?