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

  • SEARCH
  • Home
  • 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 6937611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:23:10+00:00 2026-05-27T12:23:10+00:00

This is related to this question: How to redirect ex command output into current

  • 0

This is related to this question:
How to redirect ex command output into current buffer or file?

However, the problem with using :redir is that it causes 3 or 4 extra newlines in front of the output, and they appear to be difficult to remove using the substitute function.

For example, if I do the following:

:redir @a  
:pwd  
:redir END 

The contents of @a consist of three blank lines and then the normal expected output.

I tried to post process with something like this:

:let @b = substitute(@a, '\s*\(.\{-}\)\s*', '\1', '')

But the result is that @b has the same contents as @a.

Does anyone know a more effective (i.e. working) way to postprocess, or a replacement for :redir that doesn’t have those extra lines?

  • 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-27T12:23:11+00:00Added an answer on May 27, 2026 at 12:23 pm

    The value in the b register is unchanged from the value in the a register because your regexp is failing to match.

    1. You need to write grouping parentheses and the opening repetition brace with with backslashes.
      See :help /magic; effectively, the magic option is always on for substitute() regexps.
    2. \s only matches SP and TAB (not LF); but \_s does include LF (alternately, you could use \n to just match LF).
    3. You need to anchor the end of the expression so that the \{-} does not “give up” without matching anything (everything but the initial newlines unmatched, and thus unreplaced from the input string).

    Here is a modified version of your substitution:

    :let @b = substitute(@a,'\_s*\(.\{-}\)\_s*$','\1','')
    

    It may be simpler to just think about deleting leading and trailing whitespace instead of matching everything in between. This can be done in a single substitution by using the g substitution modifier (repeated substitutions) with a regexp that uses the alternation operator where one alternate is anchored to the start of the string (%^) and the other is anchored to the end of the string (%$).

    substitute(@a,'\v%^\_s+|\_s+%$','','g')
    

    This regexp uses \v to avoid having to add backslashes for %^, +, |, and %$.

    Change both occurrences of \_s to \n if you just want to trim leading/trailing newlines (instead of SP, TAB, or NL).

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

Sidebar

Related Questions

This question is related to my other question How to redirect to Login page
I am using config.autoload_paths in a way very similar to this related question to
The answers to this related question of mine lead me to choose Java for
I found this related question: How do I use composition with inheritance? I would
This is a related question to one I posted earlier... I'm trying to sum
I hope this is programmer-related question. I'm in the hobby business of C# programming.
Important : Please see this very much related question: Return multiple values in C++
This is related to a question I asked the other day on how to
This is related to this question . I'm writing a Flex app (a WindowedApplication)
This is related to my question on how to handle errors from jQuery AJAX

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.