File tree Expand file tree Collapse file tree
prompt_toolkit/key_binding/bindings Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,8 +58,8 @@ def _(event):
5858 handle (Keys .Escape , 'l' , filter = insert_mode )(get_by_name ('downcase-word' ))
5959 handle (Keys .Escape , 'u' , filter = insert_mode )(get_by_name ('uppercase-word' ))
6060 handle (Keys .Escape , 'y' , filter = insert_mode )(get_by_name ('yank-pop' ))
61- handle (Keys .Escape , Keys .ControlH , filter = insert_mode )(get_by_name ('unix-word-rubout ' ))
62- handle (Keys .Escape , Keys .Backspace , filter = insert_mode )(get_by_name ('unix-word-rubout ' ))
61+ handle (Keys .Escape , Keys .ControlH , filter = insert_mode )(get_by_name ('backward-kill-word ' ))
62+ handle (Keys .Escape , Keys .Backspace , filter = insert_mode )(get_by_name ('backward-kill-word ' ))
6363 handle (Keys .Escape , '\\ ' , filter = insert_mode )(get_by_name ('delete-horizontal-space' ))
6464
6565 handle (Keys .ControlUnderscore , save_before = (lambda e : False ), filter = insert_mode )(
Original file line number Diff line number Diff line change @@ -302,13 +302,13 @@ def kill_word(event):
302302
303303
304304@register ('unix-word-rubout' )
305- @register ('backward-kill-word' ) # XXX: backward-kill-word is actually slightly different.
306- def unix_word_rubout (event ):
305+ def unix_word_rubout (event , WORD = True ):
307306 """
308- Kill the word behind point. Word boundaries are the same as backward-word.
307+ Kill the word behind point, using whitespace as a word boundary.
308+ Usually bound to ControlW.
309309 """
310310 buff = event .current_buffer
311- pos = buff .document .find_start_of_previous_word (count = event .arg )
311+ pos = buff .document .find_start_of_previous_word (count = event .arg , WORD = WORD )
312312
313313 if pos is None :
314314 # Nothing found? delete until the start of the document. (The
@@ -330,6 +330,15 @@ def unix_word_rubout(event):
330330 event .cli .output .bell ()
331331
332332
333+ @register ('backward-kill-word' )
334+ def backward_kill_word (event ):
335+ """
336+ Kills the word before point, using “not a letter nor a digit” as a word boundary.
337+ Usually bound to M-Del or M-Backspace.
338+ """
339+ unix_word_rubout (event , WORD = False )
340+
341+
333342@register ('delete-horizontal-space' )
334343def delete_horizontal_space (event ):
335344 " Delete all spaces and tabs around point. "
Original file line number Diff line number Diff line change @@ -252,14 +252,30 @@ def test_emacs_other_bindings():
252252 result , cli = _feed_cli_with_input ('hello\x1b [D\x1b [D\x15 X\n ' )
253253 assert result .text == 'Xlo'
254254
255- # Delete word before the cursor.
255+ # unix-word-rubout: delete word before the cursor.
256+ # (ControlW).
256257 result , cli = _feed_cli_with_input ('hello world test\x17 X\n ' )
257258 assert result .text == 'hello world X'
258259
260+ result , cli = _feed_cli_with_input ('hello world /some/very/long/path\x17 X\n ' )
261+ assert result .text == 'hello world X'
262+
259263 # (with argument.)
260264 result , cli = _feed_cli_with_input ('hello world test\x1b 2\x17 X\n ' )
261265 assert result .text == 'hello X'
262266
267+ result , cli = _feed_cli_with_input ('hello world /some/very/long/path\x1b 2\x17 X\n ' )
268+ assert result .text == 'hello X'
269+
270+ # backward-kill-word: delete word before the cursor.
271+ # (Esc-ControlH).
272+ result , cli = _feed_cli_with_input ('hello world /some/very/long/path\x1b \x08 X\n ' )
273+ assert result .text == 'hello world /some/very/long/X'
274+
275+ # (with arguments.)
276+ result , cli = _feed_cli_with_input ('hello world /some/very/long/path\x1b 3\x1b \x08 X\n ' )
277+ assert result .text == 'hello world /some/very/X'
278+
263279
264280def test_controlx_controlx ():
265281 # At the end: go to the start of the line.
You can’t perform that action at this time.
0 commit comments