Seth Urquhart
Seth Urquhart

Reputation: 599

Delete extra spaces in list items - Sublime Text 2

Example:

Sometimes I need to put tags at the end of a list item using the shortcut: [Ctr] + [Shift] + [L] + [End] to edit multiple list items using multiple cursors. This doesn't always work so well when there are extra spaces at the end of a list item, making tha actual end of the item a few spaces longer than the text of the item.

Is there a shortcut I can use along with [Ctr] + [Shift] + [L] to delete those extra spaces and essentially make the "end" where the text ends?

Please ask questions if you need clarification on my question and I will try to best make it most clear.

Upvotes: 0

Views: 1440

Answers (2)

skuroda
skuroda

Reputation: 19744

If you don't want to delete the spaces, you can rebind the end key to a plugin that modifies the behavior. I wrote this when I was playing around with some virtual white space stuff, so it's only minimally tested (link). Save it to Packages/User. The name of the file doesn't matter, just make sure it has the .py extension. Then, add the following as a custom key binding.

{
    "keys": ["end"], "command": "custom_move_to_end_line"                              
}

Upvotes: 0

longhua
longhua

Reputation: 4242

I haven't found shortcuts for this. So I wrote one. It will trim the trailing white spaces of the current line. For example, after you enter ctrl+shift+l, you find that there are extra white spaces, enter ctrl+f and then ctrl+t to delete them. White spaces in other line won't be affected.

Key mapping:

{ "keys": ["ctrl+f", "ctrl+t"], "command": "delete_trailing_white_space" }

delete_trailing_white_space.py (put it Sublime Text 2\Packages\User)

import sublime
import sublime_plugin

class DeleteTrailingWhiteSpaceCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        for region in self.view.sel():
            line = self.view.line(region)
            line_content = self.view.substr(line)
            trimed_line = line_content.rstrip()
            self.view.replace(edit, line, trimed_line)

Upvotes: 2

Related Questions