mirror of
https://codeberg.org/landley/toybox.git
synced 2026-01-26 06:07:55 +00:00
vi: Support ZZ to save and exit
This commit is contained in:
parent
e18fd82784
commit
1520fe6e9b
@ -29,3 +29,5 @@ vitest "insert multiple times ascii" "iab\x1bicd\x1bief\x1b" "xyz" "acefdbxyz"
|
||||
|
||||
vitest "insert multi yank move and push ascii" "ixyz\x1byyjp" \
|
||||
"abc def\nghi jkl\nmno pqr\n" "xyzabc def\nghi jkl\nxyzabc def\nmno pqr\n"
|
||||
|
||||
testcmd "ZZ save" "-s /dev/stdin input 1>/dev/null 2>/dev/null && cat input" "helloabc def" "abc def" "ihello\x1bZZ"
|
||||
|
||||
@ -66,7 +66,7 @@ GLOBALS(
|
||||
|
||||
char *filename;
|
||||
int vi_mode, tabstop, list, cur_col, cur_row, scr_row, drawn_row, drawn_col,
|
||||
count0, count1, vi_mov_flag;
|
||||
count0, count1, vi_mov_flag, vi_exit;
|
||||
unsigned screen_height, screen_width;
|
||||
char vi_reg, *last_search;
|
||||
struct str_line {
|
||||
@ -1228,6 +1228,15 @@ static int vi_find_prev(char reg, int count0, int count1)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int vi_ZZ(char reg, int count0, int count1)
|
||||
{
|
||||
if (modified() && write_file(0) != 1) {
|
||||
return 1; // Write failed, don't exit
|
||||
}
|
||||
TT.vi_exit = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//NOTES
|
||||
//vi-mode cmd syntax is
|
||||
//("[REG])[COUNT0]CMD[COUNT1](MOV)
|
||||
@ -1252,6 +1261,7 @@ struct vi_special_param {
|
||||
{"I", &vi_I},
|
||||
{"J", &vi_join},
|
||||
{"O", &vi_O},
|
||||
{"ZZ", &vi_ZZ},
|
||||
{"N", &vi_find_prev},
|
||||
{"n", &vi_find_next},
|
||||
{"o", &vi_o},
|
||||
@ -1848,6 +1858,8 @@ void vi_main(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Check for exit flag (used by ZZ command)
|
||||
if (TT.vi_exit) goto cleanup_vi;
|
||||
}
|
||||
cleanup_vi:
|
||||
linelist_unload();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user