🏃 Google StackOverflow in Vim. Copy-pastes the code directly in your script.
MIT License
Googling Stack Overflow
Thank you Daniel, Brionius, and bytecode77!
GSO now work exclusively in Python 3. Confirmed to work in NeoVim.
(GSO now also prints the answer URL.)
(If you just want to try, there are demo keys at the bottom of this page. They are shared, so play nice.)
Make sure your vim supports python scripting (vim --version | grep +python3
should return something).
If this doesn't work, the vim-nox-py2
package on ubuntu has this (sudo apt-get install vim-nox-py2
),
else, look to SO.
Then, install python dependencies:
pip3 install google-api-python-client Cython py-stackexchange lxml
If there are issues with installing lxml
, it's probably to do with a missing libxml
library.
The lxml
site has some help for this.
Get API keys for Google Custom Search (scroll to API key), and Stack Apps. This is free, don't be intimidated by the forms! Enter whatever in the boxes, and the key generated for you will be compatible with this app. Trust me, it's worth it.
Put these into
environment variables GOOGLE_KEY
and
SE_KEY
, respectively (e.g., export GOOGLE_KEY="......"
).
(Vundle) Add this repo to your .vimrc
file:
Plugin 'MilesCranmer/gso'
Then, just :PluginInstall
in vim.
(optional) Map Ctrl-E to type ":GSO " for you, by putting the following in your .vimrc
:
nnoremap <C-e> :GSO
:GSO [(-l | --language) <language>] [-n | --no-text] [<search>...]
For example, in a file sort.py
, run:
:GSO Do a bubble sort
And watch the python code get dumped below your cursor. GSO will append the language to your query by the file extension, but you can set it explicitly by:
:GSO -l haskell Generate a fibonacci sequence
I have a similar problem and made a hack around it. Your gso should be installed into ~/.vim/gso. Edit the file ~/.vim/gso/plugin/gso.vim, and after each python << EOF
, paste the following lines:
import sys
sys.path.append('....')
Replace the inside of the string with the "site-packages" directory where googleapi-client is installed. Make sure you use python 3 to install the packages, or optionally replace the python3 << EOF
with python << EOF
.
There is a shell utility in tools
. It simply calls the GSO command and dumps the result to the /dev/stdout.
Copy it to /usr/bin/gso
(or anywhere on the PATH
), then call it as you normally would:
➜ gso How to change the url of a git remote
GSO>>>
You can
git remote set-url origin git://new.url.here
(see git help remote) or you can just edit .git/config and change the
URLs there. You're not in any danger of losing history unless you do
something very silly (and if you're worried, just make a copy of your
repo, since your repo is your history.)
<<<GSO
To pull and run (with your Google and Stack apps API keys, or the demo ones at the bottom):
docker run -it -e GOOGLE_KEY=$GOOGLE_KEY -e SE_KEY=$SE_KEY mcranmer/gso
Then, inside vim:
:GSO Flatten a list of lists
And it will dump the highest score answer to below your cursor.
unittests
on the gso
module.man
function.This is the custom search engine that GSO uses: https://cse.google.com/cse/publicurl?cx=003962226882031433174:qk7rs-ca-bi
Currently, it searches the stackoverflow, superuser, tex, and unix forums.
SE: "NExeVkJzlom8ZUagXLcHQA(("
GOOGLE: "AIzaSyAk7sxnY_yHAP2OIdSOrgf9JysO8E_xJRo"