I've the following example:

vim -E http://example.com/

where I'd like to search for <head> tag.

It seems that search only works when the lines are separated, but when the lines are joined together (%j) then it doesn't work and it says:

Search hit BOTTOM, continuing at TOP

What I'm doing is simply:


The above search works when lines are separated, but not when everything is in one line (just run %j before doing search).

Any idea why or how to search properly for pattern in Ex mode?

I'm expecting after search that the cursor would be placed under the found pattern (similar as in visual mode), so I'm able to perform further changes (for example removing inner tag content by: norm vitd), but it doesn't work when the cursor is not placed on the tag it-self. In other words it seems to work only when the tag is at the beginning of the line, but not when it's in the middle.

  • 1
    ex mode is really only intended to work with lines. The whole concept of "line-wise" vs. "character-wise" was entirely new in vi; before that (in ex) everything was line-wise.
    – Wildcard
    Commented Mar 17, 2016 at 10:24

2 Answers 2


In vim we can read (:help :range):

/{pattern}[/] - the next line where {pattern} matches

That means if there is no next line - no match can be found, because there is only one current line (all lines together).

So to search starting from the first/current line, we need to use 0;/foo.

0;/that - the first line containing "that", also matches in the first line.

However specifying ; makes that the cursor isn't moved, so as workaround, you can manually jump to the next found phrase by: norm n.

$ vim http://example.com/

doesn't download anything so your buffer is empty and the search reaches the end of the buffer without finding anything.

On the other hand,

$ vim http://example.com/index.html

actually downloads a file and populates the buffer, which allows you to search for <head>:


find the first line containing that pattern, make it the current line and print it.

Ex mode

There's nothing complicated, here.

  • In my case (on OS X) vim -E http://example.com/ works as expected (it's populated) and /<head> also works (as you've shown), but the main problem is that it doesn't work when everything is in one line. Just run: :%j before doing search and you'll see.
    – kenorb
    Commented May 14, 2015 at 19:28
  • 1
    I forgot the trailing slash. Ex is line-based: if everything is on one single line that mode is near useless and there is no "cursor" to place on <head> anyway.
    – romainl
    Commented May 14, 2015 at 19:39
  • It's not useless, as I'm require this for my script which is to find the tag and remove the content of the inner tag (e.g. /<head and norm vitd) from the file, but it's another story. So finding pattern and placing the cursor on the tag is the key, but unfortunately my html code for parsing doesn't have much new lines, that's why it's failing.
    – kenorb
    Commented May 14, 2015 at 19:44
  • You actually can place the cursor on <head> in Ex mode, as I've shown in my other answer. You can see cursor moving when going back to visual mode when executing motion movements, so its position changes (by jumping to the next match: norm n).
    – kenorb
    Commented May 14, 2015 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.