@@ -54,6 +54,7 @@ def forward_word(cursor_offset, line):
5454
5555@on ('b' )
5656@on ('\x1b OD' )
57+ @on ('\x1b B' )
5758def back_word (cursor_offset , line ):
5859 return (last_word_pos (line [:cursor_offset ]), line )
5960
@@ -91,21 +92,30 @@ def delete_from_cursor_back(cursor_offset, line):
9192def delete_from_cursor_forward (cursor_offset , line ):
9293 return cursor_offset , line [:cursor_offset ]
9394
94- @on ('d' )
95+ @on ('d' ) # option-d
9596def delete_rest_of_word (cursor_offset , line ):
96- raise NotImplementedError ()
97+ m = re .search (r'\w\b' , line [cursor_offset :])
98+ if not m :
99+ return cursor_offset , line
100+ return cursor_offset , line [:cursor_offset ] + line [m .start ()+ cursor_offset + 1 :]
97101
98102@on ('' )
99103def delete_word_to_cursor (cursor_offset , line ):
100- raise NotImplementedError ()
104+ matches = list (re .finditer (r'\s\S' , line [:cursor_offset ]))
105+ start = matches [- 1 ].start ()+ 1 if matches else 0
106+ return start , line [:start ] + line [cursor_offset :]
101107
102108@on ('y' )
103109def yank_prev_prev_killed_text (cursor_offset , line ):
104110 raise NotImplementedError ()
105111
106112@on ('' )
107113def transpose_character_before_cursor (cursor_offset , line ):
108- raise NotImplementedError ()
114+ return (min (len (line ), cursor_offset + 1 ),
115+ line [:cursor_offset - 1 ] +
116+ (line [cursor_offset ] if len (line ) > cursor_offset else '' ) +
117+ line [cursor_offset - 1 ] +
118+ line [cursor_offset + 1 :])
109119
110120@on ('t' )
111121def transpose_word_before_cursor (cursor_offset , line ):
@@ -116,7 +126,13 @@ def transpose_word_before_cursor(cursor_offset, line):
116126@on ('\x1b \x7f ' )
117127@on ('\xff ' )
118128def delete_word_from_cursor_back (cursor_offset , line ):
119- raise NotImplementedError ()
129+ """Whatever my option-delete does in bash on my mac"""
130+ if not line :
131+ return cursor_offset , line
132+ starts = [m .start () for m in list (re .finditer (r'\b\w' , line )) if m .start () < cursor_offset ]
133+ if starts :
134+ return starts [- 1 ], line [:starts [- 1 ]] + line [cursor_offset :]
135+ return cursor_offset , line
120136
121137def get_updated_char_sequences (key_dispatch , config ):
122138 updated_char_sequences = dict (char_sequences )
0 commit comments