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 876385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:25:23+00:00 2026-05-15T11:25:23+00:00

In the article, Vim Regular Expressions , Oleg Raisky gives the following command to

  • 0

In the article, Vim Regular Expressions, Oleg Raisky gives the following command to reduce multiple blank lines to a single blank:

:g/^$/,/./-j

Can someone please describe how this works?

I know :g command and regular expressions. But I didn’t understand what the part /,/./-j does.

  • 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-15T11:25:24+00:00Added an answer on May 15, 2026 at 11:25 am

    It really is quite ingenious. Let’s break it down. The ex command

    g/^$/xyzzy
    

    will search for all empty lines and execute the xyzzy command (an arbitrary ex command) on each of them.

    The tricky bit here is that the xyzzy command in your case is yet another substitute command:

    ,/./-j
    

    The ,/./- specifies a range. This is of the form <start>,<end> and, because there’s nothing before the comma, it assumes the current line (the one where you found the blank line) is the start.

    After the comma is /./- which means search for the next character (. means any character) then back up one line (/./- is short for /./-1 since the one is implied if no value is given). You’ll find that pattern . on the first non-blank line following the one you’re operating on.

    In other words, the end of the range is the last blank line after or at the one you’re currently operating on.

    Then you execute a join over that range.

    If the start and the end of the range were equal (only one blank line was in the section), join does nothing. If they’re not equal, join will join them all up.

    That’s the way in which it combines multiple blank lines into one.

    Lets look at an example (line numbers are not in the file):

    1 Line 1
    2
    3 Line 3
    4 Line 4
    5
    6
    7
    8
    9 Line 9
    

    The :g command will find all blank lines and perform its operation on them (lines 2, 5, 6, 7 and 8).

    For line 2, ,/./-j will set up a range from 2 to 2 (next . found on line 3 then subtract 1). A join on the range 2,2 does nothing.

    For line 5, ,/./-j will set up a range from 5 to 8 (next . found on line 9 then subtract 1). A join on the range 5,8 will join all those lines together.

    I’m not entirely certain about this but I think the operation may not be performed on lines that disappear as part of an earlier operation. That’s because it would make no sense to process lines that have been deleted earlier in the cycle.

    In other words, because lines 6 through 8 are deleted (combined with line 5), the global command doesn’t operate on them after that. I base that on nothing more than the fact that the vim documentation states a two-pass algorithm, one to mark the lines, one to perform the operation.

    I may be wrong on that point (it wouldn’t be the first time) but it’s an implementation detail which doesn’t affect the functionality.

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

Sidebar

Related Questions

This article argues that regular expressions cannot match nested structures because regexes are finite
This article gives a good overview on why structured exception handling is bad. Is
An article has many articles that it refers to and many other articles can
The wikipedia article about Law of Demeter says: The law can be stated simply
I recently read this article related to indenting source files in Vim . However
This article says that Emacs has redo because you can reverse direction while undoing,
The article gives a good insight of how to deal with sqlite in Flex;
The article states the following: http://msdn.microsoft.com/en-us/library/dd799517.aspx Variance does not apply to delegate combination. That
I found an article on About.com that tells you how you can manage your
In this article its says that references allow you to reduce the amount of

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.