同一行有多个命令
我一直在尝试找到能让我在 Vim 中的同一行上运行多个命令的东西,类似于在 *nix 系统中使用分号分隔命令或在 Windows 中使用 &
。有办法做到这一点吗?
I've been trying to find something that will let me run multiple commands on the same line in Vim, akin to using semicolons to separate commands in *nix systems or &
in Windows. Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
一个
|
栏将允许您执行此操作。来自:help :bar
示例:
:echo "hello" | echo "goodbye"
输出:
注意:您可能会发现您的
~/.vimrc
不支持映射|
或\|.在这些情况下,请尝试改用
。A bar
|
will allow you to do this. From:help :bar
Example:
:echo "hello" | echo "goodbye"
Output:
NB: You may find that your
~/.vimrc
doesn't support mapping|
, or\|
. In these cases, try using<bar>
instead.将
(回车/回车)放在命令之间和之后。例如:不要使用
|
,因为:如果在某些命令后面使用
|
,某些命令会出现问题|
在配置文件中不能一致工作,请参阅:help map_bar
Put
<CR>
(Carriage Return/Enter) between and after commands. For example:Don't use
|
because:Some commands have problems if you use
|
after them|
does not work consistently in configuration files, see:help map_bar
您可以定义一个执行命令的函数。
并将其放置在例如您的 vimrc 中。运行该函数
You could define a function that executes your commands.
And place this in, for example, your vimrc. Run the function with
vim 中的命令分隔符是
|
。The command seperator in vim is
|
.认为这可能会帮助某人尝试在链中进行替换,但
由于 comment
失败,您可以使用
e
标志用于在找不到字符串时忽略错误。Thought this might help someone trying to do substitutions in a chain and one fails
from a comment
You can use the
e
flag to ignore the error when the string is not found.我总是使用
^J
通过按 Ctrl+v、Ctrl+ 来分隔多个命令j。I've always used
^J
to separate multiple commands by pressing Ctrl+v, Ctrl+j.您可以创建一个新文件,并在其上写入命令。然后
:so %
,表示源当前文件。You can create a new file, and write your commands on it. Then
:so %
, which means source current file.某些命令不允许通过
|
分隔。幸运的是,您可以将它们包装在
execute
中:输出:
Some commands don't allow separation via
|
.Luckily, you can wrap them up in an
execute
:Output: