In particular when programming, it's handy to post error messages in Firefox' search box, to see what Google has to say on the matter :) On linux and particularly X11, it's even more handy since you only have to select some text to put in the X buffer, to later paste it with the middle button.

Unfortunately, before pasting in the search box, you need to clear it. So basically I have to Ctrl+K Del middle click to paste my text in the search box. Not very handy anymore. Is there a better way?

  • 1
    I know this doesn't answer your question, but it comes so darned close and is useful otherwise. If you middle click in Firefox with text in your "primary selection", it tries to load it as a URL. If it fails to load it as a url, it will do the autosearch thing that's enabled with "keyword.enabled" and "keyword.URL". Sadly, if what you paste contains a space, it says "The URL is not valid and cannot be loaded". – wfaulk Sep 30 '09 at 13:46
  • 1
    @wfaulk indeed, close. unfortunately error messages without spaces are rare. – quack quixote Oct 4 '09 at 21:50

The problem is subtle. You want a way to clear the contents of a text field without selecting the contents first, because selecting them will clobber your selection buffer's contents. In my opinion, this is a design flaw in whatever UI toolkits are used on Linux. Only manually selected text should be copied to the X primary selection, not text that is selected incidentally as a result of a non-text-selecting operation (e.g. clicking in a text field). But anyway, how about a couple of workarounds?

If you don't mind adding extra toolbar buttons, you can try the pastego extension: But I'm not sure it works with the X selection.

Another option is to install one of the many extensions that add clear buttons to the location/search bars, such as Clear Fields, DiggiDig, ClearURLButton, or xclear. Then, you just hit the clear button, and the text field is empty, ready for you to middle-click your own text into it.

Lastly, you can try clickngo, which does more or less exactly what you want, and seems to work in FF 3.5, despite the lack of a recent version bump.

Edit: I just remembered a command-line solution to this problem: surfraw. Here's the beginning of the package description:

Surfraw provides a fast unix command line interface to a variety of popular WWW search engines and other artifacts of power. It reclaims google, altavista, dejanews, freshmeat, research index, slashdot and many others from the false-prophet, pox-infested heathen lands of html-forms, placing these wonders where they belong, deep in unix heartland, as god loving extensions to the shell.

Basically, it lets to do google (and other) searches from the command line.

  • 1
    I'm glad I found this question, because answering it prompted me to go and find clickngo, which I like a lot. – Ryan Thompson Oct 4 '09 at 5:37
  • nice explanation of the underlying problem. the selection buffer is an old X feature, it predates the Web by a good bit, and unfortunately never made it into MS Windows. if it had, GUI input methods would have accommodated it better. – quack quixote Oct 4 '09 at 5:58
  • i assume clickngo is a firefox addon? can you add a link? – quack quixote Oct 4 '09 at 6:10
  • Searching any of the extension names on addons.mozilla.org should find the extension. – Ryan Thompson Oct 4 '09 at 20:56
  • just prodding you to prettify your answer. >poke<! i'd edit and add the link myself if i had the power. – quack quixote Oct 4 '09 at 22:10

I believe this is a workaround for your problem.

Use this command as a new keyboard shortcut:

sh -c 'xsel | tr " " "+" | xargs -I %s xdg-open "http://www.google.com/search?q=%s"'

This was tested on Ubuntu 9.04 after installing the xsel package. The keyboard shortcut was added to the Gnome environment via the tool Keyboard Shortcuts found in the menu System->Preferences. It should be easy to adapt this to another desktop environment.

If your system does not provide the command xdg-open, you may replace it with the command firefox (xdg-open chooses the default browser to open urls).

Once done, you just have to select the text you want searched on google and press your chosen keyboard shortcut.

  • +1 nice find. can you tell me how to change it so the search string is quoted? ie instead of searching for libfoo error 23 i execute a search for "libfoo error 23"? – quack quixote Oct 5 '09 at 0:32
  • 1
    @~quack, just add some escaped double quotes: sh -c 'xsel | tr " " "+" | xargs -I %s xdg-open "google.com/search?q=\"%s\""' – avelldiroll Oct 5 '09 at 2:47
  • @avelldiroll thx! – quack quixote Oct 5 '09 at 21:26

I'm not entirely sure I understand the question, but here's a favorite set-up of mine:

  1. Give all the items in the search bar keywords (Google is 'g', CPAN is 'cpan', Wikipedia is 'wiki', Weather.com is 'w', and so on)
  2. Remove the search bar from the GUI (it just wastes space and after 1 you no longer need it). You can do this via View -> Toolbars -> Customize. Drag the search bar off the browser onto the customizer to remove it.
  3. When you want to search, CTRL + L selects the whole address bar. Type 'g' and then insert the text you've copied. Hit enter and you just started a Google search. (If it's an error message, you probably want to try the search wrapped in quotes first, now that I think of it.)
  • i don't like that idea; makes it harder for others (family members, friends, etc) to borrow my browser for a few minutes. unless i put up a stickynote that says "press G for Google" and the like. – quack quixote Oct 4 '09 at 6:06
  • 1
    @Quack: and that's a reasonable concern. I have been told by people that in many ways, my computers are "odd" and counterintuitive. My primary concern is to make them comfortable and intuitive for me. – Telemachus Oct 4 '09 at 11:35
  • @telemachus: yup. and that's totally your call. it's a good idea, clever, even elegant. just not something i'd use. rereading it now, my comment starts ruder than i meant -- sorry about that! – quack quixote Oct 4 '09 at 22:07

I understand the question (and I really like Ryan Thompson's explanation of the problem, though it's more an anachronism than a design flaw).

Perhaps the simplest, no-install way is to make a change in your habits. Here's a couple of ideas:

  1. (easiest) When you want to execute a new search, make Firefox active, press Ctrl-N to open a new window. Presto -- a fresh, empty search box in which your middle-click will always work.

  2. (harder) Train yourself to clear the searchbox after any use.


Check out IronAHK. Then you can map the middle mouse button to send Ctrl + k + Del in one shot only if Firefox is the active window.

#IfWinActive,,Mozilla Firefox
MButton::Send {Ctrl Down}{k Down}{Ctrl Up}{k Up}{Delete}

While this isn't a single key combination, using SHIFT+INS to paste, you can do several in quick succession. So your key combos would be

  • Highlight or cut something in your IDE or Terminal
  • ALT+TAB to Firefox
  • CTRL+K in firefox (will auto select everything, no need to delete)
  • SHIFT+INSERT to paste (w/o using mouse)

also, I would recommend setting up Firefox to open a new tab on every search, so you don't lose everything you were referencing on in your browser:

  • go to about:config
  • search for 'openintab'
  • set browser.search.openintab to true
  • 2
    Shift-Ins does NOT paste stuff only highlighted with the mouse. You would have to Ctrl-Ins to Copy it first. Middle-click is not the same as paste. – CarlF Oct 4 '09 at 5:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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