Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I search for the dot character using the search command?

Tags:

replace

vim

I'm trying to use the Search command in Vim:

:Rs/F/T/X

R = range
F = text to find
T = text to replace with
X = options

But, when I want to search for the "." (dot character) I'm getting some problems.

The task: Replace all occurences of " ." (space dot) for ">" (greater-than)

So, first I tried this:

:%s/ ./>/g

But this changed me all the " ." (space ANY-CHARACTER) to the ">" character.

Then I remembered that the dot character is a special one, so I tried this:

:%s/ \./>/g

But vim threw me an error: E486 Can't find pattern " \."

And finally I tried this crazy thing:

:%s/" ."/>/g and this :%s/" \."/>/g

But I got the same result: E486 Can't find pattern...

So, how can I search for the dot character using the search command?

PS: Sorry for my poor English.

like image 319
Lucas Gabriel Sánchez Avatar asked May 12 '10 17:05

Lucas Gabriel Sánchez


1 Answers

Both a space and a dot are special characters. Try this:

:%s/\s\./>/g

Update: \s is used to represent all whitespace characters (space, tab, line break), not just a space.

like image 110
Ben Hoffstein Avatar answered Oct 05 '22 23:10

Ben Hoffstein