#!/bin/sh -e
# Generated by patch2vi from unified diff
# Available separators: 0003-0010 0013-0014 0016-0037 0110 0115 0121-0122 0126-0132 0136 0176-0205 0207-0217 0224-0341 0343-0377

# Pass any argument to use patch(1) instead of nextvi ex commands
if [ -n "$1" ]; then
    sed '1,/^=== PATCH2VI PATCH ===$/d' "$0" | patch -p1 --merge=diff3
    exit $?
fi

VI=${VI:-vi}
if ! $VI -? 2>&1 | grep -q 'Nextvi'; then
    echo "Error: $VI is not nextvi" >&2
    echo "Set VI environment variable to point to nextvi binary" >&2
    exit 1
fi

SEP="$(printf '\001')"
ESC="$(printf '\002')"
# Command that handles readability line breaks
LB="0?"
# Phase 1 (search/mark): errors disabled by default,
# DBG1=1 enables error reporting, QF1=1 quits on failure
# OK1: with DBG1=1 also report fallback anchor successes
[ "$DBG1" = "1" ] && OK1= || OK1="0?"
[ "$DBG1" = "1" ] && DBG1= || DBG1="0?"
[ "$QF1" = "1" ] && QF1="${ESC}${SEP}vis 2${ESC}${SEP}q!1" || QF1=
# Phase 2 (edits): DBG2=1 disables errors, QF2=1 ignores them
# OK2: with DBG2= also report fallback substitute successes
[ "$DBG2" = "1" ] && OK2="0?" || OK2=
[ "$DBG2" = "1" ] && DBG2="0?" || DBG2=
[ "$QF2" = "1" ] && QF2= || QF2="${ESC}${SEP}vis 2${ESC}${SEP}q!1"
# Enters vi at failing code line in this script
# Designed for state inspection mid execution
[ "$INTR" = "1" ] && INTR="${ESC}${SEP}|sc|${ESC}${SEP}vis 2:fr 0:e $0:83reg %@47:%f> %@112:&Q:b0:|sc! ${ESC}${ESC}${ESC}${SEP}|:vis 3${ESC}${SEP}q1" || INTR=

# Patch: led.c vi.c
# Body too large for EXINIT/argv: stage it in a file
( : > /tmp/p2vi.$$ ) 2>/dev/null && P2VIF=/tmp/p2vi.$$ || P2VIF=./p2vi.$$
trap 'rm -f "$P2VIF"' EXIT
printf '%s\n' "|sc! ${ESC}${SEP}|:vis 3${SEP}fr 98${SEP}b0${SEP}%ya 98${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f> static sbuf \\*suggestsb;
static sbuf \\*acsb;
sbuf \\*led_attsb;

int dstrlen\\(const char \\*s, char delim\\)
\\{${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+2m 1${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f> static sbuf \\*suggestsb;
static sbuf \\*acsb;
sbuf \\*led_attsb;${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+2m 1${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:3:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f> static sbuf \\*suggestsb;.*?
static sbuf \\*acsb;.*?
(sbuf \\*led_attsb;)${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 1${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:3:a7${SEP}${LB}
${SEP}1;3;7??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:3${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ }

static void led_printparts\\(sbuf \\*sb, int pre, int ps,
	char \\*post, int postn, int \\*poff\\)
\\{
	if \\(!xled\\) \\{
		sbufn_null\\(sb\\)${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+3m 2${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	char \\*post, int postn, int \\*poff\\)
\\{
	if \\(!xled\\) \\{
		sbufn_null\\(sb\\)${ESC}${SEP}2??${ESC}${SEP}${LB}
${ESC}${SEP}2??m 2${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:281:a2${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ }

static void led_printparts\\(sbuf \\*sb, int pre, int ps,${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+3m 2${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:281:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP};0${ESC}${SEP}fr${ESC}${SEP}.,\$f+ ^	char \\*post, int postn, int \\*poff\\)\$${ESC}${SEP}4??${ESC}${SEP}${LB}
${ESC}${SEP}4??m 2${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:281:a4${ESC}${ESC}${ESC}${SEP}fr 98${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}fr 98${ESC}${SEP}${LB}
${ESC}${SEP}%f+ \\{
	if \\(!xled\\) \\{
		sbufn_null\\(sb\\)${ESC}${SEP}5??${ESC}${SEP}${LB}
${ESC}${SEP}5??-1m 2${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:281:a5${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ }

..a..c..............t.ar.s\\(sb.f..s.,..n.....,......s,
........o..,..nt....... ........f.
\\{
.....!.l... .
...b..._n...\\(...${ESC}${SEP}6??${ESC}${SEP}${LB}
${ESC}${SEP}6??+3m 2${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:281:a6${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ }.*?
.*?
static void led_printparts\\(sbuf \\*sb, int pre, int ps,.*?
(	char \\*post, int postn, int \\*poff\\))${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 2${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:281:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 	while \\(r > s && uc_kind\\(uc_beg\\(s, r - 1\\)\\) == kind\\)
		r = uc_beg\\(s, r - 1\\);
	return r - s;.*(		return;)
	}
	int dir, off, pos, psn = sb->s_n;${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-4m 2${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:281:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 	while \\(r > s && uc_isspace\\(\\*r\\)\\)
		r = uc_beg\\(s, r - 1\\);
	kind = r > s \\? uc_kind\\(r\\) : 0;.*(	sbuf_str\\(sb, post\\))
	sbufn_null\\(sb\\)
	/\\* XXX: O\\(n\\) insertion; recursive array data structure cannot be optimized\\.${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-7m 2${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:281:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;2;3;4;5;6;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:281${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	}
	if \\(pos >= xleft \\+ xcols \\|\\| pos < xleft\\)
		xleft = pos < xcols \\? 0 : pos - xcols / 2;
	syn_scdir\\(0\\);
	led_crender\\(r->s, -1, vi_lncol, xleft, xleft \\+ xcols - vi_lncol\\);
	term_pos\\(-1, led_pos\\(r->s, pos\\) \\+ vi_lncol\\);
	sbufn_cut\\(sb, psn\\)
	rstate -= 2;${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+3m 3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	syn_scdir\\(0\\);
	led_crender\\(r->s, -1, vi_lncol, xleft, xleft \\+ xcols - vi_lncol\\);
	term_pos\\(-1, led_pos\\(r->s, pos\\) \\+ vi_lncol\\);
	sbufn_cut\\(sb, psn\\)
	rstate -= 2;${ESC}${SEP}2??${ESC}${SEP}${LB}
${ESC}${SEP}2??m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:307:a2${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	}
	if \\(pos >= xleft \\+ xcols \\|\\| pos < xleft\\)
		xleft = pos < xcols \\? 0 : pos - xcols / 2;${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+3m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:307:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	syn_scdir\\(0\\);
	led_crender\\(r->s, -1, vi_lncol, xleft, xleft \\+ xcols - vi_lncol\\);${ESC}${SEP}4??${ESC}${SEP}${LB}
${ESC}${SEP}4??m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:307:a4${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	term_pos\\(-1, led_pos\\(r->s, pos\\) \\+ vi_lncol\\);
	sbufn_cut\\(sb, psn\\)
	rstate -= 2;${ESC}${SEP}5??${ESC}${SEP}${LB}
${ESC}${SEP}5??-2m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:307:a5${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	}
.i...p.. ...xl..t...x.o.. \\|\\| .os.........
......... ........o...... ..................
......c..r.0..
...d_...n...\\(.-........v..l........e.....l.f......... . v.....ol\\).
.t..m......1. ..........>.....s.......l......
	......c..\\(s...p..\\)
...t...... ..${ESC}${SEP}6??${ESC}${SEP}${LB}
${ESC}${SEP}6??+3m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:307:a6${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ 	}.*?
	if \\(pos >= xleft \\+ xcols \\|\\| pos < xleft\\).*?
		xleft = pos < xcols \\? 0 : pos - xcols / 2;.*?
(	syn_scdir\\(0\\);)${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:307:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 		if \\(abs\\(dir\\) > r->wid\\[off-\\(two\\+1\\)]\\)
			pos = ren_cursor\\(r->s, r->pos\\[off-two]\\);
		pos \\+= dir < 0 \\? -1 : 1;.*(/\\* read a character from the terminal \\*/)
char \\*led_read\\(int \\*kmap, int c\\)
\\{${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-7m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:307:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 	if \\(off > 0\\) \\{
		int two = off > 1 && psn != pre;
		dir = r->pos\\[off-two] - r->pos\\[off-\\(two\\+1\\)];.*(	static char buf\\[5];)
	int c1, c2, i, n;
	while \\(!TK_INT\\(c\\)\\) \\{${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-10m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:307:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;2;3;4;5;6;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:307${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 		sbuf_mem\\(led_attsb, &la, sizeof\\(la\\)\\) \\\\
	} \\\\
	sbuf_str\\(sb, buf\\) \\\\
	led_printparts\\(sb, pre, ps, \\*post, postn, poff\\); \\\\
	sbuf_cut\\(sb, len\\) \\\\
	sbuf_free\\(led_attsb\\) \\\\
	led_attsb = prev_attsb; \\\\${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+3m 4${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	led_printparts\\(sb, pre, ps, \\*post, postn, poff\\); \\\\
	sbuf_cut\\(sb, len\\) \\\\
	sbuf_free\\(led_attsb\\) \\\\
	led_attsb = prev_attsb; \\\\${ESC}${SEP}2??${ESC}${SEP}${LB}
${ESC}${SEP}2??m 4${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:367:a2${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 		sbuf_mem\\(led_attsb, &la, sizeof\\(la\\)\\) \\\\
	} \\\\
	sbuf_str\\(sb, buf\\) \\\\${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+3m 4${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:367:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP};0${ESC}${SEP}fr${ESC}${SEP}.,\$f+ ^	led_printparts\\(sb, pre, ps, \\*post, postn, poff\\); \\\\\$${ESC}${SEP}4??${ESC}${SEP}${LB}
${ESC}${SEP}4??m 4${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:367:a4${ESC}${ESC}${ESC}${SEP}fr 98${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}fr 98${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	sbuf_cut\\(sb, len\\) \\\\
	sbuf_free\\(led_attsb\\) \\\\
	led_attsb = prev_attsb; \\\\${ESC}${SEP}5??${ESC}${SEP}${LB}
${ESC}${SEP}5??-1m 4${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:367:a5${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ ...b.._...\\(l.....t.....la...............
	...
...uf_st..... b....\\\\
	..d.........ts..b. .re,........... ...........\\)..\\\\
..b.....t.....l.....
....._..e.\\(.e..........
......tt..........a....;..${ESC}${SEP}6??${ESC}${SEP}${LB}
${ESC}${SEP}6??+3m 4${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:367:a6${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ 		sbuf_mem\\(led_attsb, &la, sizeof\\(la\\)\\) \\\\.*?
	} \\\\.*?
	sbuf_str\\(sb, buf\\) \\\\.*?
(	led_printparts\\(sb, pre, ps, \\*post, postn, poff\\); \\\\)${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 4${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:367:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 	sbuf_make\\(led_attsb, sizeof\\(la\\) \\* 2\\) \\\\
	for \\(i = uc_slen\\(buf\\) - 1; i >= 0; i--\\) \\{ \\\\
		la\\.off = \\*poff \\+ i; \\\\.*(static void led_redraw\\(char \\*cs, int r, int orow, int crow, int ctop, int flg\\))
\\{
	rstate\\+\\+;${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-9m 4${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:367:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 	la\\.s = NULL; \\\\
	la\\.att = WH1 \\| SYN_BD \\| SYN_OWR; \\\\
	sbuf \\*prev_attsb = led_attsb; \\\\.*(	for \\(int nl = 0; r < xrows; r\\+\\+\\) \\{)
		if \\(vi_lncol\\) \\{
			term_pos\\(r, 0\\);${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-12m 4${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:367:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;2;3;4;5;6;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:367${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	sbuf_free\\(led_attsb\\) \\\\
	led_attsb = prev_attsb; \\\\
	c = term_read\\(TK_CTL\\('l'\\)\\); \\\\
	led_printparts\\(sb, pre, ps, \\*post, postn, poff\\); \\\\
	goto noredraw; \\\\
} \\\\

${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+3m 5${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	led_printparts\\(sb, pre, ps, \\*post, postn, poff\\); \\\\
	goto noredraw; \\\\
} \\\\

${ESC}${SEP}2??${ESC}${SEP}${LB}
${ESC}${SEP}2??m 5${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:372:a2${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	sbuf_free\\(led_attsb\\) \\\\
	led_attsb = prev_attsb; \\\\
	c = term_read\\(TK_CTL\\('l'\\)\\); \\\\${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+3m 5${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:372:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP};0${ESC}${SEP}fr${ESC}${SEP}.,\$f+ ^	led_printparts\\(sb, pre, ps, \\*post, postn, poff\\); \\\\\$${ESC}${SEP}4??${ESC}${SEP}${LB}
${ESC}${SEP}4??m 5${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:372:a4${ESC}${ESC}${ESC}${SEP}fr 98${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}fr 98${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	goto noredraw; \\\\
} \\\\

${ESC}${SEP}5??${ESC}${SEP}${LB}
${ESC}${SEP}5??-1m 5${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:372:a5${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	..uf....e........s....
.l....t..b.. ............\\\\
	. . t.r....a...._CT.....\\)...\\\\
.l.._....t...t...b. ..........post.....t.,.........
...t..n.red.... .
}..

${ESC}${SEP}6??${ESC}${SEP}${LB}
${ESC}${SEP}6??+3m 5${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:372:a6${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ 	sbuf_free\\(led_attsb\\) \\\\.*?
	led_attsb = prev_attsb; \\\\.*?
	c = term_read\\(TK_CTL\\('l'\\)\\); \\\\.*?
(	led_printparts\\(sb, pre, ps, \\*post, postn, poff\\); \\\\)${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 5${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:372:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 	sbuf_make\\(led_attsb, sizeof\\(la\\) \\* 2\\) \\\\
	for \\(i = uc_slen\\(buf\\) - 1; i >= 0; i--\\) \\{ \\\\
		la\\.off = \\*poff \\+ i; \\\\.*(static void led_redraw\\(char \\*cs, int r, int orow, int crow, int ctop, int flg\\))
\\{
	rstate\\+\\+;${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-4m 5${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:372:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 	la\\.s = NULL; \\\\
	la\\.att = WH1 \\| SYN_BD \\| SYN_OWR; \\\\
	sbuf \\*prev_attsb = led_attsb; \\\\.*(	for \\(int nl = 0; r < xrows; r\\+\\+\\) \\{)
		if \\(vi_lncol\\) \\{
			term_pos\\(r, 0\\);${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-7m 5${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:372:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;2;3;4;5;6;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:372${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	int len, c, i;
	sbuf \\*reg;
	do \\{
		led_printparts\\(sb, pre, ps, \\*post, postn, poff\\);
		len = sb->s_n;
		c = term_read\\(TK_CTL\\('l'\\)\\);
		noredraw:${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+3m 6${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 		led_printparts\\(sb, pre, ps, \\*post, postn, poff\\);
		len = sb->s_n;
		c = term_read\\(TK_CTL\\('l'\\)\\);
		noredraw:${ESC}${SEP}2??${ESC}${SEP}${LB}
${ESC}${SEP}2??m 6${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:432:a2${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	int len, c, i;
	sbuf \\*reg;
	do \\{${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+3m 6${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:432:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP};0${ESC}${SEP}fr${ESC}${SEP}.,\$f+ ^		led_printparts\\(sb, pre, ps, \\*post, postn, poff\\);\$${ESC}${SEP}4??${ESC}${SEP}${LB}
${ESC}${SEP}4??m 6${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:432:a4${ESC}${ESC}${ESC}${SEP}fr 98${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}fr 98${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 		len = sb->s_n;
		c = term_read\\(TK_CTL\\('l'\\)\\);
		noredraw:${ESC}${SEP}5??${ESC}${SEP}${LB}
${ESC}${SEP}5??-1m 6${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:432:a5${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ ........,......
..bu.....g.
....\\{
..l.d...........\\(... pre.........st,....t...p.....
..l.. ....->s_..
	...=..e.m_....\\(......\\(...\\)..
...o.......${ESC}${SEP}6??${ESC}${SEP}${LB}
${ESC}${SEP}6??+3m 6${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:432:a6${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ 	int len, c, i;.*?
	sbuf \\*reg;.*?
	do \\{.*?
(		led_printparts\\(sb, pre, ps, \\*post, postn, poff\\);)${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 6${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:432:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 	int ai_max, int \\*poff, int \\*kmap, ins_state \\*is, int orow, int crow, int ctop, int flg\\)
\\{
	char \\*cs;.*(		switch \\(c\\) \\{)
		case TK_CTL\\('h'\\):
			c = 127;${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-4m 6${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:432:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 	restore\\(xvis\\)
	restore\\(xexec_dep\\)
}.*(		case 127:)
			if \\(len - pre > 0\\)
				sbuf_cut\\(sb, led_lastchar\\(sb->s \\+ pre\\) \\+ pre\\)${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-7m 6${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:432:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;2;3;4;5;6;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:432${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 			else if \\(!i\\)
				term_clean\\(\\);
			continue;
		case TK_CTL\\('o'\\): \\{
			if \\(!\\*postref\\)
				\\*postref = \\*post = uc_dup\\(\\*post\\);${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+2m 7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 			else if \\(!i\\)
				term_clean\\(\\);
			continue;${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+2m 7${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:625:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ 			else if \\(!i\\).*?
				term_clean\\(\\);.*?
(			continue;)${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 7${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:625:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 			term_init\\(\\);
			if \\(ai_max >= 0\\)
				led_redraw\\(sb->s, 0, orow, crow, ctop, flg\\);.*(			preserve\\(struct buf\\*, ex_buf,\\))
			int bidx = istempbuf\\(ex_buf\\) \\? -1 : ex_buf - bufs;
			preserve\\(int, ftidx,\\)${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-4m 7${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:625:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 		case TK_CTL\\('l'\\):
			i = term_winch;
			term_done\\(\\);.*(			led_modeswap\\(\\);)
			restore\\(ftidx\\)
			if \\(bidx < 0\\) \\{${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-7m 7${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:625:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;3;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:625${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ int led_prompt\\(sbuf \\*sb, char \\*insert, int \\*kmap, ins_state \\*is, int ps, int flg\\)
\\{
	int n = !\\(flg & 2\\) \\? sb->s_n : 0, key, off;
	char \\*post = \"\", \\*postref = post;
	ins_state _is;
	vi_lncol = 0;
	if \\(insert\\)${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+3m 8${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	char \\*post = \"\", \\*postref = post;
	ins_state _is;
	vi_lncol = 0;
	if \\(insert\\)${ESC}${SEP}2??${ESC}${SEP}${LB}
${ESC}${SEP}2??m 8${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:661:a2${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ int led_prompt\\(sbuf \\*sb, char \\*insert, int \\*kmap, ins_state \\*is, int ps, int flg\\)
\\{
	int n = !\\(flg & 2\\) \\? sb->s_n : 0, key, off;${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+3m 8${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:661:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP};0${ESC}${SEP}fr${ESC}${SEP}.,\$f+ ^	char \\*post = \"\", \\*postref = post;\$${ESC}${SEP}4??${ESC}${SEP}${LB}
${ESC}${SEP}4??m 8${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:661:a4${ESC}${ESC}${ESC}${SEP}fr 98${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}fr 98${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	ins_state _is;
	vi_lncol = 0;
	if \\(insert\\)${ESC}${SEP}5??${ESC}${SEP}${LB}
${ESC}${SEP}5??-1m 8${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:661:a5${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ .n....d_.r.......uf \\*... cha..\\*.n.er.........ma.........a.e.\\*..,..n..p.....t.....
\\{
...t......\\(.......... .b....n....,...y. o...
.c... ...s.....\", ..o...e. ..p...;
...._s.... ...;
.....n..l....;
........e...${ESC}${SEP}6??${ESC}${SEP}${LB}
${ESC}${SEP}6??+3m 8${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:661:a6${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ int led_prompt\\(sbuf \\*sb, char \\*insert, int \\*kmap, ins_state \\*is, int ps, int flg\\).*?
\\{.*?
	int n = !\\(flg & 2\\) \\? sb->s_n : 0, key, off;.*?
(	char \\*post = \"\", \\*postref = post;)${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 8${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:661:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 	} while \\(!\\(flg & 2\\)\\);
	return c;
}.*(		sbuf_str\\(sb, insert\\))
	if \\(!is\\) \\{
		ins_init\\(_is\\)${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-4m 8${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:661:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 		is->_sug = NULL;
		if \\(ai_max >= 0 && xpac\\)
			goto pac;.*(		is = &_is;)
	}
	preserve\\(int, xleft, xleft = 0;\\)${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-7m 8${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:661:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;2;3;4;5;6;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:661${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 			&off, kmap, is, 0, xrow, xtop, flg\\);
	restore\\(xtd\\)
	restore\\(xleft\\)
	if \\(key == '\\\\n' && flg & 1\\) \\{
		lbuf_dedup\\(tempbufs\\[0]\\.lb, sb->s \\+ n, sb->s_n - n\\)
		temp_pos\\(0, -1, 0, 0\\);${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+2m 9${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 			&off, kmap, is, 0, xrow, xtop, flg\\);
	restore\\(xtd\\)
	restore\\(xleft\\)${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+2m 9${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:675:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ 			&off, kmap, is, 0, xrow, xtop, flg\\);.*?
	restore\\(xtd\\).*?
(	restore\\(xleft\\))${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 9${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:675:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 	preserve\\(int, xleft, xleft = 0;\\)
	preserve\\(int, xtd, xtd = 2;\\)
	key = led_line\\(sb, ps, n, &post, 0, &postref, -1,.*(		temp_write\\(0, sb->s \\+ n\\);)
	}
	return key;${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-4m 9${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:675:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 		ins_init\\(_is\\)
		is = &_is;
	}.*(int led_input\\(sbuf \\*sb, char \\*post, int postn, int row, int flg, int \\*pren\\))
\\{
	int ai_max = 128 \\* xai;${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-9m 9${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:675:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;3;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:675${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 			return key;
		}
		sbuf_chr\\(sb, key\\)
		led_printparts\\(sb, -1, ps, \"\", 0, &xoff\\);
		term_chr\\('\\\\n'\\);
		term_room\\(1\\);
		crow\\+\\+;${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+3m 10${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 		led_printparts\\(sb, -1, ps, \"\", 0, &xoff\\);
		term_chr\\('\\\\n'\\);
		term_room\\(1\\);
		crow\\+\\+;${ESC}${SEP}2??${ESC}${SEP}${LB}
${ESC}${SEP}2??m 10${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:706:a2${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 			return key;
		}
		sbuf_chr\\(sb, key\\)${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+3m 10${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:706:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP};0${ESC}${SEP}fr${ESC}${SEP}.,\$f+ ^		led_printparts\\(sb, -1, ps, \"\", 0, &xoff\\);\$${ESC}${SEP}4??${ESC}${SEP}${LB}
${ESC}${SEP}4??m 10${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:706:a4${ESC}${ESC}${ESC}${SEP}fr 98${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}fr 98${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 		term_chr\\('\\\\n'\\);
		term_room\\(1\\);
		crow\\+\\+;${ESC}${SEP}5??${ESC}${SEP}${LB}
${ESC}${SEP}5??-1m 10${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:706:a5${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	...e...n...y;
.	.
.....f..h.\\(....ke..
....d.p........s\\(.b,.............., ...ff..
.	..r...h..'....;
.	t.r........\\).
.	...w...${ESC}${SEP}6??${ESC}${SEP}${LB}
${ESC}${SEP}6??+3m 10${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:706:a6${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ 			return key;.*?
		}.*?
		sbuf_chr\\(sb, key\\).*?
(		led_printparts\\(sb, -1, ps, \"\", 0, &xoff\\);)${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 10${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:706:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 				sb->s\\[\\*pren] = \\*post;
			free\\(postref\\);
			xrow = crow;.*(		n = ps;)
		ps = sb->s_n;
		if \\(ai_max\\) \\{	/\\* updating autoindent \\*/${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-4m 10${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:706:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 				xoff = uc_slen\\(sb->s\\+ps\\);
				sbufn_str\\(sb, post\\)
			} else.*(			for \\(; \\*post == ' ' \\|\\| \\*post == '\\\\t'; postn--\\))
				\\+\\+post;
			int ai_new = n;${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-7m 10${ESC}${ESC}${ESC}${SEP}${OK1}p OK led.c:706:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;2;3;4;5;6;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:706${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}${LB}
${SEP}'1i static int vi_insmov;
${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:3:m1${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'2s/f\\)/f, int print)/${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:281:m2${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'3,#+1c 	if (print) {
		syn_scdir(0);
		led_crender(r->s, -1, vi_lncol, xleft, xleft + xcols - vi_lncol);
	}
${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:307:m3${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'4s/f\\)/f, 1)/${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:367:m4${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'5s/f\\)/f, !vi_insmov)/${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:372:m5${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'6c 		led_printparts(sb, pre, ps, *post, postn, poff, !vi_insmov);
		vi_insmov = 0;
${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:432:m6${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'7i 		case '\\033':;	/* Arrow keys */
			char cbuf[1];
			cbuf[0] = '\\0';
			int fl = fcntl(STDIN_FILENO, F_GETFL);
			fcntl(STDIN_FILENO, F_SETFL, fl | O_NONBLOCK);
			read(STDIN_FILENO, cbuf, 1);
			if (*cbuf == '[') {
				read(STDIN_FILENO, cbuf, 1);
				c = *cbuf;
				fcntl(STDIN_FILENO, F_SETFL, fl);
				if (ai_max < 0) {
					/* Prompt mode: handle arrows internally */
					int lc, clen, plen;
					char *newpost;
					switch (c) {
					case 'D':  /* ← */
						if (len > pre) {
							lc = led_lastchar(sb->s + pre) + pre;
							clen = len - lc;
							plen = strlen(*post);
							newpost = emalloc(plen + clen + 1);
							memcpy(newpost, sb->s + lc, clen);
							memcpy(newpost + clen, *post, plen + 1);
							free(*postref);
							*postref = *post = newpost;
							postn++;
							sbuf_cut(sb, lc)
						}
						continue;
					case 'C':  /* → */
						if (**post) {
							clen = uc_len(*post);
							sbuf_mem(sb, *post, clen)
							plen = strlen(*post);
							newpost = emalloc(plen - clen + 1);
							memcpy(newpost, *post + clen, plen - clen + 1);
							free(*postref);
							*postref = *post = newpost;
							postn--;
						}
						continue;
					case 'A':  /* ↑ - history */
					case 'B':  /* ↓ - history */
						if (is->t_row < -1)
							is->t_row = tempbufs[0].row;
						else if (c == 'A' && is->t_row > 0)
							is->t_row--;
						else if (c == 'B' && is->t_row < lbuf_len(tempbufs[0].lb) - 1)
							is->t_row++;
						if ((cs = lbuf_get(tempbufs[0].lb, is->t_row))) {
							sbuf_cut(sb, pre)
							sbuf_str(sb, cs)
							sb->s_n--;
							newpost = emalloc(1);
							*newpost = '\\0';
							free(*postref);
							*postref = *post = newpost;
							postn = 0;
						}
						continue;
					}
				}
				vi_insmov = c;
				return c;
			}
			fcntl(STDIN_FILENO, F_SETFL, fl);
			return c;
${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:625:m7${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'8s/ post/ NULL/${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:661:m8${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'9i 	sbufn_str(sb, post)
	free(postref);
${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:675:m9${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'10s/f\\)/f, 1)/${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL led.c:706:m10${ESC}${SEP}pr${INTR}${QF2}}${SEP}b1${SEP}%ya 98${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f> 	\\*l = ln - pln;
}

static int vi_change\\(int r1, int o1, int r2, int o2, int lnmode\\)
\\{
	char \\*post, \\*ln = lbuf_get\\(xb, r1\\);${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+2m 1${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f> 	\\*l = ln - pln;
}

${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+2m 1${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:837:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 		ln = \"\";
	char \\*pln = ln;
	for \\(; \\*ln == ' ' \\|\\| \\*ln == '\\\\t'; ln\\+\\+\\);.*(	int key, tlen, l1, l2 = 1, postn = 1;)
	sbuf_smake\\(sb, xcols\\)
	if \\(lnmode \\|\\| !ln\\) \\{${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-5m 1${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:837:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> static void vi_indents\\(char \\*ln, int \\*l\\)
\\{
	if \\(!xai \\|\\| !ln\\).*(		o1 = l1;)
		post = \"\\\\n\";
		tlen = -1;${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-9m 1${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:837:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;3;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL vi.c:837${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	if \\(postn \\+ l2 != tlen \\|\\| memcmp\\(ln \\+ l1, sb->s \\+ l1, tlen - l2 - l1\\)\\)
		lbuf_edit\\(xb, sb->s, r1, r2 \\+ 1, o1, xoff\\);
	free\\(sb->s\\);
	return key;
}

${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+2m 2${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	if \\(postn \\+ l2 != tlen \\|\\| memcmp\\(ln \\+ l1, sb->s \\+ l1, tlen - l2 - l1\\)\\)
		lbuf_edit\\(xb, sb->s, r1, r2 \\+ 1, o1, xoff\\);
	free\\(sb->s\\);${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+2m 2${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:869:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ 	if \\(postn \\+ l2 != tlen \\|\\| memcmp\\(ln \\+ l1, sb->s \\+ l1, tlen - l2 - l1\\)\\).*?
		lbuf_edit\\(xb, sb->s, r1, r2 \\+ 1, o1, xoff\\);.*?
(	free\\(sb->s\\);)${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 2${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:869:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 		xtop = r1;
	sbuf_mem\\(sb, ln, l1\\)
	key = led_input\\(sb, post, postn, r1 - \\(r1 - r2\\), 0, &postn\\);.*(static void vi_case\\(int r1, int o1, int r2, int o2, int lnmode, int cmd\\))
\\{
	sbuf rsb;${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-4m 2${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:869:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 			\\(\\*vi_word && ln && \\*ln != '\\\\n' && r1 != r2\\)\\);
	xrow = r1;
	if \\(r1 < xtop\\).*(	lbuf_region\\(xb, &rsb, r1, lnmode \\? 0 : o1, r2, lnmode \\? -1 : o2\\);)
	char \\*s = rsb\\.s;
	while \\(uc_len\\(s\\)\\) \\{${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-7m 2${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:869:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;3;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL vi.c:869${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	term_room\\(cmdo\\);
	sbuf_mem\\(sb, ln, l1\\)
	key = led_input\\(sb, post, postn, row, cmdo << 2, &postn\\);
	if \\(postn != l1 \\|\\| cmdo \\|\\| !ln\\)
		lbuf_edit\\(xb, sb->s, row, row \\+ !cmdo, off, xoff\\);${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+3m 3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	if \\(postn != l1 \\|\\| cmdo \\|\\| !ln\\)
		lbuf_edit\\(xb, sb->s, row, row \\+ !cmdo, off, xoff\\);${ESC}${SEP}2??${ESC}${SEP}${LB}
${ESC}${SEP}2??m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1041:a2${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 	term_room\\(cmdo\\);
	sbuf_mem\\(sb, ln, l1\\)
	key = led_input\\(sb, post, postn, row, cmdo << 2, &postn\\);${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+3m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1041:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP};0${ESC}${SEP}fr${ESC}${SEP}.,\$f+ ^	if \\(postn != l1 \\|\\| cmdo \\|\\| !ln\\)\$${ESC}${SEP}4??${ESC}${SEP}${LB}
${ESC}${SEP}4??m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1041:a4${ESC}${ESC}${ESC}${SEP}fr 98${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}fr 98${ESC}${SEP}${LB}
${ESC}${SEP};0${ESC}${SEP}fr${ESC}${SEP}.,\$f+ ^		lbuf_edit\\(xb, sb->s, row, row \\+ !cmdo, off, xoff\\);\$${ESC}${SEP}5??${ESC}${SEP}${LB}
${ESC}${SEP}5??-1m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1041:a5${ESC}${ESC}${ESC}${SEP}fr 98${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}fr 98${ESC}${SEP}${LB}
${ESC}${SEP}%f+ ..e.._.....cm.o.;
.s.u.......b......l..
.ke....l......u..... po.t.....tn...o............. ....t.\\).
.......... ....1.\\|..cmd......ln.
	....f......x.,..b..., r... ..... .........f....ff\\).${ESC}${SEP}6??${ESC}${SEP}${LB}
${ESC}${SEP}6??+3m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1041:a6${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ 	term_room\\(cmdo\\);.*?
	sbuf_mem\\(sb, ln, l1\\).*?
	key = led_input\\(sb, post, postn, row, cmdo << 2, &postn\\);.*?
(	if \\(postn != l1 \\|\\| cmdo \\|\\| !ln\\))${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1041:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 		post = ln \\+ l1;
	}
	term_pos\\(row - xtop, 0\\);.*(static int vc_put\\(int cmd\\))
\\{
	int cnt = MAX\\(1, vi_arg\\);${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-6m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1041:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 		off = xoff;
		l1 = rstate->chrs\\[off] - ln;
		postn = rstate->n - off;.*(	int i, off;)
	char \\*ln;
	sbuf \\*buf = ex_regget\\(vi_ybuf\\);${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-9m 3${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1041:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;2;3;4;5;6;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL vi.c:1041${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 		lbuf_edit\\(xb, sb->s, row, row \\+ !cmdo, off, xoff\\);
	free\\(sb->s\\);
	return key;
}${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??m 4${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP};0${ESC}${SEP}fr${ESC}${SEP}.,\$f+ ^		lbuf_edit\\(xb, sb->s, row, row \\+ !cmdo, off, xoff\\);\$${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??m 4${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1042:a3${ESC}${ESC}${ESC}${SEP}fr 98${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}fr 98${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 		post = ln \\+ l1;
	}
	term_pos\\(row - xtop, 0\\);.*(static int vc_put\\(int cmd\\))
\\{
	int cnt = MAX\\(1, vi_arg\\);${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-5m 4${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1042:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 		off = xoff;
		l1 = rstate->chrs\\[off] - ln;
		postn = rstate->n - off;.*(	int i, off;)
	char \\*ln;
	sbuf \\*buf = ex_regget\\(vi_ybuf\\);${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-8m 4${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1042:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;3;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL vi.c:1042${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 				insert:
				k = vc_insert\\(c\\);
				insert_done:
				if \\(k == 127 \\|\\| k == TK_CTL\\('w'\\)\\) \\{
					if \\(xrow && !\\(xoff > 0 && lbuf_eol\\(xb, xrow, 1\\)\\)\\) \\{
						xrow--;${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+2m 5${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 				insert:
				k = vc_insert\\(c\\);
				insert_done:${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+2m 5${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1529:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ 				insert:.*?
				k = vc_insert\\(c\\);.*?
(				insert_done:)${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 5${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1529:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 			case 'A':
			case 'o':
			case 'O':.*(						topfix\\(\\))
						vc_join\\(0, 2\\);
						vi_drawagain\\(xtop\\);${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-4m 5${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1529:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 			case 'I':
			case 'i':
			case 'a':.*(					} else if \\(xoff\\) \\{)
						if \\(k == TK_CTL\\('w'\\)\\) \\{
							noff = xoff;${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-7m 5${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1529:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;3;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL vi.c:1529${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}?${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 				rep_record\\(\\)
				vi_mod \\|= !xpac && xrow == orow \\? 8 : 1;
				break;
			case 'J':
				vc_join\\(1, vi_arg <= 1 \\? 2 : vi_arg\\);
				rep_record\\(\\)${ESC}${SEP}1??${ESC}${SEP}${LB}
${ESC}${SEP}1??+2m 6${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}%f+ 				rep_record\\(\\)
				vi_mod \\|= !xpac && xrow == orow \\? 8 : 1;
				break;${ESC}${SEP}3??${ESC}${SEP}${LB}
${ESC}${SEP}3??+2m 6${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1551:a3${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}grp 1${ESC}${SEP}%f+ 				rep_record\\(\\).*?
				vi_mod \\|= !xpac && xrow == orow \\? 8 : 1;.*?
(				break;)${ESC}${SEP}7??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}7??m 6${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1551:a7${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 					goto insert;
				}
				xoff--;.*(			case 'K': \\{)
				preserve\\(int, xvis, xvis = 1;\\)
				do \\{${ESC}${SEP}8??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}8??-6m 6${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1551:a8${ESC}${SEP}'0${ESC}${SEP}8??${ESC}${ESC}${ESC}${SEP}1q${ESC}${SEP}${LB}
${ESC}${SEP}m 0${ESC}${SEP}1;0${ESC}${SEP}grp 1${ESC}${SEP}%f> 					}
					c = xoff != lbuf_eol\\(xb, xrow, 1\\) \\? 'i' : 'a';
					xb->useq \\+= xseq;.*(					ex_exec\\(\";\\+1c\\\\n:-1\"\\);)
				} while \\(vi_arg--\\);
				restore\\(xvis\\)${ESC}${SEP}9??${ESC}${SEP}${LB}
${ESC}${SEP}grp 0${ESC}${SEP}9??-9m 6${ESC}${ESC}${ESC}${SEP}${OK1}p OK vi.c:1551:a9${ESC}${SEP}'0${SEP}${LB}
${SEP}1;3;7;8;9??!${DBG1:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL vi.c:1551${ESC}${SEP}pr${INTR}${QF1}}${SEP}${LB}
${SEP}${LB}
${SEP}'1i static int lmodified;

${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL vi.c:837:m1${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'2i 	lmodified = 1;
${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL vi.c:869:m2${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'3s/\\)/) {/${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL vi.c:1041:m3${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'4i 		lmodified = 1;
	} else
		lmodified = 0;
${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL vi.c:1042:m4${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'5i 				switch (k) {
				case 'A':	/* ↑ */
					term_push(!lmodified ? (char*)&c : \"i\", 1);
					if (lmodified)
						vi_col = vi_off2col(xb, xrow, xoff);
					xrow--;
					xrow = xrow < 0 ? 0 : xrow;
					xoff = vi_col2off(xb, xrow, vi_col);
					lmodified = 0;
					goto _break;
				case 'B':	/* ↓ */
					term_push(!lmodified ? (char*)&c : \"i\", 1);
					if (lmodified)
						vi_col = vi_off2col(xb, xrow, xoff);
					xrow++;
					xoff = vi_col2off(xb, xrow, vi_col);
					lmodified = 0;
					goto _break;
				case 'D':	/* ← */
					term_push(\"i\", 1);
					xoff--;
					xoff = xoff < 0 ? 0 : xoff;
					vi_col = vi_off2col(xb, xrow, xoff);
					goto _break;
				case 'C':	/* → */
					term_push(*uc_chr(lbuf_get(xb, xrow), xoff+2) ? \"i\" : \"A\", 1);
					xoff++;
					if (*uc_chr(lbuf_get(xb, xrow), xoff))
						vi_col = vi_off2col(xb, xrow, xoff);
					goto _break;
				}
${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL vi.c:1529:m5${ESC}${SEP}pr${INTR}${QF2}}${SEP}${LB}
${SEP}'6i 				_break:
				vi_mod = 0;
				break;
${SEP}??!${DBG2:-ya!112${ESC}${SEP}prp${ESC}${SEP}p FAIL vi.c:1551:m6${ESC}${SEP}pr${INTR}${QF2}}${SEP}vis 2${SEP}b0${SEP}w${SEP}b1${SEP}w${SEP}2q" > "$P2VIF"
EXINIT='%ya 97:? %@97' $VI -e 'led.c' 'vi.c' "$P2VIF"

exit 0
=== PATCH2VI DELTA ===
=== PATCH2VI PATCH ===
diff --git a/led.c b/led.c
index 96d2e3ba..7aa93d76 100644
--- a/led.c
+++ b/led.c
@@ -1,6 +1,7 @@
 static sbuf *suggestsb;
 static sbuf *acsb;
 sbuf *led_attsb;
+static int vi_insmov;
 
 int dstrlen(const char *s, char delim)
 {
@@ -278,7 +279,7 @@ static int led_lastword(char *s)
 }
 
 static void led_printparts(sbuf *sb, int pre, int ps,
-	char *post, int postn, int *poff)
+	char *post, int postn, int *poff, int print)
 {
 	if (!xled) {
 		sbufn_null(sb)
@@ -304,8 +305,10 @@ static void led_printparts(sbuf *sb, int pre, int ps,
 	}
 	if (pos >= xleft + xcols || pos < xleft)
 		xleft = pos < xcols ? 0 : pos - xcols / 2;
-	syn_scdir(0);
-	led_crender(r->s, -1, vi_lncol, xleft, xleft + xcols - vi_lncol);
+	if (print) {
+		syn_scdir(0);
+		led_crender(r->s, -1, vi_lncol, xleft, xleft + xcols - vi_lncol);
+	}
 	term_pos(-1, led_pos(r->s, pos) + vi_lncol);
 	sbufn_cut(sb, psn)
 	rstate -= 2;
@@ -364,12 +367,12 @@ char *led_read(int *kmap, int c)
 		sbuf_mem(led_attsb, &la, sizeof(la)) \
 	} \
 	sbuf_str(sb, buf) \
-	led_printparts(sb, pre, ps, *post, postn, poff); \
+	led_printparts(sb, pre, ps, *post, postn, poff, 1); \
 	sbuf_cut(sb, len) \
 	sbuf_free(led_attsb) \
 	led_attsb = prev_attsb; \
 	c = term_read(TK_CTL('l')); \
-	led_printparts(sb, pre, ps, *post, postn, poff); \
+	led_printparts(sb, pre, ps, *post, postn, poff, !vi_insmov); \
 	goto noredraw; \
 } \
 
@@ -429,7 +432,8 @@ static int led_line(sbuf *sb, int ps, int pre, char **post, int postn, char **po
 	int len, c, i;
 	sbuf *reg;
 	do {
-		led_printparts(sb, pre, ps, *post, postn, poff);
+		led_printparts(sb, pre, ps, *post, postn, poff, !vi_insmov);
+		vi_insmov = 0;
 		len = sb->s_n;
 		c = term_read(TK_CTL('l'));
 		noredraw:
@@ -623,6 +627,73 @@ static int led_line(sbuf *sb, int ps, int pre, char **post, int postn, char **po
 			else if (!i)
 				term_clean();
 			continue;
+		case '\033':;	/* Arrow keys */
+			char cbuf[1];
+			cbuf[0] = '\0';
+			int fl = fcntl(STDIN_FILENO, F_GETFL);
+			fcntl(STDIN_FILENO, F_SETFL, fl | O_NONBLOCK);
+			read(STDIN_FILENO, cbuf, 1);
+			if (*cbuf == '[') {
+				read(STDIN_FILENO, cbuf, 1);
+				c = *cbuf;
+				fcntl(STDIN_FILENO, F_SETFL, fl);
+				if (ai_max < 0) {
+					/* Prompt mode: handle arrows internally */
+					int lc, clen, plen;
+					char *newpost;
+					switch (c) {
+					case 'D':  /* ← */
+						if (len > pre) {
+							lc = led_lastchar(sb->s + pre) + pre;
+							clen = len - lc;
+							plen = strlen(*post);
+							newpost = emalloc(plen + clen + 1);
+							memcpy(newpost, sb->s + lc, clen);
+							memcpy(newpost + clen, *post, plen + 1);
+							free(*postref);
+							*postref = *post = newpost;
+							postn++;
+							sbuf_cut(sb, lc)
+						}
+						continue;
+					case 'C':  /* → */
+						if (**post) {
+							clen = uc_len(*post);
+							sbuf_mem(sb, *post, clen)
+							plen = strlen(*post);
+							newpost = emalloc(plen - clen + 1);
+							memcpy(newpost, *post + clen, plen - clen + 1);
+							free(*postref);
+							*postref = *post = newpost;
+							postn--;
+						}
+						continue;
+					case 'A':  /* ↑ - history */
+					case 'B':  /* ↓ - history */
+						if (is->t_row < -1)
+							is->t_row = tempbufs[0].row;
+						else if (c == 'A' && is->t_row > 0)
+							is->t_row--;
+						else if (c == 'B' && is->t_row < lbuf_len(tempbufs[0].lb) - 1)
+							is->t_row++;
+						if ((cs = lbuf_get(tempbufs[0].lb, is->t_row))) {
+							sbuf_cut(sb, pre)
+							sbuf_str(sb, cs)
+							sb->s_n--;
+							newpost = emalloc(1);
+							*newpost = '\0';
+							free(*postref);
+							*postref = *post = newpost;
+							postn = 0;
+						}
+						continue;
+					}
+				}
+				vi_insmov = c;
+				return c;
+			}
+			fcntl(STDIN_FILENO, F_SETFL, fl);
+			return c;
 		case TK_CTL('o'): {
 			if (!*postref)
 				*postref = *post = uc_dup(*post);
@@ -658,7 +729,7 @@ static int led_line(sbuf *sb, int ps, int pre, char **post, int postn, char **po
 int led_prompt(sbuf *sb, char *insert, int *kmap, ins_state *is, int ps, int flg)
 {
 	int n = !(flg & 2) ? sb->s_n : 0, key, off;
-	char *post = "", *postref = post;
+	char *post = "", *postref = NULL;
 	ins_state _is;
 	vi_lncol = 0;
 	if (insert)
@@ -673,6 +744,8 @@ int led_prompt(sbuf *sb, char *insert, int *kmap, ins_state *is, int ps, int flg
 			&off, kmap, is, 0, xrow, xtop, flg);
 	restore(xtd)
 	restore(xleft)
+	sbufn_str(sb, post)
+	free(postref);
 	if (key == '\n' && flg & 1) {
 		lbuf_dedup(tempbufs[0].lb, sb->s + n, sb->s_n - n)
 		temp_pos(0, -1, 0, 0);
@@ -703,7 +776,7 @@ int led_input(sbuf *sb, char *post, int postn, int row, int flg, int *pren)
 			return key;
 		}
 		sbuf_chr(sb, key)
-		led_printparts(sb, -1, ps, "", 0, &xoff);
+		led_printparts(sb, -1, ps, "", 0, &xoff, 1);
 		term_chr('\n');
 		term_room(1);
 		crow++;
diff --git a/vi.c b/vi.c
index 357df5ff..acc7a899 100644
--- a/vi.c
+++ b/vi.c
@@ -835,6 +835,8 @@ static void vi_indents(char *ln, int *l)
 	*l = ln - pln;
 }
 
+static int lmodified;
+
 static int vi_change(int r1, int o1, int r2, int o2, int lnmode)
 {
 	char *post, *ln = lbuf_get(xb, r1);
@@ -867,6 +869,7 @@ static int vi_change(int r1, int o1, int r2, int o2, int lnmode)
 	if (postn + l2 != tlen || memcmp(ln + l1, sb->s + l1, tlen - l2 - l1))
 		lbuf_edit(xb, sb->s, r1, r2 + 1, o1, xoff);
 	free(sb->s);
+	lmodified = 1;
 	return key;
 }
 
@@ -1038,8 +1041,11 @@ static int vc_insert(int cmd)
 	term_room(cmdo);
 	sbuf_mem(sb, ln, l1)
 	key = led_input(sb, post, postn, row, cmdo << 2, &postn);
-	if (postn != l1 || cmdo || !ln)
+	if (postn != l1 || cmdo || !ln) {
 		lbuf_edit(xb, sb->s, row, row + !cmdo, off, xoff);
+		lmodified = 1;
+	} else
+		lmodified = 0;
 	free(sb->s);
 	return key;
 }
@@ -1527,6 +1533,37 @@ void vi(int init)
 				insert:
 				k = vc_insert(c);
 				insert_done:
+				switch (k) {
+				case 'A':	/* ↑ */
+					term_push(!lmodified ? (char*)&c : "i", 1);
+					if (lmodified)
+						vi_col = vi_off2col(xb, xrow, xoff);
+					xrow--;
+					xrow = xrow < 0 ? 0 : xrow;
+					xoff = vi_col2off(xb, xrow, vi_col);
+					lmodified = 0;
+					goto _break;
+				case 'B':	/* ↓ */
+					term_push(!lmodified ? (char*)&c : "i", 1);
+					if (lmodified)
+						vi_col = vi_off2col(xb, xrow, xoff);
+					xrow++;
+					xoff = vi_col2off(xb, xrow, vi_col);
+					lmodified = 0;
+					goto _break;
+				case 'D':	/* ← */
+					term_push("i", 1);
+					xoff--;
+					xoff = xoff < 0 ? 0 : xoff;
+					vi_col = vi_off2col(xb, xrow, xoff);
+					goto _break;
+				case 'C':	/* → */
+					term_push(*uc_chr(lbuf_get(xb, xrow), xoff+2) ? "i" : "A", 1);
+					xoff++;
+					if (*uc_chr(lbuf_get(xb, xrow), xoff))
+						vi_col = vi_off2col(xb, xrow, xoff);
+					goto _break;
+				}
 				if (k == 127 || k == TK_CTL('w')) {
 					if (xrow && !(xoff > 0 && lbuf_eol(xb, xrow, 1))) {
 						xrow--;
@@ -1549,6 +1586,9 @@ void vi(int init)
 				rep_record()
 				vi_mod |= !xpac && xrow == orow ? 8 : 1;
 				break;
+				_break:
+				vi_mod = 0;
+				break;
 			case 'J':
 				vc_join(1, vi_arg <= 1 ? 2 : vi_arg);
 				rep_record()
