Vim “show my last command” command?

前端 未结 5 1911
小鲜肉
小鲜肉 2020-12-12 18:44

Is there a command which shows what was the last command in normal mode?

Suppose I accidently hit random key and got some unexpected result. Sure I can undo it, but

5条回答
  •  难免孤独
    2020-12-12 19:33

    It is difficult to know it. You can play with the variables:

    v:operator
    v:count (and v:prevcount)
    v:register
    

    But you cannot fully get the last normal mode command issued.

    However if you want to systematically record everything you type while in Vim, you can launch vim -W ~/.vim-last-scriptout (a Windows version: vim -W "%HOMEPATH%\Vim\.last-scriptout) You can alias it in your shell on a UNIX machine. Every single key, or control-key, will be recorded into that file. Note that if you happen to use gvim or vim -g (the GUI) you might encounter this bug.

    If you want to replay this file you can use :source! (with the exclamation mark) or the -s option from the command line.

    On Windows I have set gvimportable.exe -W gvim_directory\last_scriptout as my default editor in my Commander program (FreeCommander). This way I can always remember what I have typed to do something and repeat a sequence of commands on another file. Of course I have another shortcut for opening Vim and playing the scriptout.

    Note that the file might be written only when Vim exits, so you have to lose your session to know what you've done.

提交回复
热议问题