From 2630342d811beb6af3726b3482beea894e06f8b1 Mon Sep 17 00:00:00 2001 From: Rootiest Date: Mon, 21 Sep 2026 19:06:59 -0400 Subject: [PATCH 1/2] feat(keybind): recall last history entry on empty prompt for ctrl-alt-u --- functions/_replace_command_token.fish | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/functions/_replace_command_token.fish b/functions/_replace_command_token.fish index b8a4f3a..50c3b40 100644 --- a/functions/_replace_command_token.fish +++ b/functions/_replace_command_token.fish @@ -7,7 +7,9 @@ # DESCRIPTION # Removes the first command token from the commandline buffer and # positions the cursor for immediate replacement. If the command starts -# with sudo, preserves sudo and removes the token after it instead. +# with sudo, preserves sudo and removes the token after it instead. If +# the commandline is empty, first recalls the most recent history entry +# (like pressing Up) before doing the token replacement on it. # Intended to be bound to a key in key_bindings.fish. # # EXAMPLE @@ -15,6 +17,12 @@ function _replace_command_token --description 'Remove first command token (or first after sudo) and place cursor for replacement' set -l cmd (commandline) + # Empty prompt: recall the last history entry first, same as it would + # behave if that command were already on the commandline. + if string match -rq '^\s*$' -- "$cmd" + set cmd (history --max 1) + end + # 1. Logic for commands starting with sudo if string match -rq '^sudo\s+' -- "$cmd" # regex explanation: From e4df160fc01a0dd969b5b4b9a15de8e4484c1686 Mon Sep 17 00:00:00 2001 From: Rootiest Date: Mon, 21 Sep 2026 19:07:02 -0400 Subject: [PATCH 2/2] docs(key-bindings): document ctrl-alt-u empty-prompt history recall --- docs/manual/03-key-bindings.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/manual/03-key-bindings.md b/docs/manual/03-key-bindings.md index 711905c..c5d6141 100644 --- a/docs/manual/03-key-bindings.md +++ b/docs/manual/03-key-bindings.md @@ -29,8 +29,11 @@ are active in Insert, Normal, and Visual modes unless noted. Ctrl+Alt+U Strip the first token of the current command line, leaving arguments in place with the cursor at the - start. Useful for quickly retyping the command. + start. Useful for quickly retyping the command. On + an empty command line, first recalls the most recent + history entry (like Up), then strips its first token. Example: "mkdir new_folder" -> " new_folder" + Example: empty line after "cd /home/me" -> " /home/me" Ctrl+Alt+= Evaluate the current command line buffer with Qalculate! (qalc) and print the result inline.