views:

116

answers:

1

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.

+6  A: 

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.

Ben Hoffstein
Excellent! :) Thanks! (it works)
unkiwii
Since when is space a special character? `:%s/ \./>/g` works fine for me. You're actually modifying the search by using `\s` to include other kinds of whitespace, not just space.
Jefromi
But `:%s/ \./>/g` doesn't works for me.
unkiwii
Jefromi is right. I just tried :%s/ \./>/g and it worked. Not sure if you are on a different version of Vim or what. I never realized that \s applies to all whitespace (spaces, tabs, line breaks), so keep that in mind if you use the pattern I provided.
Ben Hoffstein
@lk: My guess is that your space character isn't a space character but a tab.
Hasturkun
@Hasturkun: You're probably right (unless it's something weird like a nonbreaking space). I'm tempted to edit the question, because it's not at all about how to search for `.`, but it'd be a pretty big edit.
Jefromi
@Hasturkun: The character is the simple space character (not tab or somthing like that)@Ben Hoffstein: I'm using gVim 7.2
unkiwii