ebylund
6/20/2017 - 10:36 PM

An example of using vim registers to reformat a config file

An example of using vim registers to reformat a config file

with vim, I wanted to change the following line items in a file:

    aws.kinesis.version: "this is just some version of this text"

to look like:

AWS_KINESIS_VERSION="this is just some version of this text"

using vim Macros, the following sequence of character is reponsible for the changes:

^d0vf:^[:s/\%V\./_/g^MgUiwf:dwi=^[j

^d0 is reponsible for deleting any leading whitespace

vf:^[ visually selects everything up to the first : on the line. ^[ is the ESC charcter.

Substituting in the last selected text by using:

:s/\%V\./_/g^M this substitues any . with _ in the last visual selection

gUiw will Uppercase the word under the cursor

f:dw will delete the next : until the next word

i=^[j will insert a = and move down a line