Skip to content

Agent: Option/Alt/Ctrl + arrows/backspace - #1350

Open
pierrei wants to merge 1 commit into
antirez:mainfrom
pierrei:linenoise-word-navigation
Open

pierrei wants to merge 1 commit into
antirez:mainfrom
pierrei:linenoise-word-navigation

Conversation

@pierrei

@pierrei pierrei commented Nov 13, 2026

Copy link
Copy Markdown

What

Word-wise cursor motion in the linenoise editor used by ds4-agent and the CLI:

  • Option+Left / Option+Right on macOS (ESC b / ESC f, also ESC B / ESC F): previous / next word.
  • Modified arrows on other terminals: ESC [ 1;3 D/C (Alt), 1;4 (Alt+Shift), 1;5 (Ctrl, the word-jump key on most Linux terminals and tmux) and 1;9 (iTerm Meta), in both CSI and SS3 (ESC O 1;3 D) form.
  • Option+Backspace (ESC DEL): delete the previous word.

Words are whitespace-delimited (isspace). Motion goes through the existing linenoiseEditPrevLen / NextLen helpers, so multibyte UTF-8 characters are never split and a folded multiline paste is stepped over as one unit. Ctrl+W now shares the same word-boundary helper instead of duplicating the loop.

Behaviour change worth knowing about: a lone ESC followed by b, f, B, F or DEL is now a command, as in readline, rather than ESC being dropped and the character inserted.

Who did what

Most of this was written by DS4 itself (the agent in this repo), working on the original request: the word-motion functions, the CSI/SS3 modifier parsing, the ESC b/f handling, and the first version of tests/test_linenoise_wordnav.c.

I then had it reviewed, and Claude Sonnet 5.5 made these adjustments on top:

  • Switched word delimiters from ' ' to isspace, and pulled the boundary scan into two shared helpers (linenoiseWordStartBefore / linenoiseWordStartAfter), also used by linenoiseEditDeletePrevWord.
  • Added Ctrl (5) and iTerm Meta (9) modifiers to the accepted arrow modifiers.
  • Added Option+Backspace (ESC DEL) word deletion.
  • Made linenoiseEditMovePrevWord / MoveNextWord static.
  • Removed a redundant condition in the ESC handling.
  • Extended the test: Ctrl/Meta arrows, uppercase ESC B/F, ESC DEL, UTF-8 words, and word motion across a folded multiline paste.
  • Added the test binary to .gitignore and make clean.

Testing

  • macOS, default (Metal) build: make tests/test_linenoise_wordnav && ./tests/test_linenoise_wordnav passes (drives linenoiseEditFeed through pipes using LINENOISE_ASSUME_TTY, no terminal needed), and make ds4-agent builds without warnings. The test is also wired into make test.
  • Tried by hand in ds4-agent on macOS: Option+Left/Right jump words.
  • Not run: the full make test (needs a model), make cpu, CUDA. No inference code is touched, so there is no speed or correctness impact on the backends.

This touches linenoise.c, as do #426 and #699, so I'd expect small rebases against those if they land first. I didn't find an existing PR or issue for word navigation.

…n+Backspace

macOS terminals send ESC b / ESC f for Option+Left/Right, and many Linux
terminals send modified CSI arrows (ESC [ 1;3 D, 1;5 C, ...). Both now move
the cursor by whole words, and ESC DEL (Option+Backspace) deletes the previous
word. Words are whitespace-delimited and the motion steps over folded pastes
and multibyte characters as single units.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pierrei pierrei changed the title Jump by word with Option/Alt/Ctrl+arrows, delete a word with Option+Backspace Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant