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 screendefaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool trueI'd like to replace # Trackpad: ... with running Trackpad: ...Breaking the problem down, I came up with something using a regex tester:/\n\n#\s(.*)/gIf I try and use this in Vim it doesn't work for me::/\n\n#\s(.*)/running \1/gI 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.
Find and replace using regular expressions
regular expression;substitute
Just to be clear I believe you asked for this to be the result of the substitution?################################################################################ Trackpad, mouse, keyboard, Bluetooth accessories, and input                 ################################################################################running Trackpad: enable tap to click for this user and for the login screendefaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool trueIn that case, I recommend the following command::%s/\n\n#\s+(.*)/^M^Mrunning \1/Explanation of the pattern:s/PATTERN/REPLACEMENT/ is the substitute command.  The percent sign in :%s makes it work on the whole file, rather than just the current line.The \n\n says that the line of interest must occur after a blank line.  If you didn't care about the preceding blank line, then ^ would suffice.#\s\+ matches a hash character followed by one or more whitespace characters.  \(.*\) captures all subsequent text on the line.Explanation of the replacement text^M^M inserts two ends of lines to replace the \n\n that were present in the pattern.  Otherwise, the text would get moved to the end of the line preceding the blank line.  To type each ^M, press Ctrl-V Ctrl-M.Then, insert the string running, followed by whatever was captured in the parentheses within double-quotes.