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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:09:17+00:00 2026-06-18T12:09:17+00:00

Using a text editor, without writing JavaScript functions (e.g. can’t use this great answer:

  • 0

Using a text editor, without writing JavaScript functions (e.g. can’t use this great answer: Replacing the nth instance of a regex match in Javascript)

How do I take something like this (a proprietary code structure I have no control over)

map(key1, value1, key2, value2, key3, value3, key4, value4 ...)

And convert it to this

map(
  key1, value1,
  key2, value2,
  key3, value3,
  key4, value4 
  ...
)

One option I found was using this regex to find every 2nd comma (([^,]*,){2})

Then replace with \1\n\t

But I would like to improve it:

1. It doen’t handle the first and last lines very well

 map(key1, value1,
    key2, value2,
    key3, value3,
    key4, value4 ...)

2. Only works on a flat structure

e.g. I can’t think of a way to transform this

map(key1, value1, key2, map(key3, value3, key4, value4 ...), key5, value5)

To this

map(
  key1,value1,
  key2,map(
    key3,value3,
    key4,value4 
  ),
  key5,value5    
)

Using regex, or is there a way?

  • 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-06-18T12:09:17+00:00Added an answer on June 18, 2026 at 12:09 pm

    Eran, oh you finally tag the question with vim, nice! ^_^

    vim can format it a bit, I wrote a small function:

    Note that I used \r as linebreak, if it doesn’t work for you, change into \n

    function! ExpandMap()
        let s = line('.')
        exec 'silent s/(/(\r/g'
        let e = line('.')
        exec 'silent '.s.','.e.'s/),\=/\r&\r/g'
        let e = line('.')
        exec 'silent '.s.','.e.'s/,[^,]*\zs,\ze/,\r/g'
        let e = line('.')
        exec s.','.e.' normal =='
    endfunction
    

    You can put it in your .vimrc file, if you use that very often. Also you could just give it a try by typing :so %

    You can create a map for that function call by:

    `nnoremap <leader>r :call ExpandMap()<cr>`
    

    in this way, if you want to reformat your map line, just move cursor to that line, and in Normal mode type <leader>r (default is \)

    This function will change

    map(k1, v1, k2,  map(k3, v3, k4, v4), k5, v5, k6, map(k7, v7,k8,v8,k9,v9),k10,v10,k11,v11)
    

    into

    map(
            k1, v1,
            k2,  map(
                k3, v3,
                k4, v4
                ),
            k5, v5,
            k6, map(
                k7, v7,
                k8,v8,
                k9,v9
                ),
            k10,v10,
            k11,v11
    )
    

    Here I show how it works:

    • I split the window into two, just show the function
    • I created a mapping after the function
    • I make two nested maps, also to make the line short, I just used k#, v#

    enter image description here

    Now, when are you gonna uninstall your notepad++? ^_^

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

Sidebar

Related Questions

I am using this text editor for my windows forms application This works great
I am writing a text editor and had planned on using the richtextbox control
I am writing a text editor using Avalon Edit. I would like to replace
I am designing a simple Rich Text Editor using HTML/Javascript. It uses iframe. While
I'm using a rich text editor type control, which is a written as a
I am using a rich text editor on my website and i am using
I am using SciTE as text editor. It is possible to run script and
I am making a text editor using Java swing. I am using JTextArea for
I'm currently using the Rich Text Editor from the YUI framework. But I don't
guys which text editor is good for Rubyonrails? i m using Windows and i

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.