Skip to content

Instantly share code, notes, and snippets.

@ebylund
Last active June 20, 2017 22:52
Show Gist options
  • Save ebylund/957943669068b79709e0ffc9a62168cd to your computer and use it in GitHub Desktop.
Save ebylund/957943669068b79709e0ffc9a62168cd to your computer and use it in GitHub Desktop.
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment