Search and replace the following in vi

Hi I want to replace the occurrence of [x] with [] in vi editor

I have used the following command

:%s/[x]/[]

and it gives me [[]], how to update my command so that I get desired result.

Upvotes: 0

Views: 53

Answers (1)

Garo
Garo

Reputation: 1520

You can replace:

  • It once (the first occurrence on the current line) with: :s/\[x\]/[]/
  • It everywhere on the current line with :s/\[x\]/[]/g
  • The first occurence on every line with :%s/\[x\]/[]/
  • It everywhere :%s/\[x\]/[]/g

(Obviously you must make sure you are in command mode, use the esc-key for this)

Upvotes: 2

Related Questions