forked from tgrosinger/aenea-grammars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_vim.py
168 lines (142 loc) · 4.87 KB
/
_vim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Created for aenea using libraries from the Dictation Toolbox
# https://github.com/dictation-toolbox/dragonfly-scripts
#
# Commands for interacting with Vim
#
# Author: Tony Grosinger
#
# Licensed under LGPL
import aenea
import aenea.configuration
from aenea.lax import Key, Function
from aenea import (
Dictation,
IntegerRef,
Text,
Choice
)
import dragonfly
from _generic_edit import pressKeyMap
vim_context = aenea.ProxyCustomAppContext(executable="gnome-terminal")
grammar = dragonfly.Grammar('vim', context=vim_context)
surroundCharsMap = {
'quotes': '"',
'parens': "(",
'brackets': "[",
'braces': "{",
}
def goto_line(n):
for c in str(n):
Key(c).execute()
Key("G").execute()
def yank_lines(n, n2):
goto_line(n)
Key("V").execute()
goto_line(n2)
Key("y").execute()
def delete_lines(n, n2):
goto_line(n)
Key("V").execute()
goto_line(n2)
Key("d").execute()
basics_mapping = aenea.configuration.make_grammar_commands('vim', {
'vim': Text("vim"),
# Moving between splits
'win-left': Key("escape, c-h"),
'win-right': Key("escape, c-l"),
'win-up': Key("escape, c-k"),
'win-down': Key("escape, c-j"),
'win-close': Key("escape, colon, q, enter"),
'open [in] split': Key("s"),
'open [in] tab': Key("t"),
# Moving viewport
'bund': Key("escape, 2, 0, c-y"),
'fund': Key("escape, 2, 0, c-e"),
'screen down': Key("escape, c-f"),
'screen up': Key("escape, c-b"),
# Append to line
'noop <n>': Key("escape") + Function(goto_line) + Key("A, enter"),
'noop': Key("escape, A, enter"),
'nope': Key("escape, A"),
'nope <n>': Key("escape") + Function(goto_line) + Key("A"),
'prepend': Key("escape, I"),
'insert': Key("i"),
'insert below': Key("escape, o"),
'insert above': Key("escape, O"),
'undo': Key("escape, u, i"),
'scratch': Key("escape, u, i"),
'escape': Key("escape"),
'filename': Key("escape, c-g"),
'save': Key("escape, colon, w, enter"),
'save and quit': Key("escape, colon, w, q, enter"),
'quit all': Key("escape, colon, q, a, enter"),
'discard': Key("colon, q, exclamation"),
'tab <n>': Key("escape, comma, %(n)d"),
'comma': Key("comma"),
'comes': Key("comma, space"),
'listed': Key("escape, s-a, comma, enter"),
'cause': Key("colon, space"),
# Finding text
'find <text>': Key("escape, slash") + Text("%(text)s") + Key("enter"),
'next': Key("n"),
'prev|previous': Key("N"),
'clear search': Key("escape, colon, n, o, h, enter"),
# Character operations
'dart': Key("x"),
'dart <n>': Key("x:%(n)d"),
'replace letter': Key("r"),
'replace mode': Key("R"),
'change case': Key("escape, right, s-backtick, i, left"),
'change case back': Key("escape, b, s-backtick, e, a"),
# Word operations
'doord': Key("right, escape, d, i, w, i"),
'doord back': Key("right, escape, b, d, w, i"),
'doord <n>': Key("right, escape, %(n)d, d, w, i"),
'doord back <n>': Key("right, escape, %(n)d, b, %(n)d, d, w, i"),
'chord': Key("right, escape, c, i, w"),
'chord <n>': Key("escape, right, c, %(n)d, w"),
'sword': Key("escape, right, v, e"),
'sword <n>': Key("escape, right, v, e:%(n)d"),
'forward': Key("escape, right, w, i"),
'forward <n>': Key("escape, right, %(n)d, w, i"),
'backward': Key("escape, b, i"),
'backward <n>': Key("escape, %(n)d, b, i"),
'stripword': Key("escape, b, left, del, e, a"),
# Line operations
'dine': Key("escape, d:2"),
'dine <n>': Key("escape") + Function(goto_line) + Key("d:2"),
'dine <n> (thru|through|to) <n2>': Key("escape") + Function(delete_lines),
'yine': Key("escape, y:2"),
'yine <n>': Key("escape") + Function(goto_line) + Key("y:2"),
'yine <n> (thru|through|to) <n2>': Key("escape") + Function(yank_lines),
'select until <pressKey>': Key("escape, v, t") + Text("%(pressKey)s"),
'select including <pressKey>': Key("escape, v, f") + Text("%(pressKey)s"),
'dell until <pressKey>': Key("escape, d, t") + Text("%(pressKey)s"),
'dell including <pressKey>': Key("escape, d, f") + Text("%(pressKey)s"),
# Copy and Paste
'yank': Key("y"),
'extract': Key("x"),
'glue': Key('escape, p'),
# Movement
'up <n> (lines|line)': Key("%(n)d, up"),
'down <n> (lines|line)': Key("%(n)d, down"),
'go to [line] <n>': Key("escape") + Function(goto_line),
'matching': Key("escape, percent"),
'(boop|easy motion)': Key("escape, comma, comma, s"),
})
class Basics(dragonfly.MappingRule):
mapping = basics_mapping
extras = [
Dictation('text'),
IntegerRef('n', 1, 999),
IntegerRef('n2', 1, 999),
Choice("pressKey", pressKeyMap),
Choice("surroundChar", surroundCharsMap),
]
grammar.add_rule(Basics())
grammar.load()
def unload():
global grammar
if grammar:
grammar.unload()
grammar = None