Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 706609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:11:08+00:00 2026-05-14T04:11:08+00:00

How can I redirect or pipe the output of an ex command into my

  • 0

How can I redirect or pipe the output of an ex command into my current buffer or a file?

For example, I want to read the contents of all the registers into the current buffer, which in ex mode is shown using :registers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:11:08+00:00Added an answer on May 14, 2026 at 4:11 am
    :redir >name_of_registers_file
    :registers
    :redir END
    :r name_of_registers_file
    :help redir
    

    The last command is very useful, since there are lots of options for redirection: to variables, to registers, how to append, further cornucopia.

    I still find it weird and annoying that it uses END that way, but since everything else that can follow redir has to start with a non-word-character, at least it’s not ambiguous.

    PS AFAIK (which is pretty far in this case) there’s no way to read it directly into the buffer: you have to store it in a register or a variable first. Check the help for the various options of how to do that.

    PPS If you do want to do this using a variable —maybe to encapsulate it in a function and avoid clobbering registers or global variables— you’ll have to convert the multiline string that gets written to the variable into a list. EG

    :call append( '.', split(variable_you_redirected_to, "\n") )
    

    Otherwise (if you just do append('.',var)) you end up with ^@’s (nulls) instead of newlines, since that’s what vimscript uses to represent newlines in String variables.

    edit: as @Bill Odom mentions, using :put =variable_you_redirected_to is a lot easier than the complicated append() expression. Thanks, Bill!


    PPPS

    I’ve written a snippet to make this stuff more convenient. It declares a function Redir(command, target) and a command R.

    The command parses the last series of non-space characters as a redirection target and passes that to the function, which does the boilerplate to redirect the command output to the redirection target.

    The command is everything after R and before the last space.

    EG

    " Store the vim buffer list in buffer_list.txt
    :R ls >buffer_list.txt
    " Store error messages emitted by a function being debugged
    "   in the 'unnamed register'
    :R call FunctionBeingDebugged() @">
    

    There are a few limitations with this: for example you won’t be able to write to a filename that contains a space. The upside to this is that you don’t have to quote your command. I’ve got it posted on gist.github.com, and I’ll try to keep it updated if I end up improving it. Or you can fork it yourself</noeuphemism>!

    Anyway the snippet is available here. It can be dropped into a .vimrc file or into a file in ~/.vim/plugins.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I pipe the stdout of multiple commands to a single command? Example
I'm trying to redirect a patch command output using a named pipe. I tried
How can I redirect to current url after logout? HTLM for logout: <a href=<?php
How can I redirect all external links (ie clicks from Google towards my site)
How I can redirect users to home page in default language? For example to
Normally I would start a command like longcommand &; I know you can redirect
I want to do subprocess.call, and get the output of the call into a
I am trying to redirect output so I can send it over the network.
Usually we can redirect to another page using ForwardResolution(path) in stripes, but I want
Possible Duplicate: Can colorized output be captured via shell redirect? setup In this case

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.