Minimal vim plugin integration for DuckDuckGo cli
ddgr
ddgrcli
-
With vim-plug:
Plug 'https://github.com/pbnj/vim-ddgr'
Query DuckDuckGo:
:DDGR <query>This is equivalent to running the following shell command:
ddgr --expand --num 5 <query>The results are displayed in Vim's integrated terminal, where all ddgr
omniprompt keys work as expected:
n,p,fto fetch the next, prev or first set of search results<index>to open the result corresponding to index in$BROWSERo [index|range|a ...]to open space-separated result indices, ranges or allO [index|range|a ...]like key 'o', but try to open in a GUI browserd keywordsnew DDG search for 'keywords' with original options; should be used to search omniprompt keys and indicesxto toggle url expansionc <index>to copy url to clipboardq,^D, double Enter to exit ddgr?to show omniprompt help*other inputs are considered as new search keywords
See https://github.com/jarun/ddgr for more details.
Query DuckDuckGo with Bangs:
:DDGR! <bang> <query>Tab completion is supported for Bangs:
:DDGR! <tab> <query>Completions come from
DDGRBangCompletion
function.
This is equivalent to running the following shell command:
ddgr --noprompt --gui-browser \!<bang> <query>This will open the search results in your $BROWSER or your default GUI browser.
Vim uses keywordprg to query external programs when K
(shift + k) is pressed on a word in Vim. On many systems,
keywordprg is to man by default.
You may alternatively set keywordprg to :DDGR globally, by adding set keywordprg=:DDGR to your vimrc, to query DuckDuckGo when K is
pressed on a word.
You may further customize keywordprg for specific filetypes, like:
augroup ddgr
autocmd!
autocmd FileType python setlocal keywordprg=:DDGR!\ python
autocmd FileType go setlocal keywordprg=:DDGR!\ devdocs\ go
augroup ENDThis means:
- When K is pressed on a word in a Python buffer, Vim will run
:DDGR! python <word> - When K is pressed on a word in a Go buffer, Vim will run
:DDGR! devdocs go <word>
Note: This plugin is not required for keywordprg integration. You can
just as easily call :terminal ddgr, like:
augroup ddgr
autocmd!
autocmd FileType python setlocal keywordprg=:terminal\ ++close\ ddgr\ --noprompt\ --gui-browser\ !python
autocmd FileType go setlocal keywordprg=:terminal\ ++close\ ddgr\ --noprompt\ --gui-browser\ !devdocs\ go
augroup END