I have a file with a bunch of user defaults in. I want to change some of the text, but I'm struggling coming up with a matcher and replacer. Using the following example:
###############################################################################
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
###############################################################################
# Trackpad: enable tap to click for this user and for the login screen
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
I'd like to replace # Trackpad: ...
with running "Trackpad: ..."
Breaking the problem down, I came up with something using a regex tester:
/\n\n#\s(.*)/g
If I try and use this in Vim it doesn't work for me:
:/\n\n#\s(.*)/running "\1"/g
I guess my problem boils down to two specific questions:
- How can I avoid searching for
\n
characters, and instead make sure#
doesn't appear at the end of the search group? - How can I effectively use capture groups?
There are some great answers below. Hard to choose between all three, however I feel the chosen answer is the most accurate for my original spec. I recommend you try all three answers with the actual file to see how you feel about them.