%s/\[.*\]//g
%s/stringToPrepend/prepend&/g
= do last action
A = append to end of line
C = change to end of line
D = delete to end of line
P = paste buffer before cursor
S = substitute line
V = highlight line
VU = UPPERCASE LINE
Vu = lowercase line
X = delete before cursor
Y = yank line
\D = non-digit
\W = non-word [whitespace, colons, brackets]
\d = digit
\w = word [a-Z0-9]
a = append
b = go to previous word
c = change
d = delete
e = go to end of word
h = <-
j = v
k = ^
l = ->
p = paste buffer after cursor
s = substitute
u = undo
v = highlight character
w = go to next word
x = delete
y = yank

+++
vim: how to search/replace special chars?

Ask Question
up vote 22 down vote favorite
9
9

After a copy-paste from wikipedia into vim, I get this:
1 A
2
3 [+] Metier agricole<200e> - 44 P o 2 C
4 [ *] Metier de l'ameublement<200e> - 10 P
5 [ *] Metier de l'animation<200e> - 5 P
6 [+] Metier en rapport avec l'art<200e> - 11 P o 4 C
7 [ *] Metier en rapport avec l'automobile<200e> - 10 P
8 [ *] Metier de l'aeronautique<200e> - 15 P

The problem is that <200e> is only a char.

I'd like to know how to put it in a search/replace (via the / or
:).
vim replace
share|improve this question
edited Dec 9 '11 at 15:19
lucapette
17.7k45457
asked Dec 9 '11 at 15:14
Olivier Pons
8,0751567143
* what page is it anyway? - Ya Zhuang Dec 9 '11 at 15:19

add a comment |

2 Answers 2

active oldest votes
up vote 24 down vote accepted

Check the help for \%u:
/\%d /\%x /\%o /\%u /\%U E678

\%d123 Matches the character specified with a decimal number. Must befollowed by a non-digit.
\%o40 Matches the character specified with an octal number up to 0377. Numbers below 040 must be followed by a non-octal digit or a non-digit.
\%x2a Matches the character specified with up to two hexadecimal characters.
\%u20AC Matches the character specified with up to four hexadecimal characters.
\%U1234abcd Matches the character specified with up to eight hexadecima
l
characters.

These are sequences you can use. Looks like you have two bytes, so
\%u200e should match it. Anyway, it's pretty strange. 20 in UTF-8
/ ASCII is the space character, and 0e is ^N. Check your encoding
settings.
share|improve this answer
answered Dec 9 '11 at 15:21
sidyll
37.1k874126
* 1
\u200e is never encoded as \x20\x0e in utf-8, it is encoded as
three bytes \xE2\x80\x8E, you can test this by running echo
"\u200E" is# "\xE2\x80\x8E": it will output 1 if you have
'encoding' option equal to 'utf-8'. So, this sequence has no
connection with space or newline. - ZyX Dec 10 '11 at
22:22
* Thanks @ZyX , much clearer now. I should dedicate a moment to
learn more about UTF-8, I'm often facing these here and there
without really understanding it. If you know any document that
is a must read in this subject please let me know.
- sidyll Dec 12 '11 at 11:57
* @ZyX by the way I think the real encoding for \u202E is
\xE2\x80\xAE instead (I begin to see a little now)
- sidyll Dec 12 '11 at 12:10
* UTF-8 is described in wikipedia, there also must be some
links, including link to the RFC (I read only Russian version
and didn't bother myself to remember much of it). You can
always get how specific symbol is encoded by doing echo
"\u202E" "\u202E" ... "\u202E"[len("\u202E")-1] or
automate it using let s="\u202E" | echo map(range(len(s)),
's[v:val]'). - ZyX Dec 13 '11 at 18:03
* @sidyll My favorite link on that stuff, I'm still re-reading
it almost every 6 months!
joelonsoftware.com/articles/Unicode.html - Olivier
Pons Nov 25 '13 at 8:53

| show 2 more comments
up vote 4 down vote

If you want to quickly select this extraneous character everywhere
and replace it / get rid of it, you could :
1. isolate one of the strange characters by adding a space before
and after it, so it becomes a "word"
2. use the * command to search for the word under the cursor. If
you have set hlsearch on, you should then see all of the
occurances of the extraneous character highlighted.
3. replace last searched item by something else, globally:
:%s//something else/

share|improve this answer
answered Dec 9 '11 at 15:29
Dalker
423511