I have a file with following pattern
property1: value1 property2: value2 property3: value3 property4: value4 property5: value5
Value could be ipv4/ipv6 ip address, number, string etc.
How can this be modified to something like using available text editor tools:
property1 "value1"; property2 "value2"; property3 "value3"; property4 "value4"; property5 "value5";
One simple way is to record a macro.
- Place a cursor on first line, first column
- Make sure you are in "normal" mode.
- Start recording a macro into "q" register by typing "qq"
- Stop recording by typing
- Transform next line by typing
- Repeat macro by typing
You will see your file transforming.
Detailed explanation of step 4:
f<char>moves the cursor to next occurence of . That’s how we get from the first column of the line to the index of
xdelete char under cursor.
wmoves us to next word, essentialy we are jumping over the whitespace
ienters insert mode, so we can type new characters. We are inserting
"and exiting insert mode by pressing Esc.
$gets us to the end of the line.
aagain enters insert mode, but cursor is placed after current position (essentialy
$ameans append to end of the line)
- We insert last chars
";and we again exit insert mode with Esc.
0moves to the beginning of the line, and
jmoves one line down. This last step is so the macro can be repeated without much thinking.