torbai
torbai

Reputation: 19

In Vim, how to copy content in file and use it in command?

For example, I open a file which includes

FATAL ERROR: Simulation failed. Please read /path/to/the/error/file.error

What I want to do is copy the path of the error file, which I've already done that by "v" into the visual mode and "y" to copy it, and open that file by splitting the window by ":sp /path/to/the/error/file.error".

My problem is: how to paste the copied path in command mode?

Upvotes: 1

Views: 335

Answers (2)

filbranden
filbranden

Reputation: 8898

Vim also has a feature to open the filename under the cursor directly.

If you want to open it in a new split, then you can use Ctrl+W, f (or the equivalent Ctrl+W, Ctrl+F).

See :help CTRL-W_f for more details.

The mapping to open the file under the cursor in the current window (not in a new split) is gf.

Upvotes: 3

Keith Nicholas
Keith Nicholas

Reputation: 44288

In command mode, use Ctrl-R, which is paste register, then " to paste the last yanked thing from the unnamed register.

to see your current registers, execute the following command :reg

Upvotes: 1

Related Questions