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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:31:43+00:00 2026-05-28T20:31:43+00:00

Here is a sample of text that I’m working with: Word1 Word2 … Word4

  • 0

Here is a sample of text that I’m working with:

Word1
Word2
...
Word4 / Word5 Word6
Word7
Word8 Word9 Word10 / Word11 Word12 Word13 Word14
Word15
Word16
...

I would like to transform it by splitting the lines containing
slash-separated chunks, so that the first chunk (preceding the slash)
gets the trailing words copied from the second chunk (following the
slash) to equalize the number of words in both lines resulting from
the chunks, if the former one has fewer words than the latter.

In other words, the desired transformation is to target the lines
consisting of two groups of words separated by a (space-surrounded)
slash character. The first group of words (preceding the slash) on
a target line has 1 to 3 words, but always fewer than the second
group.

Thus, the target lines have the following structure:

‹G1› / ‹G2› ‹G3›

where ‹G1› and
‹G2› ‹G3› (i.e.,
‹G2› concatenated with ‹G3›)
constitute the two aforementioned groups of words, with
‹G2› standing for as many of the leading words of the
after-slash group as there are in the before-slash one, and
‹G3› standing for the remaining words in the
after-slash group.

Such lines should be replaced with two lines, as follows:

‹G1› ‹G3›
‹G2› ‹G3›

For the above example, the desired result is as follows:

Word1
Word2
...
Word4 Word6
Word5 Word6
Word7
Word8 Word9 Word10 Word14
Word11 Word12 Word13 Word14
Word15
Word16
...

Could you please help me implement this transformation in Vim?

  • 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-28T20:31:43+00:00Added an answer on May 28, 2026 at 8:31 pm

    You can write a function to expand slash:

    fun! ExpandSlash() range
        for i in range(a:firstline, a:lastline)
            let ws = split(getline(i))
            let idx = index(ws, '/')
            if idx==-1
                continue
            endif
            let h= join(ws[ : idx-1])
            let m= join(ws[idx+1 : 2*idx])
            let t= join(ws[2*idx+1 : ])
            call setline(i, h.' '.t.'/'.m.' '.t)
        endfor
    endfun
    

    :%call ExpandSlash()
    :%s@/@\r@
    

    before

    1 2 3 / 4 5 6 7 8
    

    after

    1 2 3 7 8
    4 5 6 7 8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is sample of the text file I am working with: <Opera> Tristan/NNP and/CC
In QMessageBox how can I make the title text bold? Here is the sample
i am working on a program that reads in a text file that the
Here, the listbox is loaded sample Text. My Model.aspx will be public class Employee
I'm trying to get auto-complete working with a simple application that I'm building. Here
Here is a sample application that creates a Window with a single Button inside.
I'm working on an application that requires arabic text to be displayed, using custom
Here is a simple program to output to a text file: #include <iostream> #include
a simple question here Is there a way to change the text click here
Simple question, I just want to select the text from the <Template> tag. Here's

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.