vim: Find history of recently used shortcuts

我只是一个虾纸丫 提交于 2020-01-07 04:41:31

问题


Problem

A plugin that I am using, my mappings, or a combination of those two are causing some issues on vim. In particular, when I press a particular combination of keys the following happens:

  • the 1st number in the current line it decreases
  • it jumps to another line

The problem is that I don't know who the combination that I am pressing is. I cannot reproduce it. I am a saving-the-buffers-constantly-freak, so when I am "idling" (don't write anything on vim) my fingers involuntary maybe enter/exit edit mode, :wa, zz, maybe a few others, quite fast. I must be mixing some shortcuts here which are causing this issue. You might say "stop doing what you do" but I cannot help it. It's like a problem. Can't control that. But still, there is a shortcut somewhere that it's doing stuff that I don't want to, and I cannot reproduce it or find it in my vim configuration.

BTW I have set map <C-a> <Nop> in my .vimrc, so default behavior of auto-increment is disabled. (see a previous question of mine here)

Question

How can I see the history shortcuts that have been used? q: Doesn't give me such information.


回答1:


I don't know any way in Vim to retrieve the history of the keys having been pressed.

As an alternative, you can use your OS abilities in order to do it.

If you're on a Linux system, you can log key events quite easily; try to run in background this little bash script, it will do the job (not well tested, it may need some fixes); of course, all events will be recorded, even those which didn't occur while working with Vim:

#!/bin/bash

xinput list |
grep -Po 'id=\K\d+(?=.*slave\s*keyboard)' |
xargs -P0 -n1 xinput test |
awk '
    BEGIN { while (("xmodmap -pke" | getline) > 0) k[$2]=$4 }
    /^key press/ {
        cmd = "date +%H:%M:%S"; cmd | getline date; close(cmd)
        printf("%s [ %s ]\n", date, k[$NF])
    }
' |
tee /tmp/keys.log  # <-- pressed keys will be logged here



回答2:


You can dump your active mappings by typing:

:map


来源:https://stackoverflow.com/questions/43777178/vim-find-history-of-recently-used-shortcuts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!