Skip to content

Instantly share code, notes, and snippets.

@patrickhulce
Created April 11, 2014 20:01
Show Gist options
  • Save patrickhulce/10497055 to your computer and use it in GitHub Desktop.
Save patrickhulce/10497055 to your computer and use it in GitHub Desktop.
Sublime Home/End Fix OS X
[{
"keys": ["ctrl+a"],
"command": "move_cursor_beginning"
}, {
"keys": ["shift+ctrl+a"],
"command": "select_to_beginning"
}]
import sublime, sublime_plugin, re
class move_cursor_beginning(sublime_plugin.TextCommand):
def run(self, edit):
sel = self.view.sel()
current_line_pos = self.view.line(sel[0].begin())
current_line_text = self.view.substr(current_line_pos)
num_whitespace = re.search(r'^(\s+)', current_line_text)
if num_whitespace is None:
return
target = current_line_pos.begin() + len(num_whitespace.group(0))
self.view.sel().clear()
self.view.sel().add(sublime.Region(target,target))
class select_to_beginning(sublime_plugin.TextCommand):
def run(self, edit):
sel = self.view.sel()
end_pos = sel[0].end()
current_line_pos = self.view.line(sel[0].begin())
current_line_text = self.view.substr(current_line_pos)
num_whitespace = re.search(r'^(\s+)', current_line_text)
if num_whitespace is None:
return
target = current_line_pos.begin() + len(num_whitespace.group(0))
self.view.sel().clear()
self.view.sel().add(sublime.Region(target,end_pos))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment