简体   繁体   English

在Vim中命令行模式(ex模式)中的命令替换

[英]Command substitution in command-line mode (ex mode) in Vim

Short and simple example 简短的例子

How can I use shell like command substitution in the vim command-line mode? 如何在vim命令行模式下使用shell命令替换?

For example, if I want to edit a particular path whose path is available as output of another command, say, which foo , I could do something like this on the shell. 例如,如果我想编辑一个路径可用作另一个命令的输出的特定路径,比如说which foo ,我可以在shell上做这样的事情。

vim "$(which foo)"

How can I do this with the :e command when I am already within Vim? 当我已经在Vim中时,如何使用:e命令执行此操作?

I am looking for something that is the equivalent of :e $(which foo.txt) . 我正在寻找相当于的东西:e $(which foo.txt)

Real use case 真实用例

The above is just a short example so that this question makes sense for everyone. 以上只是一个简短的例子,这个问题对每个人都有意义。 Here is the real reason why I am looking for this answer. 这是我寻找这个答案的真正原因。

In the shell, I can execute gdb -p $(pidof bar) to attach to a process bar and debug it. 在shell中,我可以执行gdb -p $(pidof bar)来附加到进程条并进行调试。 With Vim, I am using ConqueGdb which accepts the same arguments as gdb, so I would want to do something like :ConqueGdb -p $(pidof bar) from within Vim. 使用Vim,我使用的ConqueGdb接受与gdb相同的参数,所以我想做一些类似于:ConqueGdb -p $(pidof bar) Vim内的:ConqueGdb -p $(pidof bar)

:e `which foo`
:help backtick-expansion

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM