Skip to content

Instantly share code, notes, and snippets.

@adscriven
Forked from romainl/devdocs.md
Last active April 28, 2018 18:37
Show Gist options
  • Save adscriven/4314f0980e1a120152d69ef1c9de602f to your computer and use it in GitHub Desktop.
Save adscriven/4314f0980e1a120152d69ef1c9de602f to your computer and use it in GitHub Desktop.
Look up keyword on http://devdocs.io from Vim

Look up keyword on http://devdocs.io from Vim

Use :DD without argument to look up the word under the cursor, scoped with the current filetype:

:DD

Use :DD keyword to look up the given keyword, scoped with the current filetype:

:DD Map

Use :DD scope keyword to do the scoping yourself:

:DD scss @mixin

Use the :DD command for keyword look up with the built-in K:

setlocal keywordprg=:DD
" * Adjusted to work in Windows 10 (cmd & quoting). I don't know about
" other OSs.
" * fname_case to include MSYS Vim. Otherwise the system() call is
" rather slow.
let s:win_or_msys = !has('fname_case')
function! s:Get_env() abort
if s:win_or_msys
return 'WINDOWS'
else
return toupper(substitute(system('uname'), '\n', '', ''))
endif
endfunction
" What command to use on what system
let s:cmds = {
\ 'DARWIN': 'open',
\ 'LINUX': 'xdg-open',
\ 'WINDOWS': 'explorer'
\ }
" Build the URL stub
let s:stub = s:cmds[s:Get_env()] . ' "https://devdocs.io/?q='
command! -nargs=* DD silent! call system(
\ len(split(<q-args>, ' ')) == 0
\ ? s:stub . &ft . ' ' . expand('<cword>') . '"'
\ : len(split(<q-args>, ' ')) == 1
\ ? s:stub . &ft . ' ' . <q-args> . '"'
\ : s:stub . <q-args> . '"'
\ )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment