From: Steve Bennett Date: Thu, 30 Sep 2010 22:32:44 +0000 (+1000) Subject: Add support for ^W to remove a word on the left X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=446197fdee72b8960ac587bd61881bd7c5556d9c;p=linenoise.git Add support for ^W to remove a word on the left Signed-off-by: Steve Bennett --- diff --git a/linenoise.c b/linenoise.c index 3911a51..0812467 100644 --- a/linenoise.c +++ b/linenoise.c @@ -366,6 +366,24 @@ process_char: free(history[history_len]); return -1; } + case 23: /* ctrl-w */ + /* eat any spaces on the left */ + { + int n = 0; + while (pos > 0 && len > 0 && buf[pos - 1] == ' ') { + pos--; + len--; + n++; + } + /* now eat any non-spaces on the left */ + while (pos > 0 && len > 0 && buf[pos - 1] != ' ') { + pos--; + len--; + n++; + } + memmove(buf+pos,buf+pos+n,len-pos); + refreshLine(fd,prompt,buf,len,pos,cols); + } break; case 18: /* ctrl-r */ {