Skip to content

Instantly share code, notes, and snippets.

@chewmanfoo
Created January 11, 2020 18:16
Show Gist options
  • Save chewmanfoo/fc6cadff0be740a045e8adf1e6be1d67 to your computer and use it in GitHub Desktop.
Save chewmanfoo/fc6cadff0be740a045e8adf1e6be1d67 to your computer and use it in GitHub Desktop.
vim search and replace
I have this file containing a lot of this
authorized_cidr = ""
concourse_keys = ""
encryption_key = ""
instance_ami = ""
name_prefix = ""
postgres_database = ""
postgres_host = ""
postgres_password = ""
postgres_port = ""
postgres_username = ""
private_subnet_ids = ""
public_subnet_ids = ""
I need to transform into this:
authorized_cidr = "${var.authorized_cidr}"
concourse_keys = "${var.concourse_keys}"
encryption_key = "${var.encryption_key}"
... etc
I'm trying vim, like this:
%:s:/\(\s*\)\(\w*\)\(\s*\)=\(\s*\)"":\1\2\3= "\$\{var.\1\}"
but it doesn't work. It reports the error "Pattern not found: /\(\s*\)\(\w*\)\(\s*\)=\(\s*\)"""
@chewmanfoo
Copy link
Author

%s/\s*(\w*)\s*=\s*"\zs\ze"/${var.\1}

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