开发者

How to see the last few keystrokes in vim?

开发者 https://www.devze.com 2023-03-07 01:00 出处:网络
Sometimes I hit the wrong keys on my laptop\'s small keyboard, and odd navigation or editing occurs (sometimes a feature that\'s new to me).

Sometimes I hit the wrong keys on my laptop's small keyboard, and odd navigation or editing occurs (sometimes a feature that's new to me).

Although I can undo the editing (u) or navigation (control-o), I don't know what I开发者_开发知识库 did wrong, so it's difficult to avoid it in future. It's also frustrating to not know what just happened. So, I would like to be able to see my last few keystrokes.

A bit like :set showcmd, but to show the literal keystrokes, and (ideally) a short history of them.

I've only found commandline and navigation history in help/google.


To clarify: I'm not looking for commandline history, but keystroke history. e.g. did I press ) accidentally and go to the next sentence? Did I press dd and delete a line? I guess it's similar to a keystroke logger.

Commandline history (:history) only shows commands entered at the : prompt.


A bit old, but I've just found this on reddit:

You can start vim with the -w flag to write all keystrokes in a file. See :h -w

vim -w filename


To my knowledge, the closest you can get is the q command, which records your keystrokes into a register of your choice. Obviously, that has to be set up a priori as it's intended for complex repeats, although you could probably hack something to start recording on every file open. There's the matter of memory usage and that annoying "recording" prompt though.

Probably the most straightforward way would be to install keylogging software. I don't have any personal experience with these, but the security implications are probably mild if you get it from a trustworthy source or build it yourself, set it to only log to memory not a disk, only have a buffer the size of a sentence or so, or only log for vim windows.


More recently I came across a logging plugin for Vim and it reminded me of this question:

http://wolever.net/~wolever/wiki/vim-logging

It basically records everything you do for later analysis, it was intended for getting statistics about command usage but should work perfectly for finding what those magic commands you accidentally entered were.


:history will show your command history - that should help you uncover the new features that we all uncover in vim with misplaced keystrokes.


Gundo - Is probably worth a look, whilst perhaps not exactly what you are looking it will help slightly.

It lets you visualise the Vim undo tree, this means you will be able to see the last edits that happened. For example if you accidentally deleted a line or some such this will show up in the tree, however, it doesn't show you the actual keystrokes that were pushed and will not show things such as cursor movements.

0

精彩评论

暂无评论...
验证码 换一张
取 消