Skip to content

Commit

Permalink
add sublime_meow.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tianshu committed Oct 16, 2021
1 parent 8e23eb0 commit 3d4ba1e
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
27 changes: 27 additions & 0 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{"keys": ["i"], "command": "insert_mode", "context": [{"key": "setting.command_mode"}]},
{"keys": ["a"], "command": "insert_mode_append", "context": [{"key": "setting.command_mode"}]},

// character movements
{"keys": ["h"], "command": "move", "context": [{"key": "setting.command_mode"}],
"args": {"by": "characters", "forward": false}},
{"keys": ["t"], "command": "move", "context": [{"key": "setting.command_mode"}],
"args": {"by": "characters", "forward": true}},
{"keys": ["p"], "command": "move", "context": [{"key": "setting.command_mode"}],
"args": {"by": "lines", "forward": false}},
{"keys": ["n"], "command": "move", "context": [{"key": "setting.command_mode"}],
"args": {"by": "lines", "forward": true}},

// character expand
{"keys": ["H"], "command": "move", "context": [{"key": "setting.command_mode"}],
"args": {"by": "characters", "forward": false, "extend": true}},
{"keys": ["T"], "command": "move", "context": [{"key": "setting.command_mode"}],
"args": {"by": "characters", "forward": true, "extend": true}},
{"keys": ["P"], "command": "move", "context": [{"key": "setting.command_mode"}],
"args": {"by": "lines", "forward": false, "extend": true}},
{"keys": ["N"], "command": "move", "context": [{"key": "setting.command_mode"}],
"args": {"by": "lines", "forward": true, "extend": true}},

// escape
{"keys": ["escape"], "command": "command_mode", "context": [{"key": "setting.is_widget", "operator": "equal", "operand": false}]}
]
4 changes: 4 additions & 0 deletions Preferences.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"block_caret": true,
"command_mode": true,
}
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# sublime-meow
Modal Editing on Sublime Text 4

![Logo](meow-subl.svg)
![Logo](meow-subl.svg)

# Development Guide

Link this project to `~/.config/sublime-text/Packages/`.

Sublime will reload plugins automatically after you make any changes.
4 changes: 4 additions & 0 deletions Widget.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"command_mode": false,
"block_caret": false,
}
39 changes: 39 additions & 0 deletions sublime_meow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sublime
import sublime_plugin

class InsertModeCommand(sublime_plugin.TextCommand):
"""
Switch to INSERT mode, put carets at the start of each selection.
"""
def run(self, edit):
buf = self.view
if buf.is_read_only():
sublime.status_message('Buffer is read only')
return

buf.settings().set(key='block_caret', value=False)
buf.settings().set(key='command_mode', value=False)

class InsertModeAppendCommand(sublime_plugin.TextCommand):
"""
Switch to INSERT mode, put carets at the end of each selection.
"""
def run(self, edit):
buf = self.view
if buf.is_read_only():
sublime.status_message('Buffer is read only')
return

self.view.run_command("move", {"by": "characters", "forward": True})

buf.settings().set(key='block_caret', value=False)
buf.settings().set(key='command_mode', value=False)

class CommandModeCommand(sublime_plugin.TextCommand):
"""
Switch to COMMAND mode.
"""
def run(self, edit):
buf = self.view
buf.settings().set(key='block_caret', value=True)
buf.settings().set(key='command_mode', value=True)

0 comments on commit 3d4ba1e

Please sign in to comment.