Sometimes I'll be using VIM and something will happen, and I don't know what it was or what I typed that caused it. Is there a way to list some of the recent keys that were typed, and, even better, find out what actions they triggered?
3 Answers
Vim
has an option -W
you could abuse, but it won't work while Vim
is still running.
-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.
-W {scriptout}
Like -w, but an existing file is overwritten.
Calling Vim
with e.g. an alias
vim -W /tmp/vimlog-$(id -un)
will let you inspect with less /tmp/vimlog-$(id -un)
or cat -v /tmp/vimlog-$(id -un)
what you literally typed after you quit Vim
.
-
This is an interesting idea. I will give this a shot and see if I learn anything.– OwenCommented May 3, 2011 at 22:53
First make sure that vim is remembering any lines of history at all. This sets the history to 1000 commands and searches:
:set history=1000
If you type the start of what you are looking for you can use the ↑ ↓ keys to scroll through the history - this applies to commands and searches.
For example, if you had searched for china then cuba then Chad then cyprus:
You could type /c
and press ↑ several times. You will find it displays /cyprus
then /cuba
then /china
(/Chad
is skipped because it doesn't start with a c).
Other commands:
:history
lists the entire history.:his
lists the command history.:his /
lists the search history.
-
2I don't think this applies to normal mode commands only to ex mode commands (that is commands that start with ':', example :e :w :q)– kmkkmkCommented May 3, 2011 at 13:52
-
1To see the ex commands history, you can also simply type
q:
in normal mode. same goes for search history withq/
– YabCommented May 3, 2011 at 16:08
You could add this to your .vimrc :
set showcmd
It will show in the status bar the command you are making as you type them. While this won't give you an history, this is the closest solution I know of.
If however you are talking about ex
commands, Gareth's awnser is the way to go