Skip to content

Instantly share code, notes, and snippets.

@kylewest
Created December 23, 2011 14:07
Show Gist options
  • Save kylewest/1514301 to your computer and use it in GitHub Desktop.
Save kylewest/1514301 to your computer and use it in GitHub Desktop.
replace all 3-character HEX color codes with 6-character codes in vim
# this will replace all 3-character HEX color codes with 6-character codes in vim.
%s/#\([0-9A-Fa-f]\)\([0-9A-Fa-f]\)\([0-9A-Fa-f]\)\([0-9A-Fa-f]\)\@!/#\1\1\2\2\3\3/g
1--
2---------------------------------------------
3--------------
4----------------
5-
1. substitution.
2. # followed by valid hex digit. \( \) is used to group the matches.
3. zero width preceding match to only match #111, not #111111. ':help @!' for details.
4. substitution. double each of the matched groups.
5. global match.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment