Vim“显示我的最后一个命令”命令?
是否有一个命令显示正常模式下的最后一个命令是什么?
假设我不小心按了随机键并得到了一些意想不到的结果。 当然我可以撤消它,但是我可以透露按下的是哪个键以及它是如何解释的吗?
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 could I reveal what key was pressed and how it was interpreted?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
点击冒号 (
:
),然后使用向上箭头开始返回之前的命令。您也可以使用向上/向下箭头在列表中移动。Hit the colon (
:
) and then use the up arrow to start going back through previous commands. You can use the up/down arrows too to move around the list.q:
将显示 Vim 中的命令历史记录。q/
将向您显示搜索历史记录。重要的是,
:q
将退出该模式。q:
will show you command history in Vim.q/
will show you history of searches.And must importantly,
:q
will quit the mode.最后一个命令的文本存储在
.
寄存器中。通过:display可以看到所有寄存器。不幸的是,它没有说明启动正常命令的内容。要查看来自
:
(命令模式)的命令,您可以使用 :hist 或 q:,后者仅限于最后 20 个(默认情况下)。另一种能力是保存撤消缓冲区 :wundo undo.bin ——但撤消缓冲区是二进制的。
但这些都没有真正回答你的问题。我很好奇是否可以做到。
The text from the last command is stored in the
.
register. You can see all registers by :display. Unfortunately it doesn't say what the started the normal command.To see commands from
:
(command mode) you can use :hist or q: which is limited to the last 20 (by default).Another ability is to save the undo buffer :wundo undo.bin -- but the undo buffer is binary.
But none of these actually answer your question. I'm curious if it can be done.
输入冒号
:
然后ctrl+p
显示您之前的命令,即向后移动 vim 命令历史记录。ctrl+n
向前移动。如果您习惯使用命令行并且不喜欢将键盘手的位置更改为使用箭头键,那么这非常方便。
Entering colon
:
thenctrl+p
shows your previous command, i.e., moving backward through your vim command history.ctrl+n
moves forward.This is very convenient if you're used to using the command line and prefer not to change your keyboard hand positioning to use arrow keys.
很难知道它。您可以使用变量:
但您无法完全获取最后发出的正常模式命令。
但是,如果您想系统地记录在 Vim 中输入的所有内容,您可以启动 vim -W ~/.vim-last-scriptout(Windows 版本:vim -W "%HOMEPATH% \Vim\.last-scriptout)您可以在 UNIX 机器上的 shell 中为其设置别名。请注意,如果您碰巧使用
,则每个键或控制键都会被记录到该文件中。 gvim
或vim -g
(GUI)您可能遇到此错误< 如果您想重播此文件,使用
:source!
(带有感叹号)或-s
选项。您可以在 Windows I 上 已设置
gvimportable.exe -W gvim_directory\last_scriptout
作为我的 Commander 程序(FreeCommander)中的默认编辑器,这样我就可以永远记住我输入的内容并在另一个文件上重复一系列命令。用于打开 Vim 并播放脚本。请注意,该文件可能仅在 Vim 退出时写入,因此您必须失去会话才能知道您做了什么。
It is difficult to know it. You can play with the variables:
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 usegvim
orvim -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.