A small plugin to expand/contract selections by one character to the left or/and to the right.
[code]import sublime
import sublime_plugin
class ExpandSelectionCustomCommand(sublime_plugin.TextCommand):
def run(self, edit, expand, right=False, left=False):
sels = ]
viewsize = self.view.size()
inc = 1 if expand else -1
for sel in self.view.sel():
a = sel.a
b = sel.b
if not (sel.size() == 0 and not expand):
if right:
if sel.b >= sel.a:
b = sel.b+inc
else:
a = sel.a+inc
if left:
if sel.b > sel.a:
a = sel.a-inc
else:
b = sel.b-inc
sels.append(sublime.Region(
min(max(a, 0), viewsize),
min(max(b, 0), viewsize), sel.xpos()))
self.view.sel().clear()
for sel in sels:
self.view.sel().add(sel)[/code]
{ "keys": "shift+ctrl+super+right"], "command": "expand_selection_custom", "args": {"expand": true, "right": true} },
{ "keys": "shift+ctrl+super+left"], "command": "expand_selection_custom", "args": {"expand": true, "left": true} },
{ "keys": "alt+shift+ctrl+super+right"], "command": "expand_selection_custom", "args": {"expand": false, "left": true} },
{ "keys": "alt+shift+ctrl+super+left"], "command": "expand_selection_custom", "args": {"expand": false, "right": true} },
{ "keys": "shift+ctrl+super+up"], "command": "expand_selection_custom", "args": {"expand": true, "left": true, "right": true} },
{ "keys": "alt+shift+ctrl+super+up"], "command": "expand_selection_custom", "args": {"expand": false, "left": true, "right": true} },