Created
August 31, 2012 16:33
-
-
Save inkredabull/3555497 to your computer and use it in GitHub Desktop.
Using dynamic val in vim substitution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BACKGROUND | |
Was using a file with a bunch of named data points [1]. Didn't | |
want to edit the name of each data point to repurpose it for my | |
prototyping efforts but needed a command mode substitution to | |
iterate over a visual block and do the replacement but with a | |
dynamic expression (line number is adequate.) | |
Found [2] and then figured out I'd need something like printf() | |
for use in eval() so stumbled upon [3]. | |
SOLUTION | |
:'<,'>s/"name":".*"/\=eval("printf('%s','\"name\":\"foo') . printf('%s', line('.')) . '\"'")/ | |
REFERENCES | |
[1] : http://bost.ocks.org/mike/sankey/energy.json | |
[2] : http://vim.wikia.com/wiki/Using_an_expression_in_substitute_command | |
[3] : http://vim.1045645.n5.nabble.com/what-is-vim-s-printf-as-it-is-in-c-td4973892.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment