Is there a way to yank the selected text into the search field in Chrome?

1

On Safari this can be done with Cmd+E, and it might even work on Chrome on OSX as well, but when on Windows I browse with Chrome. I do not want to type out what I want to search every time.

By search i mean search on the page, not search the internet.

If there is no built in key binding, then I hope someone can suggest a plugin or Tampermonkey style script to do it (I know that is definitely going to be possible).

Steven Lu

Posted 2013-08-05T16:20:14.567

Reputation: 2 818

In Visual Studio, pressing Ctrl+F searches for the text that you've selected. I'd love to see this functionality in Chrome, perhaps you should make a feature request.

– Robert Rouhani – 2013-08-05T20:37:16.663

Answers

1

Ask and ye shall receive.

When I saw your question, I too figured it would be simple, even trivial, to throw something together to do this. Unfortunately it turned out to be much harder to do because of numerous obstacles and limitations (you can see a list of problems encountered and references in the script).

After much research, experimentation, and testing, I managed to create a Chrome userscript that can do what you want. One limitation is that it does not use the browser’s actual search/find control because the devs have not provided any programmatic access to it. However, the DOM does provide a way to search the page for specified text and jump around to them, so it does work more or less.

I enhanced it a bit so that it doesn’t trigger incorrectly:

  • Hold Ctrl or Command⌘ while selecting text (by dragging or double-clicking) to jump to the next occurrence of the selected text.
  • Hold ⇧Shift+Ctrl or ⇧Shift+Command⌘ while selecting text to jump to the previous occurrence of the selected text.

The Find Selected userscript.

Synetech

Posted 2013-08-05T16:20:14.567

Reputation: 63 242

Fantastic!! Any chance you can provide functionality to search across tabs? That would be ordinarily for another question but this seems like a prime opportunity. (It would surely be a pretty heavyweight task but I have been known to keep 100+ tabs open and it would be much appreciated for users like me) – Steven Lu – 2013-08-07T19:48:23.763

Unfortunately that is indeed a big ask. There are a few extensions that let you search across tabs, but there’s no way to do a cross-tab search with the native search control, so they have to hack it by accessing the tabs, extracting the contents of the pages, performing a string-search on the contents, building a list of matches, then displaying them in a custom results page. This cannot be done with a userscript; it has to be a full Chrome extension. I don’t generally only do scripts, not extensions, so if you want to do a cross-tab search by selecting text, someone else would have to do it. – Synetech – 2013-08-08T00:11:25.830

You can try the existing extensions to see if their cross-tab search is sufficient: Search Plus, TabJuggler, Search in Tabs. You may also find Type-ahead-find useful.

– Synetech – 2013-08-08T00:14:11.403

Ah. I see. Thanks for explaining! Btw unfortunately I wasnt able to get your userscript working when I tried it. – Steven Lu – 2013-08-08T00:37:33.027

1

Well, you can always copy it to the clipboard and paste it in the searchbox like so:

Ctrl+C, Ctrl+F, Ctrl+V

Der Hochstapler

Posted 2013-08-05T16:20:14.567

Reputation: 77 228

This does work, but is not ideal because it takes 5 steps (must select in the beginning, which is at least a mouse double-click, and hit Enter to actually search at the end) and it's just too long a sequence. On OSX for instance it's 3 steps, not 5. Also the step of finding the next one is 1 step (Cmd+G) instead of 2 (Ctrl+F, Enter) – Steven Lu – 2013-08-05T20:25:59.660

@StevenLu: Instead of hitting Enter, you could go right to hitting F3 (which is also the key to continue the search). But, yeah, I know what you mean. I wouldn't mind a quicker way of doing this either. – Der Hochstapler – 2013-08-05T21:11:04.593

Ah! right, F3 is usually the counterpart to Cmd+G. It's a good one and I usually forget about it. Well, I'll make do with this, at least c, f, and v are close together. – Steven Lu – 2013-08-05T23:42:41.590

@Oliver, are you “PastaPillows”? :^Þ – Synetech – 2013-08-08T00:06:20.390

@Synetech What or who is that? – Der Hochstapler – 2013-08-08T08:15:28.723

@Oliver, PastaPillows. Wait, I guess not; that’s Brandon Maxwell. Doh.

– Synetech – 2013-08-09T01:08:41.397

@Synetech: Wow :D I actually took the image from http://gunshowcomic.com/731

– Der Hochstapler – 2013-08-09T10:07:42.780

0

Just select the text, then click and drag it into the search bar. You can also right-click on selected text and choose "search for selected text on default search engine".

nhinkle

Posted 2013-08-05T16:20:14.567

Reputation: 35 057

1I need search in page. Not search Google. The drag might help but it's a bit awkward if the search field isn't already present. And if it is, it simply appends rather than replaces what's already in the search field. This all gets in the way of filtering and finding stuff on a page quickly. – Steven Lu – 2013-08-05T17:45:48.840

@StevenLu Ah. It wasn't clear from the question that you meant search on the page. Could you edit your question to clarify that? – nhinkle – 2013-08-05T17:50:06.203