如何使用 vi 在 Linux 的终端中编辑命令? [英] How to use vi to edit a command in terminal on Linux?
问题描述
键入非常长的命令时,我想先在文本编辑器(例如vi)中编辑该命令,然后在输入错误的情况下执行.有没有办法直接在终端中编辑命令并运行,而不是通过键入vi然后键入命令来调用vi?
When typing a very long command, I'd like to first edit the command in a text editor(e.g. vi) then execute in case of typos. Is there a way to edit the command directly in a terminal and run instead of invoke vi by typing vi then type the command?
推荐答案
如果您使用的是bash,请尝试使用 edit-and-execute-command
命令.默认情况下,它被分配给 Ctrl-x Ctrl-e
(键入ctrl-x,然后键入ctrl-e).
If you're using bash, try the edit-and-execute-command
command. By default, this is assigned to Ctrl-x Ctrl-e
(type ctrl-x, then ctrl-e).
这应该打开您的环境中指定的任何编辑器.退出时缓冲区中的所有内容都将在shell中执行-包括多行命令.
This should open whatever editor is specified in your environment. Whatever is in the buffer when you exit will execute in the shell - including multiple-line commands.
这篇关于如何使用 vi 在 Linux 的终端中编辑命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!