Created
September 10, 2012 21:03
-
-
Save inkredabull/3693833 to your computer and use it in GitHub Desktop.
Using random number value generation 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 | |
Given a JSON data file for one Use Case, I wanted to repurpose it | |
for two other, similar Use Cases while prototyping. Actual values | |
in the copied files didn't matter; they just needed to be different | |
to make the prototype appear different between Use Cases. | |
RESEARCH | |
I knew I wanted to do something like [1] so I did a Google search | |
for "vim random number substitute" and found [2]. That didn't work | |
for me (something about my syntax of 'eval' and 'system' in command | |
mode) so I opted to leverage definitions as found in [3] which I | |
modified and put in my .vimrc file. The regex to the left-facing | |
curly bracket could have been \d+ but I opted to be lazy. | |
SOLUTION | |
'<,'>s/"foo":.*}/\=eval("printf('%s', '\"foo\":') . Random() . '}'")/ | |
REFERENCES | |
[1] : https://gist.github.com/3555497 | |
[2] : http://www.commandlinefu.com/commands/view/6880/map-r-do-insert-random-number-in-vim | |
[3] : http://vim.1045645.n5.nabble.com/simple-16-bit-random-number-generator-td2843842.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment