-
Notifications
You must be signed in to change notification settings - Fork 31
Edit text
David-Apps edited this page Jun 3, 2023
·
4 revisions
You can use the a
command to keep appending lines after the current line until you type a line consisting of just a period (".").
You can use the c
command to keep typing lines to replace the current line until you type a line consisting of just a period (".").
You can use the i
command to keep inserting lines before the current line until you type a line consisting of just a period (".").
Sometimes you just want to append, type, or insert a single line.
You can use the a
, c
, and i
functions to append or insert the text that you type after the function name.
The functions add text until you type a line that does not end with a backslash ("").
# Append text after the current line.
# usage: <a <text>
# End the line of text with a backslash ("\") to add another line.
function+a {
db0
a
~0
.
s/\\$//f
while(*) {
r !IFS=""; read -r line; echo "$line"
s/\\$//f
}
}
# change (replace) the text of the current line.
# usage: <c <text>
# End the line of text with a backslash ("\") to add another line.
function+c {
db0
c
~0
.
s/\\$//f
while(*) {
r !IFS=""; read -r line; echo "$line"
s/\\$//f
}
}
# Insert text before the current line.
# usage: <i <text>
# End the line of text with a backslash ("\") to add another line.
function+i {
db0
i
~0
.
s/\\$//f
while(*) {
r !IFS=""; read -r line; echo "$line"
s/\\$//f
}
}
You can use this simple function to edit the text of the current line with Readline.
# Edit the current line with Readline.
# usage: <el
function+el {
db0
H-
ebvar+
r !bash -c 'IFS=""; read -er -i '. line; echo $line'
-X
if(*) {
d
}
}