Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search a string with spaces and special characters in vi editor

I edit in the vi editor. I want to search in the text for a specific phrase, e.g "Dec 1 15:13:00". I have tried this search string, but it's not working:

/Dec\ 1\ 15

How do I search for this string properly? Note that there may be more than one space between the parts.

like image 576
user5628973 Avatar asked Dec 02 '15 06:12

user5628973


People also ask

Which command searches the string in a file opened in vi editor?

Which command searches the string in file opened in vi editor? a) / or ? Explanation: The command '/' searches downward in the file and command '? ' searches upward in the file.

How do I search for a specific line in vi editor?

If you're already in vi, you can use the goto command. To do this, press Esc , type the line number, and then press Shift-g . If you press Esc and then Shift-g without specifying a line number, it will take you to the last line in the file.

How do I search for a string in Vim?

Perform a basic search in Vim If you are in insert mode, simply press the 'ESC' key. To perform a basic search of the string or text that you want, move to the beginning of the file and simply press the forward-slash ( / ) key. Then type the search string and press ENTER on the keyboard to start searching.


1 Answers

Numbers and spaces are not special characters so

 /Dec 1 15  

is enough.

Generally speaking special characters are escaped with a \. For example, if you search for Dec., you should type /Dec\.

If you are using Vim, you might also want to check

:help pattern.txt 

And specifically the magic chapter.

If you want to know if magic is set, type :set magic?

The magic option can change the behavior of pattern matching.

like image 87
Xavier T. Avatar answered Oct 15 '22 18:10

Xavier T.