Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ search on selected words. Just select words and type:
:Google "
:Google "foo bar

You may want to quickly go to the first Google result of a search term. Just use `:Googlel` (l stands for *lucky*) :

:Googlel github

*Note:* Google will perform a regular search if search terms are ambiguous.

Configuration
-------------
Expand Down
26 changes: 21 additions & 5 deletions plugin/g.vim
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ if !exists("g:vim_g_query_url")
let g:vim_g_query_url = "http://google.com/search?q="
endif

if !exists("g:vim_g_query_url_lucky")
let g:vim_g_query_url_lucky = "http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&gfns=1&q="
endif

if !exists("g:vim_g_command")
let g:vim_g_command = "Google"
endif
Expand All @@ -48,10 +52,20 @@ if !exists("g:vim_g_f_command")
let g:vim_g_f_command = g:vim_g_command . "f"
endif

execute "command! -nargs=* -range ". g:vim_g_command ." :call s:goo('', <f-args>)"
execute "command! -nargs=* -range ". g:vim_g_f_command ." :call s:goo(&ft, <f-args>)"
if !exists("g:vim_g_l_command")
let g:vim_g_l_command = g:vim_g_command . "l"
endif

fun! s:goo(ft, ...)
if !exists("g:vim_g_f_l_command")
let g:vim_g_f_l_command = g:vim_g_f_command . "l"
endif

execute "command! -nargs=* -range ". g:vim_g_command ." :call s:goo('','', <f-args>)"
execute "command! -nargs=* -range ". g:vim_g_f_command ." :call s:goo(&ft,'', <f-args>)"
execute "command! -nargs=* -range ". g:vim_g_l_command ." :call s:goo('','lucky', <f-args>)"
execute "command! -nargs=* -range ". g:vim_g_f_l_command ." :call s:goo(&ft,'lucky', <f-args>)"

fun! s:goo(ft,lucky, ...)
let sel = getpos('.') == getpos("'<") ? getline("'<")[getpos("'<")[2] - 1:getpos("'>")[2] - 1] : ''

if a:0 == 0
Expand All @@ -71,13 +85,15 @@ fun! s:goo(ft, ...)
let query = substitute(join(words, " "), '^\s*\(.\{-}\)\s*$', '\1', '')
let query = substitute(query, '"', '\\"', 'g')

let query_url = a:lucky == 'lucky' ? g:vim_g_query_url_lucky : g:vim_g_query_url

if has('win32')
" Target command: start "" "<url>"
silent! execute "! " . g:vim_g_open_command . " \"\" \"" . g:vim_g_query_url . query . "\""
silent! execute "! " . g:vim_g_open_command . " \"\" \"" . query_url . query . "\""
else
silent! execute "! goo_query=\"$(" . g:vim_g_perl_command .
\" -MURI::Escape -e 'print uri_escape($ARGV[0]);' \"" . query . "\")\" && " .
\g:vim_g_open_command . ' "' . g:vim_g_query_url . "$goo_query" . '" > /dev/null 2>&1 &'
\g:vim_g_open_command . ' "' . query_url . "$goo_query" . '" > /dev/null 2>&1 &'
endif
redraw!
endfun