Skip to content
/ vim-ddgr Public

Minimal vim plugin integration for DuckDuckGo cli `ddgr`

License

Notifications You must be signed in to change notification settings

pbnj/vim-ddgr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

vim-ddgr

Minimal vim plugin integration for DuckDuckGo cli ddgr

Pre-requisites

Install

  • With vim-plug:

    Plug 'https://github.com/pbnj/vim-ddgr'

Usage

Simple Queries

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, f to fetch the next, prev or first set of search results
  • <index> to open the result corresponding to index in $BROWSER
  • o [index|range|a ...] to open space-separated result indices, ranges or all
  • O [index|range|a ...] like key 'o', but try to open in a GUI browser
  • d keywords new DDG search for 'keywords' with original options; should be used to search omniprompt keys and indices
  • x to toggle url expansion
  • c <index> to copy url to clipboard
  • q, ^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.

Bang Queries

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.

More Integrations with Vim

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 END

This 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

Demo

Screenshare.-.2023-01-04.5_17_42.PM.mp4

About

Minimal vim plugin integration for DuckDuckGo cli `ddgr`

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published