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 as set guifont to copy the guifont=Consolas:h10:cANSI output.
- 2,329
- 12
- 35
- 41
5 Answers
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
- 2,806
- 4
- 20
- 23
-
didn't work in vim-gtk some clue ? – Sergio Abreu Jan 05 '17 at 21:32
-
@SergioAbreu try `@+` instead of `@*` (well, it works in gvim). – leeand00 Jan 03 '18 at 20:45
-
Didn't work. Had to `:redir @"`, paste in a buffer and copy to clipboard, `"*Y`, from there – CervEd May 05 '23 at 09:16
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.
- 55,788
- 10
- 98
- 140
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.
- 34,610
- 8
- 97
- 89
-
X 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). – Marius Gedminas Jul 26 '10 at 11:47
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)
- 1,082
- 2
- 9
- 18
You could send to a file and copy it from there:
SomeCommand > SomeFile.txt
vim SomeFile.txt
See How do I save terminal output to a file? on AskUbuntu.
- 132
- 8