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

These functions can help you search for text.

The pw function prints a word on the current line and makes it the remembered search string so that you can search for it without typing it. The function argument should be the number of the word on the line.

The sl function makes the current line the remembered search string so that you can search for the whole line without typing it.

# Print a word on the current line and make it the remembered search string.
# usage: <pw [number of word on line]
function+pw {
db0
H-
sw+
e/temporary buffer for function pw to use
if(*) {
eret
ebvar-
!echo temporary buffer already exists
} else {
etmp
f temporary buffer for function pw to use
M0
.w/temporary buffer for function pw to use@.
e/temporary buffer for function pw to use
ebre+
s/\w+/\n&\n/f~0
,--d
+,d
p
s/.*/.g\/\\b&\\b\/X/f
bw
eret
<*/temporary buffer for function pw to use
q/temporary buffer for function pw to use
}
}

# Make the current line the remembered search string.
# usage: <sl
function+sl {
db0
H-
sw+
e/temporary buffer for function sl to use
if(*) {
eret
ebvar-
!echo temporary buffer already exists
} else {
etmp
f temporary buffer for function sl to use
M0
.w/temporary buffer for function sl to use@.
e/temporary buffer for function sl to use
ebre+
s/[$*+./?[\\^{}]/\\&/gf
if(?) {
}
s/.*/.g\/^&$\/X/
bw
eret
<*/temporary buffer for function sl to use
q/temporary buffer for function sl to use
}
}