Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim how to search for URL

Tags:

vim

How would you search for the following string in vim?

http://my.url.com/a/b/c

I've tried (a la Very No Magic)

:/\Vhttp://my.url.com/a/b/c

But it gives me:

E492 not an editor command: /\Vhttp://my.url.com/a/b/c

You would think there'd be a simple way to search a string literally... I'm not too interested in slash escaping every slash, or writing a complicated search, because I have to rapidly search different URLs in a text file.

like image 253
ktm5124 Avatar asked May 14 '13 22:05

ktm5124


People also ask

How do I open a URL in Vim?

If you have Vim and Netrw, you can open a URL in your browser of choice, right from the editor. Place the cursor on the URL and type gx . This will invoke your file handler; open for OSX.

How do I search in vi mode?

To find a character string, type / followed by the string you want to search for, and then press Return. vi positions the cursor at the next occurrence of the string. For example, to find the string “meta,” type /meta followed by Return. Type n to go to the next occurrence of the string.

How do I search a whole word in Vim?

To search using Vim/vi, for the current word: In normal mode, you can search forward or backward. One can search forward in vim/vi by pressing / and then typing your search pattern/word. To search backward in vi/vim by pressing ? and then typing your search pattern/word.


2 Answers

I'm not sure why you get not an editor command since I don't. The simplest way to search without having to escape slashes is to use ? instead, e.g.

:?http://my.url.com/a/b/c
" or since the : is not necessary
?http://my.url.com/a/b/c

This does search in the other direction, so just keep that in mind

like image 137
Explosion Pills Avatar answered Nov 07 '22 16:11

Explosion Pills


another way to search forward (from the position of your cursor) without escaping is use :s command.

you could do:

:%s@http://my.url.com/a/b/c@@n

then press n to navigate matched text forward, N backwards

If you want to know how many matches in the buffer, use gn instead of n

note that, I said "without escaping", I was talking about the slash, if you want to do search precisely, you have to escape the period. .. since in regex, . means any char.

like image 30
Kent Avatar answered Nov 07 '22 16:11

Kent