Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

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.

share|improve this answer
    
This is an interesting idea. I will give this a shot and see if I learn anything. –  Owen May 3 '11 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.
share|improve this answer
2  
I don't think this applies to normal mode commands only to ex mode commands (that is commands that start with ':', example :e :w :q) –  kmkkmk May 3 '11 at 13:52
    
To see the ex commands history, you can also simply type q: in normal mode. same goes for search history with q/ –  Yab May 3 '11 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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.