From 4f5ed8ace0a6d63585e260db3ac6d324a9af8f15 Mon Sep 17 00:00:00 2001 From: "Matteo Landi (aider)" Date: Wed, 26 Mar 2025 08:42:58 +0100 Subject: [PATCH 1/2] feat: Add C-x C-e keybinding to edit input in external editor --- aider/io.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/aider/io.py b/aider/io.py index 9ebff252b..d4d8205af 100644 --- a/aider/io.py +++ b/aider/io.py @@ -35,6 +35,7 @@ from rich.text import Text from aider.mdstream import MarkdownStream from .dump import dump # noqa: F401 +from .editor import pipe_editor from .utils import is_image_file # Constants @@ -556,6 +557,18 @@ class InputOutput: def _(event): "Navigate forward through history" event.current_buffer.history_forward() + + @kb.add("c-x", "c-e") + def _(event): + "Edit current input in external editor (like Bash)" + buffer = event.current_buffer + current_text = buffer.text + + # Open the editor with the current text + edited_text = pipe_editor(input_data=current_text) + + # Replace the buffer with the edited text + buffer.text = edited_text @kb.add("enter", eager=True, filter=~is_searching) def _(event): From 79246575844c6e545c7c1936e7ef12445e692a23 Mon Sep 17 00:00:00 2001 From: "Matteo Landi (aider)" Date: Thu, 27 Mar 2025 10:35:03 +0100 Subject: [PATCH 2/2] feat: Improve C-x C-e editor keybinding to handle cursor and newline --- aider/io.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aider/io.py b/aider/io.py index d4d8205af..053f739db 100644 --- a/aider/io.py +++ b/aider/io.py @@ -567,8 +567,11 @@ class InputOutput: # Open the editor with the current text edited_text = pipe_editor(input_data=current_text) - # Replace the buffer with the edited text - buffer.text = edited_text + # Replace the buffer with the edited text, strip any trailing newlines + buffer.text = edited_text.rstrip('\n') + + # Move cursor to the end of the text + buffer.cursor_position = len(buffer.text) @kb.add("enter", eager=True, filter=~is_searching) def _(event):