Tim Chase wrote:
here is the regex: %s/)\s*\n\s*{\n/) {\n/ig

It runs through but my code is getting formatted like this now

if(asdf) { ^@ nextline_of_code _newline_


Vim uses various represenations at different points for nulls and for newlines. Just change the "\n" in your replacement portion to "\r", making it

    %s/)\s*\n\s*{\n/) {\r/ig

and you should get the expected results.

-tim






Yes. It's mentioned quite briefly under ":help sub-replace-special", at ":help NL-used-for-Nul" and maybe elsewhere. \n in the "replace what" or "search" pattern matches a line break, but \n in the "replace by" expression inserts a null byte. To insert a line break in the "replace by" expression you must use \r -- this means that to replace a line break by itself you must replace \n by \r

At different places in Vim, and depending on the options you've set, a null byte (which is represented internally by a linefeed) may be displayed as ^@, ^J or <00>.


Best regards,
Tony.

Reply via email to