[PATCH] vi: cancel command and search on escape

Ethan Alker ealker1 at gmail.com
Sun Aug 3 01:59:19 UTC 2025


---
Previously, clicking escape would cause the command or search query to
run. While this matches the original vi behavior, it's less intuitive
and provides no way to fully clear the buffer other than clicking
backspace a bunch of times. If compatability with the original vi is a
concern, then an alternative could be adding support for ^U to clear the
buffer, which the original vi does support.

 editors/vi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/editors/vi.c b/editors/vi.c
index 34932f60c..76b07116a 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -1217,7 +1217,12 @@ static char *get_input_line(const char *prompt)
 	i = strlen(buf);
 	while (i < MAX_INPUT_LEN - 1) {
 		c = get_one_char();
-		if (c == '\n' || c == '\r' || c == 27)
+		if (c == 27) {
+			// user cancelled, reset buffer
+			buf[0] = '\0';
+			break;
+		}
+		if (c == '\n' || c == '\r')
 			break;		// this is end of input
 		if (isbackspace(c)) {
 			// user wants to erase prev char
-- 
2.50.1



More information about the busybox mailing list