hartley.io

coffeescript, backbone, node + related technologies

Search the web from Vim

Seamless web search - lose less focus

Laziness, Impatience…

90% of the time I switch context away from Vim, it’s to load Chrome to search for something. In order to make this as seamless as possible, I’ve added a function to my .vimrc which brings up a prompt where I can enter my search terms, hit enter and it launches Chrome and searches the search engine of my choice with the entered text.

I should note - this is for Chrome on OS X, however, it could be adapted to work on other platforms and with other browsers.

Key mapping for search prompt
1
2
3
4
5
6
7
function! Terms()
  call inputsave()
  let searchterm = input('Search: ')
  call inputrestore()
  return searchterm
endfunction
map © <ESC>:! /usr/bin/open -a "/Applications/Google Chrome.app" 'https://google.com/search?q=<C-R>=Terms()<CR>'<CR><CR>

The above code maps alt + g to bring up the prompt, hitting enter then launches a Google search in Chrome. You needn’t restrict yourself to just searching Google either - for DuckDuckGo you can replace https://google.com/search?q= with https://duckduckgo.com/?q= or for Blekko you can use https://blekko.com/ws/.

You can check out my full .vimrc on GitHub.

Comments