diff --git a/pyvim/commands/commands.py b/pyvim/commands/commands.py index def2a59..20a6c47 100644 --- a/pyvim/commands/commands.py +++ b/pyvim/commands/commands.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals, print_function from prompt_toolkit.application import run_in_terminal +from prompt_toolkit.document import Document import os import six @@ -408,6 +409,18 @@ def pwd(editor): editor.show_message('{}'.format(directory)) +@cmd('delete-trailing-whitespace') +def delete_trailing_whitespace(editor): + buffer = editor.current_editor_buffer.buffer + l = [] + for line in buffer.text.splitlines(): + l.append(line.rstrip()) + buffer.document = Document( + text='\n'.join(l), + cursor_position=buffer.document.cursor_position + ) + + @location_cmd('cd', accepts_force=False) def pwd(editor, location): " Change working directory. "