Post

How to use magic regexp to replace in vim

How to use magic regexp to replace in vim

I have an input string and I would like to take first column and transfer it in a way that the value behind = sign would be the same as the key but lowercased and encapsulated in “${}”.

1
2
3
4
5
6
7
8
9
vim
...
CLIENT_ID = "helloo-id"
TENANT_ID = "helloo-tenant"
CLIENT_SECRET = "helloo-client"
...

:'<,'>s/\v(\S+)\s\=\s(\S+)/\1 = "${\L\1\E}"/

Result:

1
2
3
4
CLIENT_ID = "${client_id}"
TENANT_ID = "${tenant_id}"
CLIENT_SECRET = "${client_secret}"

This post is licensed under CC BY 4.0 by the author.