Skip to content

Commit 43cdf8d

Browse files
author
Romain Lafourcade
committed
Andy Montañez
1 parent 0f978b5 commit 43cdf8d

File tree

4 files changed

+257
-1
lines changed

4 files changed

+257
-1
lines changed

‎README.md

+79-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,80 @@
11
# vim-devdocs
2-
Look up keyword on https://devdocs.io from Vim
2+
3+
Look up keywords on [https://devdocs.io](https://devdocs.io) from Vim.
4+
5+
## Introduction
6+
7+
Vim-devdocs is a very small and trivial plugin with a laser-focused purpose: making it possible to look up keywords on [https://devdocs.io](https://devdocs.io)from Vim.
8+
9+
It does so by providing a single command, `:DD`, that will figure out the current filetype and point your default browser to the web app with the correct query.
10+
11+
Even better, `:DD` can be used under the hood by the built-in `K` for maximum street credibility.
12+
13+
Vim-devdocs started its life in my config as an experimental snippet circa 2016, then became a clean and reusable Gist in mid-2017, which I decided to weaponize one year later. If you think a plugin should not be needed for such a trivial feature be reassured that I totally share that view. If you feel remix-y, [the original (but regularly updated) Gist](https://gist..com/romainl/8d3b73428b4366f75a19be2dad2f0987) is still up in all its 12LOC glory.
14+
15+
NOTE: vim-devdocs is not affiliated in any way with [https://devdocs.io](https://devdocs.io) so any request pertaining to that site should be directed to its operators.
16+
17+
## Installation
18+
19+
Use your favorite plugin manager or dump the files below in their standard location:
20+
21+
on Unix-like systems…
22+
23+
~/.vim/autoload/devdocs.vim
24+
~/.vim/doc/devdocs.txt
25+
~/.vim/plugin/devdocs.vim
26+
27+
on Windows…
28+
29+
%userprofile%\vimfiles\autoload\devdocs.vim
30+
%userprofile%\vimfiles\doc\devdocs.txt
31+
%userprofile%\vimfiles\plugin\devdocs.vim
32+
33+
If you go with the manual method, don't forget to execute the following command to make the documentation globally available:
34+
35+
on Unix-like systems…
36+
37+
:helptags ~/.vim/doc
38+
39+
on Windows…
40+
41+
:helptags %userprofile%\vimfiles\doc
42+
43+
## Configuration
44+
45+
Add the line below to your vimrc if you want to disable automatic filetype scoping:
46+
47+
let g:devdocs_enable_scoping = 0
48+
49+
## Usage
50+
51+
Use `:DD` without argument to look up the word under the cursor, scoped with the current filetype:
52+
53+
:DD
54+
55+
Use `:DD [keyword]` to look up the given keyword, scoped with the current filetype:
56+
57+
:DD Map
58+
59+
Use `:DD [filetype] [keyword]` to do the scoping yourself:
60+
61+
:DD scss @mixin
62+
63+
Add a `<bang>` to prevent automatic filetype scoping:
64+
65+
:DD!
66+
:DD! Map
67+
68+
unless you absolutely insist:
69+
70+
:DD! scss @mixin
71+
72+
Vim comes with the built-in and often overlooked `K`, a normal mode command that looks up the keyword under the cursor with the external command or Ex command set via the `'keywordprg'` option. `:DD` being a pretty basic Ex command it is easy to use it for `K`.
73+
74+
If you want `K` to ALWAYS use `:DD`, put this line in your vimrc:
75+
76+
set keywordprg=:DD
77+
78+
If you want `K` to use `:DD` ONLY for certain filetypes, put this line in the appropriate `after/ftplugin/<filetype>.vim`:
79+
80+
setlocal keywordprg=:DD

‎autoload/devdocs.vim

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function! devdocs#Get_env() abort
2+
if has('win64') || has('win32') || has('win16')
3+
return 'WINDOWS'
4+
else
5+
let l:uname = toupper(substitute(system('uname'), '\n', '', ''))
6+
7+
return l:uname =~ '\(MINGW\|CYGWIN\)' ? 'WINDOWS' : l:uname
8+
endif
9+
endfunction

‎doc/devdocs.txt

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
*devdocs.txt*
2+
3+
4+
VIM-DEVDOCS DOCUMENTATION by Romain Lafourcade
5+
6+
7+
*devdocs*
8+
*vim-devdocs*
9+
Help on using vim-devdocs
10+
11+
1. Introduction ............................. |devdocs-intro|
12+
2. Installation ............................. |devdocs-installation|
13+
3. Configuration ............................ |devdocs-configuration|
14+
4. Usage .................................... |devdocs-usage|
15+
5. TODO ..................................... |devdocs-todo|
16+
6. DONE ..................................... |devdocs-done|
17+
7. Releases ................................. |devdocs-releases|
18+
19+
==============================================================================
20+
1. Introduction *devdocs-intro*
21+
22+
Vim-devdocs is a very small and trivial plugin with a laser-focused purpose:
23+
making it possible to look up keywords on `https://devdocs.io` from Vim.
24+
25+
It does so by providing a single command, |:DD|, that will figure out the
26+
current filetype and point your default browser to the web app with the
27+
correct query.
28+
29+
Even better, |:DD| can be used under the hood by the built-in |K| for maximum
30+
Vimmy-ness. See |devdocs-K| below.
31+
32+
Vim-devdocs started its life in my config as an experimental snippet circa
33+
2016, then became a clean and reusable Gist in mid-2017, which I decided to
34+
weaponize one year later. If you think a plugin should not be needed for such
35+
a trivial feature be reassured that I totally share that view. If you feel
36+
remix-y, the original (but regularly updated) Gist is still up in all its
37+
12LOC glory:
38+
39+
`https://gist..com/romainl/8d3b73428b4366f75a19be2dad2f0987`
40+
41+
NOTE: vim-devdocs is not affiliated in any way with `devdocs.io` so any
42+
request pertaining to that site should be directed to its operators.
43+
44+
==============================================================================
45+
2. Installation *devdocs-installation*
46+
47+
Use your favorite plugin manager or dump the files below in their standard
48+
location:
49+
50+
on Unix-like systems... >
51+
52+
~/.vim/autoload/devdocs.vim
53+
~/.vim/doc/devdocs.txt
54+
~/.vim/plugin/devdocs.vim
55+
<
56+
on Windows... >
57+
58+
%userprofile%\vimfiles\autoload\devdocs.vim
59+
%userprofile%\vimfiles\doc\devdocs.txt
60+
%userprofile%\vimfiles\plugin\devdocs.vim
61+
<
62+
If you go with the manual method, don't forget to execute the following
63+
command to make the documentation globally available:
64+
65+
on Unix-like systems... >
66+
67+
:helptags ~/.vim/doc
68+
<
69+
on Windows... >
70+
71+
:helptags %userprofile%\vimfiles\doc
72+
<
73+
==============================================================================
74+
3. Configuration *devdocs-configuration*
75+
76+
Option(s):
77+
78+
g:devdocs_enable_scoping .................... |'g:devdocs_enable_scoping'|
79+
80+
------------------------------------------------------------------------------
81+
*'g:devdocs_enable_scoping'*
82+
Value: numeric ~
83+
Default: 1 ~
84+
85+
Enable or disable automatic scoping.
86+
87+
Add the line below to your vimrc to disable this feature: >
88+
89+
let g:devdocs_enable_scoping = 0
90+
<
91+
==============================================================================
92+
4. Usage *devdocs-usage*
93+
94+
*:DD*
95+
*devdocs-DD*
96+
:DD[!] [filetype] [keyword]
97+
98+
Without [!], [filetype], or [keyword], look up the keyword under the
99+
cursor, scoped with the current filetype.
100+
For example, with the cursor on `FuncLit` in a Go buffer: >
101+
102+
:DD
103+
<
104+
would resolve to `https://devdocs.io/go/go/ast/index#FuncLit` in your
105+
default browser. With [!], don't do any automatic scoping.
106+
107+
Without [!] or [filetype], look up [keyword], scoped with the current
108+
filetype.
109+
For example, if the active buffer is a JavaScript buffer: >
110+
111+
:DD Map
112+
<
113+
would resolve to `https://devdocs.io/javascript/global_objects/map` in
114+
your default browser. With [!], don't do any automatic scoping.
115+
116+
With or without [!], look up [keyword], scoped with [filetype].
117+
For example, no matter what's the filetype of the current buffer: >
118+
119+
:DD scss @mixin
120+
<
121+
would resolve to `https://devdocs.io/sass/index#mixin` in your default
122+
browser.
123+
124+
------------------------------------------------------------------------------
125+
*devdocs-K*
126+
*devdocs-keywordprg*
127+
128+
Vim comes with the built-in and often overlooked |K|, a normal mode command
129+
that looks up the keyword under the cursor with the external command or Ex
130+
command set via the |'keywordprg'| option. |:DD| being a pretty basic Ex
131+
command it is easy to use it for |K|.
132+
133+
If you want |K| to ALWAYS use |:DD|, put this line in your vimrc: >
134+
135+
set keywordprg=:DD
136+
<
137+
If you want |K| to use |:DD| ONLY for certain filetypes, put this line in the
138+
appropriate `after/ftplugin/<filetype>.vim`: >
139+
140+
setlocal keywordprg=:DD
141+
<
142+
==============================================================================
143+
5. Todo *devdocs-todo*
144+
145+
- Sit back and relax.
146+
147+
==============================================================================
148+
6. Done *devdocs-done*
149+
150+
- All done.
151+
152+
==============================================================================
153+
7. Releases *devdocs-releases*
154+
155+
1.0.0: Andy Montañez ..................................... 09 Jun 2018
156+
157+
First version.
158+
159+
vim:tw=78:ts=8:ft=help:norl:

‎plugin/devdocs.vim

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
" What command to use on what system
2+
let s:cmds = {"DARWIN": "open", "LINUX": "xdg-open", "WINDOWS": "explorer"}
3+
4+
" Build the URL stub
5+
let s:stub = s:cmds[devdocs#Get_env()] . " 'https://devdocs.io/?q="
6+
7+
" Build the command
8+
command! -bang -nargs=* DD silent! call system(len(split(<q-args>, ' ')) == 0 ?
9+
\ s:stub . (expand('<bang>') == "!" || get(g:, 'devdocs_enable_scoping', 0) == 1 ? '' : &filetype) . ' ' . expand('<cword>') . "'" : len(split(<q-args>, ' ')) == 1 ?
10+
\ s:stub . (expand('<bang>') == "!" || get(g:, 'devdocs_enable_scoping', 0) == 1 ? '' : &filetype) . ' ' . <q-args> . "'" : s:stub . <q-args> . "'")

0 commit comments

Comments
 (0)