diff options
author | Jonathan Slenders <jonathan@slenders.be> | 2016-06-10 20:15:42 +0200 |
---|---|---|
committer | Jonathan Slenders <jonathan@slenders.be> | 2016-06-10 20:15:42 +0200 |
commit | da1ab5f43b06c5b8665039d3218ea8e589ad0e7d (patch) | |
tree | 473fad44e321bff4cf3b0ca47c5bdee1a2fb1119 | |
parent | 8f68f4065387fda111879de6aa7bbd32ddd5eaa4 (diff) |
Implemented Vi 'gJ' key binding.
-rw-r--r-- | prompt_toolkit/buffer.py | 8 | ||||
-rw-r--r-- | prompt_toolkit/key_binding/bindings/vi.py | 15 |
2 files changed, 17 insertions, 6 deletions
diff --git a/prompt_toolkit/buffer.py b/prompt_toolkit/buffer.py index 29dac079..994876de 100644 --- a/prompt_toolkit/buffer.py +++ b/prompt_toolkit/buffer.py @@ -577,7 +577,7 @@ class Buffer(object): else: return '' - def join_next_line(self): + def join_next_line(self, separator=' '): """ Join the next line to the current one by deleting the line ending after the current line. @@ -587,10 +587,10 @@ class Buffer(object): self.delete() # Remove spaces. - self.text = (self.document.text_before_cursor + ' ' + + self.text = (self.document.text_before_cursor + separator + self.document.text_after_cursor.lstrip(' ')) - def join_selected_lines(self): + def join_selected_lines(self, separator=' '): """ Join the selected lines. """ @@ -604,7 +604,7 @@ class Buffer(object): after = self.text[to:] # Replace leading spaces with just one space. - lines = [l.lstrip(' ') + ' ' for l in lines] + lines = [l.lstrip(' ') + separator for l in lines] # Set new document. self.document = Document(text=before + ''.join(lines) + after, diff --git a/prompt_toolkit/key_binding/bindings/vi.py b/prompt_toolkit/key_binding/bindings/vi.py index 2c61ed13..07b0c9b2 100644 --- a/prompt_toolkit/key_binding/bindings/vi.py +++ b/prompt_toolkit/key_binding/bindings/vi.py @@ -395,15 +395,26 @@ def load_vi_bindings(registry, enable_visual_key=Always(), @handle('J', filter=navigation_mode & ~IsReadOnly()) def _(event): - """ Join lines. """ + " Join lines. " for i in range(event.arg): event.current_buffer.join_next_line() + @handle('g', 'J', filter=navigation_mode & ~IsReadOnly()) + def _(event): + " Join lines without space. " + for i in range(event.arg): + event.current_buffer.join_next_line(separator='') + @handle('J', filter=selection_mode & ~IsReadOnly()) def _(event): - """ Join selected lines. """ + " Join selected lines. " event.current_buffer.join_selected_lines() + @handle('g', 'J', filter=selection_mode & ~IsReadOnly()) + def _(event): + " Join selected lines without space. " + event.current_buffer.join_selected_lines(separator='') + @handle('n', filter=navigation_mode) def _(event): # XXX: use `text_object` """ |