Silently Redirecting to the Vim Clipboard

In an upcoming video tutorial, I’ll be doing a bit of work with the :redir command. This is a great Vim facility but it can be helped with a function wrapper. I’m including that wrapper here:

function! RedirToClipboardFunction(cmd, ...)

let cmd = a:cmd . " " . join(a:000, " ")

redir @*>

exe cmd

redir END

endfunction

command! -complete=command -nargs=+ RedirToClipboard

\ silent! call RedirToClipbaordFunction(<f -args>)

This function allows you to run a command (such as :history, hint hint) and have the contents placed to the clipboard that you can then paste somewhere else.

The command that is created just makes it easier to use. For example:

:RedirToClipboard history : -50,

3 comments on this post.
  1. Tedronai:

    Nice… so this blog is finally back to life?! :-)
    Just wanted to let you know that I really appreciate your previous tutorials. Looking forward to more great vim-stuff.

  2. Derek Wyatt:

    Well, it was never really dead… just very, very sleepy. I was lacking inspiration and time; recently I’ve received a small bit of both.

    Expect the blog to have “periodic” wakefulness. :)

  3. juan:

    Thank you so much for the vim“s tutorials

Leave a comment