0

I have the following search and replace expression where I am trying to format a document in a single step using multiple commands separated by |

:%s/\s\{6}...\d\d\s/  /g | %s/\(.*Inlet.*\|.*AIR.*\)/\0 false | %s/\(===)/\0 #  

I know the problem is that the interpreter does not understand that after the word "false" it needs to start with the next command.

I have tried using parenthesis and different delimiters, but it does not work.

1

The syntax of :substitute is

:[range]substitute/pattern/replacement/[flags]

(Although / can actually be any character, which is helpful for when the pattern contains slashes.)

Notice that the delimiter after replacement is not optional.

| improve this answer | |
  • "delimiter after replacement is not optional." Well, in many cases it is optional. It's not optional when the command is followed by something else, in which case Vim needs it to know where the replacement ends... But if you don't have anything following it (a :s flag such as /g, or another command following a | separator), then you can just end the line and Vim will know the replacement ends there... Right? – filbranden May 16 at 19:04
  • 1
    I think in the case of hitting enter at the command line, pr terminating the command in vimscript with a newline, you might be ok @filbranden. In sed it’s never optional :P – D. Ben Knoble May 16 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy