Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim insert after specific number of delimiters

Tags:

vim

I am looking to make some code easier to read by taking something like this:

0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 ....

and adding new lines to create increments of 8:

0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
0x44, 0x44 ....

Anyone know any vim magic that will allow me to do this with specifically selected lines?

like image 617
Blackninja543 Avatar asked Jul 25 '12 19:07

Blackninja543


People also ask

How do I insert multiple lines at the beginning of vim?

vim Inserting text Insert text into multiple lines at once Press Ctrl + v to enter into visual block mode. Use ↑ / ↓ / j / k to select multiple lines. Press Shift + i and start typing what you want. After you press Esc , the text will be inserted into all the lines you selected.

How do we insert at the beginning of the line ?)?

Step 1: Move the cursor to the line from where you would like to insert the text. Step 2: Hit Ctrl + V to enter into Visual Block and use cursor to select the first column till line where you want to stop inserting the text. Step 3: Hit Shift + i to enter into insert mode .


1 Answers

This is not the prettiest solution and I am sure that it can be cleaned up / simplified some. First select the text and then enter this command:

:'<,'>s/\(\S\+,\s*\)\{8}/&\r/g

This outputs something like this:

0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
0x44, 0x44, 0x44, 0x44, ...
like image 96
zanegray Avatar answered Sep 28 '22 07:09

zanegray