5

After pressing <C-g> in normal mode, prints useful information in the status line. How can I yank this text?

2
  • Welcome to Vi and Vim!
    – filbranden
    Commented May 23, 2022 at 20:19
  • If you use tmux you can yank any text printed to the terminal. Commented May 24, 2022 at 22:41

1 Answer 1

4

The output of <C-g> is the same as that of the :file command with no arguments.

In order to capture the contents of a command such as :file, you can use the execute() Vimscript function.

For example, to paste those contents below the current line, in the current buffer, you can use:

:put =execute('file')

Or to capture those contents in register x, you can use:

:let @x = execute('file')

Followed by something like "xp to paste those contents from the register into the buffer.

1
  • 3
    And of course with clipboard support :let @* = execute('file')
    – D. Ben Knoble
    Commented May 23, 2022 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.