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";
2
Answers
One simple way is to record a macro.
f:xwi"<Esc>$a";<Esc>0j
q
@q
@@
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:
.x
delete char under cursor.w
moves us to next word, essentialy we are jumping over the whitespacei
enters 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.a
again enters insert mode, but cursor is placed after current position (essentialy$a
means append to end of the line)";
and we again exit insert mode with Esc.0
moves to the beginning of the line, andj
moves one line down. This last step is so the macro can be repeated without much thinking.That’s a job for sed, not vim. Using any POSIX sed: