Vim“显示我的最后一个命令”命令?

发布于 2024-12-28 00:27:13 字数 101 浏览 3 评论 0原文

是否有一个命令显示正常模式下的最后一个命令是什么?

假设我不小心按了随机键并得到了一些意想不到的结果。 当然我可以撤消它,但是我可以透露按下的是哪个键以及它是如何解释的吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

少女七分熟 2025-01-04 00:27:13

点击冒号 (:),然后使用向上箭头开始返回之前的命令。您也可以使用向上/向下箭头在列表中移动。

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.

迷途知返 2025-01-04 00:27:13

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.

心在旅行 2025-01-04 00:27:13

最后一个命令的文本存储在 . 寄存器中。通过:display可以看到所有寄存器。不幸的是,它没有说明启动正常命令的内容。

要查看来自 :(命令模式)的命令,您可以使用 :histq:,后者仅限于最后 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.

神回复 2025-01-04 00:27:13

输入冒号 : 然后 ctrl+p 显示您之前的命令,即向后移动 vim 命令历史记录。 ctrl+n 向前移动。

如果您习惯使用命令行并且不喜欢将键盘手的位置更改为使用箭头键,那么这非常方便。

Entering colon : then ctrl+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.

罪#恶を代价 2025-01-04 00:27:13

很难知道它。您可以使用变量:

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

但您无法完全获取最后发出的正常模式命令。

但是,如果您想系统地记录在 Vim 中输入的所有内容,您可以启动 vim -W ~/.vim-last-scriptout(Windows 版本:vim -W "%HOMEPATH% \Vim\.last-scriptout)您可以在 UNIX 机器上的 shell 中为其设置别名。请注意,如果您碰巧使用 ,则每个键或控制键都会被记录到该文件中。 gvimvim -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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文