Tuesday, April 30, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 353  / 2 Years ago, tue, march 8, 2022, 12:49:22

I'm trying to use the substitute command in VIm but don't get the result I excpect:
I'm editing an html file, and for example I'd like to replace all "é" characters by the é code (yes it's in French and yes I really like to complicate my life :).



Then I use this command: :s /é /é /gc to replace all é by é in the line with asking for confirmation. This time it says the pattern hasn't been found, but when it finds it, it adds and don't replace, so the result is that the word "piétons" is replaced by the word "piéétons" ... the character é isn't deleted.



Can someone explain what I'm doing wrong please?



substitute command in VIm 01



substitute command in VIm 02


More From » 14.04

 Answers
7

You have to escape the & sign. Try that:



:s /é /é /gc


Notice, I don't know if it is desired, but your substitution only replaces é if it is followed by a space. To replace all é's, use that command (without the spaces):



:s /é/é/gc

[#21416] Thursday, March 10, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
berlorful

Total Points: 346
Total Questions: 90
Total Answers: 99

Location: Monaco
Member since Tue, Nov 30, 2021
2 Years ago
berlorful questions
Thu, Sep 2, 21, 10:12, 3 Years ago
Sun, May 9, 21, 20:55, 3 Years ago
Mon, Jan 16, 23, 23:19, 1 Year ago
Mon, Aug 29, 22, 05:43, 2 Years ago
;