-
Notifications
You must be signed in to change notification settings - Fork 31
Work with multiple sessions
These functions can help when working with multiple sessions or with multiple buffers. As you open new buffers in a session, you build a stack of buffers. Each session has its own stack of buffers.
These functions apply the same command to multiple sessions.
# Apply command to all sessions.
# usage: <all [<command>]
function+all {
db0
while(*) {
e-
}
while(*) {
~0
e+
}
}
# Apply command to the current and next sessions.
# usage: <allnext [<command>]
function+allnext {
db0
while(*) {
~0
e+
}
}
# Apply command to the current and previous sessions.
# usage: <allprev [<command>]
function+allprev {
db0
while(*) {
~0
e-
}
}
These functions go to the first or last session.
# Go to the first session.
# usage: <first
function+first {
db0
while(*) {
e-
}
ft
if(?) {
f
}
}
# Go to the last session.
# usage: <last
function+last {
db0
while(*) {
e+
}
ft
if(?) {
f
}
}
These functions search for a regular expression in the buffer in the current session (without wrapping) and search the buffer in the next or previous session when they fail to find a match in the buffer in the current session.
The function next
searches forward.
The function prev
searches backward.
Use the ci
command to control whether the searches are case sensitive.
# Find the next match across sessions.
# usage: <next <regular expression>
# This function uses the label z.
function+next {
db0
H-
sg+
sw-
kz
/~0/f
while(?) {
'zX
if(*) {
}
e+
sw+
kz
$X
if(*) {
}
/~0/f
}
}
# Find the previous match across sessions.
# usage: <prev <regular expression>
# This function uses the label z.
function+prev {
db0
H-
sg+
sw-
kz
?~0?f
while(?) {
'zX
if(*) {
}
e-
sw+
kz
1X
if(*) {
}
?~0?f
}
}
This function prints the number of sessions.
# Print the number of sessions.
# usage: sessions
function+sessions {
db0
var lower=1
e-
while(*) {
var lower=$(lower+1)
e-
}
var total=1
e+
while(*) {
var total=$(total+1)
e+
}
p $(total)
[ $(total) != $(lower) ]
while(*) {
var lower=$(lower+1)
e-
[ $(total) != $(lower) ]
}
var lower=clear
var total=clear
}
This function quits sessions until it reaches a session that contains a buffer with unwritten changes.
If a buffer has unwritten changes, you can use the w
command to write the changes to a file.
Use the function again to quit the current session and continue quitting sessions.
# Quit sessions.
# usage: <q
function+q {
db0
while(*) {
q
}
ft
if(?) {
f
}
bw
}
These functions go to the top or bottom buffer.
# Go to the top buffer.
# usage: <top
function+top {
db0
while(*) {
up
}
ft
if(?) {
f
}
}
# Go to the bottom buffer.
# usage: <bot
function+bot {
db0
while(*) {
down
}
ft
if(?) {
f
}
}
These functions search for a regular expression in the current buffer (without wrapping) and search the history of buffers in the current session when they fail to find a match in the current buffer.
The function sdown
searches down.
The function sup
searches up.
Use the ci
command to control whether the searches are case sensitive.
# Find the next match across buffers.
# usage: <sdown <regular expression>
# This function uses the label z.
function+sdown {
db0
H-
sg+
sw-
kz
/~0/f
while(?) {
'zX
if(*) {
}
down
sw+
kz
$X
if(*) {
}
/~0/f
}
}
# Find the previous match across buffers.
# usage: <sup <regular expression>
# This function uses the label z.
function+sup {
db0
H-
sg+
sw-
kz
?~0?f
while(?) {
'zX
if(*) {
}
up
sw+
kz
1X
if(*) {
}
?~0?f
}
}
This function moves each buffer in the stack in the current session to its own session.
# Unstack the buffers.
# usage: <unstack
function+unstack {
db0
while(*) {
M0
}
}