Lone Learner
Lone Learner

Reputation: 20628

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?

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.

vim "$(which foo)"

How can I do this with the :e command when I am already within Vim?

I am looking for something that is the equivalent of :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. 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.

Upvotes: 5

Views: 1084

Answers (1)

Amadan
Amadan

Reputation: 198324

:e `which foo`
:help backtick-expansion

Upvotes: 5

Related Questions