Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim does not find and replace simple phrase that is clearly present

I have a simple vim problem that Google hasn't managed to help me with. Any thoughts are appreciated.

I do the following search and replace:

:s/numnodes/numnodes1/g 

On a file containing the following text:

numprocs=0   numnodes=0 

I get

E486: Pattern not found 

The position of the green square which indicates where I'd start typing is clearly above the pattern. I tried searching for other short phrases not involving regex, which are also present, which also fail. A simple /numnodes highlights matches as expected. Does anyone have any idea what might be the matter with vim?

like image 719
Mark C. Avatar asked Mar 13 '11 12:03

Mark C.


People also ask

How do you replace a phrase in Vim?

Basic Find and Replace In Vim, you can find and replace text using the :substitute ( :s ) command. To run commands in Vim, you must be in normal mode, the default mode when starting the editor. To go back to normal mode from any other mode, just press the 'Esc' key.

How do we search for old and replace it with new vim?

To search in the current file, you just need to type / in normal mode. Then, you need to type your search pattern, press enter , and the result becomes highlighted in your file. To go backward and forward through the results, you can type n and N (for n ext) respectively. Using / will search forward in the file.

What command is used to replace a string with another string in vi editor?

After running a search once, you can repeat it by using n in command mode, or N to reverse direction. When you want to search for a string of text and replace it with another string of text, you can use the syntax :[range]s/search/replace/.

How do I find special characters in Vim?

^ * $ \ ? ) have special significance to the search process and must be “escaped” when they are used in a search. To escape a special character, precede it with a backslash ( \ ). For example, to search for the string “anything?” type /anything\? and press Return.


2 Answers

Try :%s/searchphrase/replacephase/g

Without the % symbol Vim only matches and replaces on the current line.

like image 79
mmccomb Avatar answered Sep 20 '22 22:09

mmccomb


try using this:

:%s/numnodes/numnodes1/g 
like image 34
Uku Loskit Avatar answered Sep 24 '22 22:09

Uku Loskit