Last active
May 22, 2021 11:38
-
-
Save ddlsmurf/11211940 to your computer and use it in GitHub Desktop.
Simple sublime text 2 multiple cursor alignment command #tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin, re | |
class AlignCursors(sublime_plugin.TextCommand): | |
def adjust_column_for_tabs(self, view, tab_size, region, rowcol): | |
line_text = view.substr(view.line(region))[:rowcol[1]] | |
return rowcol[1] + (line_text.count("\t") * (tab_size - 1)) | |
def run(self, edit): | |
view = self.view | |
regions = view.sel() | |
right_most = 0 | |
cursors = 0 | |
tab_size = int(view.settings().get('tab_size', 8)) | |
lines = set() | |
if len(regions) < 2: | |
sublime.error_message("Error: Must have more than one cursor active") | |
for region in regions: | |
if not region.empty(): | |
sublime.error_message("Error: Must have no content selected") | |
return | |
rowcol = view.rowcol(region.begin()) | |
if rowcol[0] in lines: | |
sublime.error_message("Error: Cannot have more than one cursor per line (line %i has more)" % (rowcol[0] + 1)) | |
return | |
lines = lines | set([rowcol[0]]) | |
col = self.adjust_column_for_tabs(view, tab_size, region, rowcol) | |
if col > right_most: | |
right_most = col | |
for region in regions: | |
rowcol = view.rowcol(region.begin()) | |
col = self.adjust_column_for_tabs(view, tab_size, region, rowcol) | |
if col < right_most: | |
view.insert(edit, region.begin(), ''.join([' '] * (right_most - rowcol[1]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
[ | |
{ "keys": ["ctrl+alt+]"], "command": "align_cursors" } | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment