LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (https://www.linuxquestions.org/questions/general-10/)
-   -   vim search pattern (https://www.linuxquestions.org/questions/general-10/vim-search-pattern-664343/)

Berticus 08-21-2008 09:36 AM

[SOLVED] vim search pattern
 
I have vim on Windows, and need to use it to edit a file containing a list of files. An example would be something like "C:\Documents and Settings\Berticus\foo\bar." I would like to replace "C:\Documents and Settings\Berticus" with something like "D:\Backup\Berticus Files"

If I do something like
Code:

:%s/C:\Documents and Settings\Berticus/D:\Backup\Berticus Files
It says:
Code:

E486: Pattern not found: C:\Documents and Settings\Berticus
But pretty much every line starts with that.

I also tried:
Code:

:%s/*Berticus/D:\Backup\Berticus Files
and that didn't work either.

I don't have a lot of experience with patterns, and the semicolon always throughs everything off. I've always found a way to work around it, but this time I can't seem to figure a way around it.

---Edit---
Solved:
Code:

:%s/.*Berticus/D:\Backup\Berticus Files

oneandoneis2 08-21-2008 10:26 AM

You need TWO backslashes: C:\\Documents etc.

Backslash is a special character, it's so you can do things like :%s/Indent/\tIndent and it'll insert a tab in front of the word Indent..

Berticus 08-21-2008 11:39 AM

Quote:

Originally Posted by oneandoneis2 (Post 3254986)
You need TWO backslashes: C:\\Documents etc.

Backslash is a special character, it's so you can do things like :%s/Indent/\tIndent and it'll insert a tab in front of the word Indent..

Didn't think it was a special character issue since I was having a similar problem with a different program (in Linux). I used a double backslash to get a backslash character, but I still had the problem.

oneandoneis2 08-21-2008 12:13 PM

Not sure why you still had the issue:

:%s/C:\\Documents and Settings\\Berticus/D:\\Backup\\Berticus Files

works for me. But it's good to know you solved it, whatever way


All times are GMT -5. The time now is 09:50 AM.