Substitute partial line in vim using only substitute command
vim
Solution
This command should do what you want:
:%s/\v(".{-}")/\=substitute(submatch(1), "_", " ", "g")
I capture the first pair of quotes on each line then I use it as replacement with all underscores removed.
Problem
I am editing a file with lines similar to the following: ``` {"a_function", a_function}, {"a_second_function", a_second_function}, ``` I would like to convert the underscores to spaces, but only within the quotes. Is there a way to do this just by using the `:substitute` command? I know I can do this by recording a macro and there are probably plugins out there that can do this, but for the sake of cleverness I'd like to do this in one shot with the `:substitute` command.