Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 17 down vote accepted

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
share|improve this answer

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.

share|improve this answer
This is useful, but can I use this with set guifont for example? – Steven Jul 27 '10 at 18:47
No, that is not a shell command so it will not work. – Kevin Panko Aug 2 '10 at 19:56

For this particular example you could do (note the "!" which makes it go through the shell):

:!pwd | xclip


:!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)

share|improve this answer

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.

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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