Skip to main content
added 418 characters in body
Source Link

I cannot add comment to previous answer, so I decided to post my answerown.

As it's already been mentioned, you should use 'g' modifierflag to replace all occurrences. But for :s/X/Y/gcg it will still replace only in current line]line. Reference from :help :s

4.2 Substitute                      *:substitute*
                            *:s* *:su*
:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]

            ......
    
            When [range] and [count] are omitted, replace in the
            current line only.

            ......

You can specify range after colon symbol, like % (:%s/X/Y/cg), to replace in the whole file. Or you can specify range from current line to document's end by .,$ (:.,$s/X/Y/cg). More about ranges you can see in :help :range:

I cannot add comment to previous answer, I decided to post my answer.

As it's already been mentioned, you should use 'g' modifier to replace all occurrences. But for :s/X/Y/g it will still replace only current line]. You can specify range after colon symbol, like %, to replace in the whole file.

I cannot add comment to previous answer, so I decided to post my own.

As it's already been mentioned, you should use 'g' flag to replace all occurrences. But for :s/X/Y/cg it will still replace only in current line. Reference from :help :s

4.2 Substitute                      *:substitute*
                            *:s* *:su*
:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]

            ......
    
            When [range] and [count] are omitted, replace in the
            current line only.

            ......

You can specify range after colon symbol, like % (:%s/X/Y/cg), to replace in the whole file. Or you can specify range from current line to document's end by .,$ (:.,$s/X/Y/cg). More about ranges you can see in :help :range:

Source Link

I cannot add comment to previous answer, I decided to post my answer.

As it's already been mentioned, you should use 'g' modifier to replace all occurrences. But for :s/X/Y/g it will still replace only current line]. You can specify range after colon symbol, like %, to replace in the whole file.