Home Download Buy Blog Forum Support

move_to_beg_of_contig_boundary - Move to Contiguous Boundary

move_to_beg_of_contig_boundary - Move to Contiguous Boundary

Postby robertcollier4 on Sun Mar 17, 2013 11:59 am

I realized that I don't like the default behavior of ctrl+left/ctrl+right - and wanted to try programming my own behavior. What I prefer is to use Ctrl to move between contiguous boundaries (boundaries are found from where whitespaces occur). After that, I use alt+left/alt+right to move by "subwords" to then find my location precisely within a contiguous boundary.

Here are the recommended key bindings. This will use Ctrl to move between contiguous boundaries to do the broad strokes and Alt to move between subwords to do the fine strokes:
Code: Select all
{ "keys": ["ctrl+left"], "command": "move_to_beg_of_contig_boundary", "args": {"forward": false} },
{ "keys": ["ctrl+right"], "command": "move_to_beg_of_contig_boundary", "args": {"forward": true} },
{ "keys": ["ctrl+shift+left"], "command": "move_to_beg_of_contig_boundary", "args": {"forward": false, "extend": true} },
{ "keys": ["ctrl+shift+right"], "command": "move_to_beg_of_contig_boundary", "args": {"forward": true, "extend": true} },

{ "keys": ["alt+left"], "command": "move", "args": {"by": "subwords", "forward": false} },
{ "keys": ["alt+right"], "command": "move", "args": {"by": "subword_ends", "forward": true} },
{ "keys": ["alt+shift+left"], "command": "move", "args": {"by": "subwords", "forward": false, "extend": true} },
{ "keys": ["alt+shift+right"], "command": "move", "args": {"by": "subword_ends", "forward": true, "extend": true} },


move_to_beg_of_contig_boundary.py:
Code: Select all
import sublime, sublime_plugin, string

class MoveToBegOfContigBoundaryCommand(sublime_plugin.TextCommand):
   def run(self, edit, forward, extend=False):
      view = self.view
      oldSelRegions = list(view.sel())
      view.sel().clear()
      for thisregion in oldSelRegions:
         if(forward): #forward
            caretPos = thisregion.b
            if(view.substr(caretPos) not in string.whitespace): #initially have char right of me, find whitespace
               while ((view.substr(caretPos) not in string.whitespace) and (caretPos < view.size())):
                  caretPos += 1
            while((view.substr(caretPos) in string.whitespace) and (caretPos < view.size())): #now have whitespace right of me, find char beginning
               caretPos += 1
            if(extend):
               view.sel().add(sublime.Region(thisregion.a, caretPos))
               view.show(caretPos)
            else:
               view.sel().add(sublime.Region(caretPos))
               view.show(caretPos)
         else: #backward
            caretPos = thisregion.b - 1
            if(view.substr(caretPos) in string.whitespace): #initially have whitespace left of me, find char
               while ((view.substr(caretPos) in string.whitespace) and (caretPos >= 0)):
                  caretPos -= 1
            while ((view.substr(caretPos) not in string.whitespace) and (caretPos >= 0)): #now have char left of me, find whitespace
               caretPos -= 1
            if(extend):
               view.sel().add(sublime.Region(thisregion.a, caretPos+1))
               view.show(caretPos+1)
            else:
               view.sel().add(sublime.Region(caretPos+1))
               view.show(caretPos+1)
robertcollier4
 
Posts: 153
Joined: Sun Feb 24, 2013 5:37 pm

Return to Plugin Announcements

Who is online

Users browsing this forum: Google [Bot] and 11 guests

cron