How do I copy command output in vim?
Solution 1
Are you looking for this,
:redir @* | set guifont | redir END
:redir command redirects the output of a command to a register (@*). The register @* refers to the clipboard.
For more info on this,
:help :redir
Solution 2
Try ':r !pwd
' to get the current working directory directly in to the GVIM opened file.
You can then copy it to clipboard like you would any other text file contents opened there.
Solution 3
For this particular example you could do (note the "!" which makes it go through the shell):
:!pwd | xclip
or
:!pwd | xclip -selection secondary
(depending on which X-selection you want).
You might have to install xclip first
sudo apt-get install xclip
(or equivalent)
Solution 4
If you're running vim in an xterm, holding the shift key while selecting the text will copy the text to the X equivalent of the clipboard.
Related videos on Youtube
Steven
Updated on September 17, 2022Comments
-
Steven over 1 year
For example, if I type '
:pwd
' to get the current working directory, I can select the text in gvim but I can't figure out how to copy it to the clipboard. If I try the same in console vim, I can't even select it with the mouse. I would like this to work with all vim commands, such asset guifont
to copy theguifont=Consolas:h10:cANSI
output. -
Marius Gedminas almost 14 yearsX has two clipboards (at least); your suggestion will place the text in the PRIMARY selection (paste with middle-click) rather than the CLIPBOARD hselection (paste with Ctrl+V in most apps).
-
Steven almost 14 yearsThis is useful, but can I use this with
set guifont
for example? -
DrColossos almost 14 yearsNo, that is not a shell command so it will not work.
-
Sergio Abreu over 7 yearsdidn't work in vim-gtk some clue ?
-
leeand00 over 6 years@SergioAbreu try
@+
instead of@*
(well, it works in gvim).