Skip to content
David-Apps edited this page Dec 15, 2023 · 16 revisions

These functions make it easier to search Wikipedia. The wp function searches Wikipedia for its arguments. The lwp function searches Wikipedia for the current line. If the search terms match a page title, that page opens. Otherwise, the functions move to the first search result. To move to the next search result, you can use the / command.

# Search Wikipedia.
# usage: <wp <article name or search terms>
function+wp {
db0
H-
js-
b https://en.wikipedia.org/wiki/~0
sw+
/does not have an article with this exact name/fX
if(*) {
/Search/fg
/results/fX
/already covered/fX
if(*) {
/^{/X
.g/^{~0}/fiX
if(*) {
g
# Use X at the end of the next line if you want to suppress this output.
/h1/f
/^From Wikipedia/fX
/^[^(]/f
} else {
p
}
} else {
/results/f
}
} else {
# Use X at the end of the next line if you want to suppress this output.
/h1/f
/^From Wikipedia/fX
/^[^(]/f
}
}

# Search Wikipedia for the current line.
# usage: <lwp [extra search terms]
function+lwp {
db0
H-
sw+
e/temporary buffer for function lwp to use
if(*) {
eret
ebvar-
!echo temporary buffer already exists
} else {
enew
f temporary buffer for function lwp to use
M0
.w/temporary buffer for function lwp to use@.
e/temporary buffer for function lwp to use
s/.*/b https:\/\/en.wikipedia.org\/wiki\/& ~0/f
bw
eret
js-
<*/temporary buffer for function lwp to use
q/temporary buffer for function lwp to use
/does not have an article with this exact name/fX
if(*) {
/Search/fg
/results/fX
/already covered/fX
if(*) {
/^{/
} else {
/results/f
}
} else {
# Use X at the end of the next line if you want to suppress this output.
/h1/f
/^From Wikipedia/fX
/^[^(]/f
}
}
}