From 085586fbc2c1937b091125ec17430e91ddf5be83 Mon Sep 17 00:00:00 2001 From: Slack System Date: Thu, 20 Nov 2025 16:35:59 -0500 Subject: [PATCH] Don't add newline when pasting into empty buffer - In the vi key bindings, when pasting text after the cursor in an empty buffer, a leading newline character was being added. This change removes that newline when pasting into an empty buffer. --- src/prompt_toolkit/key_binding/bindings/vi.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/prompt_toolkit/key_binding/bindings/vi.py b/src/prompt_toolkit/key_binding/bindings/vi.py index d68a31f29..86409afae 100644 --- a/src/prompt_toolkit/key_binding/bindings/vi.py +++ b/src/prompt_toolkit/key_binding/bindings/vi.py @@ -776,11 +776,16 @@ def _paste(event: E) -> None: """ Paste after """ + old_buffer_text = event.current_buffer.text event.current_buffer.paste_clipboard_data( event.app.clipboard.get_data(), count=event.arg, paste_mode=PasteMode.VI_AFTER, ) + if not old_buffer_text and event.current_buffer.text.startswith("\n"): + # Special case: when pasting into an empty buffer, remove the + # leading newline that gets added by the VI_AFTER paste mode. + event.current_buffer.text = event.current_buffer.text[1:] @handle("P", filter=vi_navigation_mode) def _paste_before(event: E) -> None: