问题
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