vimamsa 0.1.27 → 0.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/appimage.yml +17 -10
- data/Dockerfile +2 -2
- data/README.md +162 -90
- data/custom_example.rb +33 -15
- data/doc/TODO.md +334 -110
- data/doc/action_names_plan.md +442 -0
- data/doc/bundling_plan.md +2 -1
- data/doc/delta_syntax_plan.md +293 -0
- data/doc/demo_recording_plan.md +288 -0
- data/doc/design_goals.md +27 -0
- data/doc/intro_page_plan.md +266 -0
- data/doc/key_bindings_report_plan.md +45 -0
- data/doc/line_tree_plan.md +89 -0
- data/doc/missing_vim_bindings.md +34 -44
- data/doc/modules_settings_plan.md +1 -1
- data/doc/registries_plan.md +202 -0
- data/doc/startup_speed_plan.md +97 -0
- data/doc/test_commands.md +232 -0
- data/doc/treap_visualizer.html +585 -0
- data/doc/vim_compatibility_plan.md +186 -31
- data/doc/vimlike_vim_conflicts.md +236 -228
- data/doc/vm_snapshots_plan.md +4 -4
- data/doc/wysiwyg_plan.md +231 -0
- data/docker_cmd.sh +1 -1
- data/exe/run_tests.rb +85 -3
- data/exe/vimamsa +49 -6
- data/help/intro.txt +30 -0
- data/help/vim_intro.txt +31 -0
- data/img/demo.gif +0 -0
- data/img/demo.mp4 +0 -0
- data/lang/hyperplaintext.lang +1 -1
- data/lib/vimamsa/ack.rb +2 -0
- data/lib/vimamsa/actions.rb +381 -36
- data/lib/vimamsa/bookmarks.rb +8 -8
- data/lib/vimamsa/buffer.rb +84 -38
- data/lib/vimamsa/buffer_changetext.rb +58 -36
- data/lib/vimamsa/buffer_list.rb +2 -2
- data/lib/vimamsa/buffer_manager.rb +6 -6
- data/lib/vimamsa/cli_help.rb +75 -0
- data/lib/vimamsa/clipboard.rb +6 -3
- data/lib/vimamsa/conf.rb +9 -0
- data/lib/vimamsa/crash_handler.rb +2 -2
- data/lib/vimamsa/debug.rb +2 -2
- data/lib/vimamsa/demo_player.rb +494 -0
- data/lib/vimamsa/demo_recorder.rb +277 -0
- data/lib/vimamsa/diff_buffer.rb +1 -1
- data/lib/vimamsa/dot_repeat.rb +104 -0
- data/lib/vimamsa/easy_jump.rb +54 -3
- data/lib/vimamsa/editor.rb +136 -65
- data/lib/vimamsa/file_history.rb +1 -1
- data/lib/vimamsa/file_manager.rb +23 -23
- data/lib/vimamsa/form_input.rb +388 -0
- data/lib/vimamsa/gui.rb +89 -13
- data/lib/vimamsa/gui_command_line.rb +44 -5
- data/lib/vimamsa/gui_form_generator.rb +17 -6
- data/lib/vimamsa/gui_func_panel.rb +1 -1
- data/lib/vimamsa/gui_key_hint.rb +165 -0
- data/lib/vimamsa/gui_keylog_panel.rb +164 -2
- data/lib/vimamsa/gui_menu.rb +69 -50
- data/lib/vimamsa/gui_select_window.rb +77 -43
- data/lib/vimamsa/gui_settings.rb +9 -5
- data/lib/vimamsa/gui_sourceview.rb +28 -81
- data/lib/vimamsa/gui_theme.rb +11 -2
- data/lib/vimamsa/hook.rb +2 -0
- data/lib/vimamsa/intro_page.rb +367 -0
- data/lib/vimamsa/key_actions.rb +315 -225
- data/lib/vimamsa/key_binding_tree.rb +228 -61
- data/lib/vimamsa/key_bindings_notepad.rb +18 -16
- data/lib/vimamsa/key_bindings_report.rb +290 -67
- data/lib/vimamsa/key_bindings_vim.rb +43 -297
- data/lib/vimamsa/key_bindings_vim_core.rb +356 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
- data/lib/vimamsa/key_names.rb +80 -0
- data/lib/vimamsa/langservp.rb +62 -7
- data/lib/vimamsa/line_tree.rb +367 -0
- data/lib/vimamsa/macro.rb +20 -3
- data/lib/vimamsa/rbvma.rb +15 -0
- data/lib/vimamsa/registers.rb +125 -0
- data/lib/vimamsa/run_ruby.rb +64 -0
- data/lib/vimamsa/search_replace.rb +4 -4
- data/lib/vimamsa/string_util.rb +17 -3
- data/lib/vimamsa/tests.rb +8 -8
- data/lib/vimamsa/text_objects.rb +11 -54
- data/lib/vimamsa/text_transforms.rb +4 -0
- data/lib/vimamsa/tmp_user_dir.rb +39 -0
- data/lib/vimamsa/user_dirs.rb +83 -0
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa/vim_operators.rb +365 -0
- data/modules/calculator/calculator.rb +5 -5
- data/modules/color_highlight/color_highlight.rb +3 -3
- data/modules/dictation/dictation.rb +32 -32
- data/modules/ollama/ollama.rb +5 -5
- data/modules/terminal/terminal.rb +5 -5
- data/modules/tts/tts.rb +10 -10
- data/run_e2e_vm.sh +3 -3
- data/run_tests_vm.rb +163 -0
- data/scripts/appimage/AppRun +7 -0
- data/scripts/appimage/build_in_container.sh +11 -1
- data/scripts/appimage/smoke_test.sh +1 -1
- data/scripts/demo/demo_easyjump_steps.txt +60 -0
- data/scripts/demo/demo_files_steps.txt +52 -0
- data/scripts/demo/demo_steps.txt +9 -1
- data/scripts/demo/notes.txt +6 -0
- data/scripts/demo/record_demo.rb +60 -81
- data/scripts/demo/report.rb +7 -0
- data/scripts/demo/shapes.rb +1 -0
- data/scripts/demo/square/shapes.rb +29 -0
- data/scripts/demo/square/steps.txt +185 -0
- data/scripts/lib/perf_startup.rb +138 -0
- data/scripts/lib/script_helpers.rb +53 -0
- data/scripts/perf_compare.rb +34 -0
- data/scripts/profile_startup.rb +72 -0
- data/tests/test_action_ids.rb +232 -0
- data/tests/test_auto_format.rb +2 -2
- data/tests/test_autocomplete.rb +1 -1
- data/tests/test_basic_editing.rb +18 -18
- data/tests/test_bookmarks.rb +6 -6
- data/tests/test_bracket_match.rb +3 -0
- data/tests/test_cli_help.rb +64 -0
- data/tests/test_color_highlight.rb +2 -2
- data/tests/test_command_line.rb +1 -1
- data/tests/test_context_menu_file.rb +18 -0
- data/tests/test_copy_paste.rb +33 -33
- data/tests/test_custom_two_phase.rb +1 -1
- data/tests/test_demo_player.rb +355 -0
- data/tests/test_demo_recorder.rb +202 -0
- data/tests/test_dictation.rb +16 -16
- data/tests/test_dot_repeat.rb +88 -0
- data/tests/test_easy_jump.rb +93 -0
- data/tests/test_extract_file_links.rb +3 -3
- data/tests/test_file_panel.rb +2 -2
- data/tests/test_flash.rb +1 -1
- data/tests/test_fold.rb +1 -1
- data/tests/test_form_input.rb +203 -0
- data/tests/test_func_panel.rb +2 -2
- data/tests/test_gtk_sync.rb +7 -7
- data/tests/test_intro_page.rb +437 -0
- data/tests/test_key_categories.rb +163 -0
- data/tests/test_keylog_panel.rb +163 -3
- data/tests/test_line_ends.rb +51 -0
- data/tests/test_line_tree.rb +86 -0
- data/tests/test_lsp_clangd.rb +2 -2
- data/tests/test_lsp_root.rb +43 -0
- data/tests/test_macro.rb +2 -2
- data/tests/test_module_interface.rb +9 -9
- data/tests/test_notepad_bindings.rb +5 -5
- data/tests/test_perf_startup.rb +28 -0
- data/tests/test_random_edit.rb +27 -27
- data/tests/test_registers.rb +131 -0
- data/tests/test_run_ruby.rb +77 -0
- data/tests/test_startup_file.rb +45 -4
- data/tests/test_text_objects.rb +1 -1
- data/tests/test_text_transforms.rb +12 -0
- data/tests/test_tmp_user_dir.rb +79 -0
- data/tests/test_tts.rb +10 -10
- data/tests/test_undo.rb +34 -34
- data/tests/test_user_dirs.rb +122 -0
- data/tests/test_vim_bindings.rb +107 -6
- data/tests/test_vim_conflicts.rb +41 -4
- data/tests/test_vim_operators.rb +116 -0
- data/tests/test_window_layout.rb +83 -0
- data/vimamsa.gemspec +1 -1
- data/vm_guest_run.sh +75 -28
- metadata +60 -4
- data/run_tests.rb +0 -89
- data/run_tests_vm.sh +0 -130
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
module Vimamsa
|
|
2
|
+
# Shared Vim bindings, used by both keymaps (doc/vim_compatibility_plan.md):
|
|
3
|
+
# vim keymap: bind_vim_bindings binds the whole table
|
|
4
|
+
# vimlike keymap: bind_vim_bindings(only_free: true) after its own
|
|
5
|
+
# bindings: binds only entries that don't conflict with
|
|
6
|
+
# them (vim_binding_status == :missing), so vimlike's own
|
|
7
|
+
# bindings always win.
|
|
8
|
+
# What was added, and every conflict, is listed in the generated
|
|
9
|
+
# doc/vimlike_vim_conflicts.md.
|
|
10
|
+
|
|
11
|
+
# ── composite actions for vim commands not covered by a single action ────────
|
|
12
|
+
#TODO: file should be renamed to sort close to key_actions.rb
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def reg_vim_actions
|
|
16
|
+
# get_range(:to_line_end) inverts on an empty line / cursor-on-newline and
|
|
17
|
+
# would delete the previous newline (buffer.rb get_range) => guard.
|
|
18
|
+
reg_act("edit.delete.eol", proc {
|
|
19
|
+
b = buf
|
|
20
|
+
b.delete2(:to_line_end) if b.pos < b.line_ends[b.lpos]
|
|
21
|
+
}, "Delete to end of line (vim D)")
|
|
22
|
+
|
|
23
|
+
reg_act("edit.change.eol", proc {
|
|
24
|
+
b = buf
|
|
25
|
+
b.delete2(:to_line_end) if b.pos < b.line_ends[b.lpos]
|
|
26
|
+
vma.kbd.set_mode(:insert)
|
|
27
|
+
}, "Change to end of line (vim C / c$)")
|
|
28
|
+
|
|
29
|
+
reg_act("edit.change.line", proc {
|
|
30
|
+
b = buf
|
|
31
|
+
b.jump(BEGINNING_OF_LINE)
|
|
32
|
+
b.delete2(:to_line_end) if b.pos < b.line_ends[b.lpos]
|
|
33
|
+
vma.kbd.set_mode(:insert)
|
|
34
|
+
}, "Change whole line, keep newline (vim cc/S)")
|
|
35
|
+
|
|
36
|
+
reg_act("edit.change.word", proc {
|
|
37
|
+
buf.delete2(:to_word_end) # vim cw ~= ce semantics; close enough
|
|
38
|
+
vma.kbd.set_mode(:insert)
|
|
39
|
+
}, "Change word (vim cw/ce)")
|
|
40
|
+
|
|
41
|
+
reg_act("edit.change.char", proc {
|
|
42
|
+
buf.delete(CURRENT_CHAR_FORWARD) if buf.current_char != "\n"
|
|
43
|
+
vma.kbd.set_mode(:insert)
|
|
44
|
+
}, "Substitute char (vim s)")
|
|
45
|
+
|
|
46
|
+
reg_act("edit.delete.char.inline", proc {
|
|
47
|
+
buf.delete(CURRENT_CHAR_FORWARD) if buf.current_char != "\n"
|
|
48
|
+
}, "Delete char under cursor; no-op on empty line (vim x)")
|
|
49
|
+
|
|
50
|
+
reg_act("edit.delete.char.prev", proc {
|
|
51
|
+
buf.delete(BACKWARD_CHAR) if buf.cpos > 0
|
|
52
|
+
}, "Delete char before cursor; no-op at col 0 (vim X)")
|
|
53
|
+
|
|
54
|
+
reg_act("edit.line.above", proc {
|
|
55
|
+
b = buf
|
|
56
|
+
b.jump(BEGINNING_OF_LINE)
|
|
57
|
+
# insert_txt_at neither auto-indents nor moves the cursor: @pos ends up on
|
|
58
|
+
# the inserted "\n" = the new empty line, matching vim O.
|
|
59
|
+
b.insert_txt_at("\n", b.pos)
|
|
60
|
+
b.set_pos(b.pos) # refresh view + lpos/cpos
|
|
61
|
+
vma.kbd.set_mode(:insert)
|
|
62
|
+
}, "Open line above (vim O)")
|
|
63
|
+
|
|
64
|
+
reg_act("sel.change", proc {
|
|
65
|
+
buf.delete(SELECTION) # ends visual mode itself
|
|
66
|
+
vma.kbd.set_mode(:insert)
|
|
67
|
+
}, "Delete selection and enter insert mode (vim visual c/s)")
|
|
68
|
+
|
|
69
|
+
# Operators, motions and text objects (vim_operators.rb). Bound through
|
|
70
|
+
# the templates in the "vim operators" section of VIM_BINDINGS; v is the
|
|
71
|
+
# values of the expansion ({ op: :delete, motion: :word_next }), c the
|
|
72
|
+
# typed <char>. They use the count themselves (d3w deletes three words at
|
|
73
|
+
# once, it doesn't run d w three times).
|
|
74
|
+
reg_act("op.motion", proc { |v, c = nil|
|
|
75
|
+
vma.kbd.method_handles_repeat = true
|
|
76
|
+
buf.vim_operator_motion(v[:op], v[:motion], vma.kbd.next_command_count, c || v[:char])
|
|
77
|
+
}, "Apply <op> from the cursor to where <motion> moves")
|
|
78
|
+
reg_act("op.lines", proc { |v|
|
|
79
|
+
vma.kbd.method_handles_repeat = true
|
|
80
|
+
buf.vim_operator_lines(v[:op], vma.kbd.next_command_count)
|
|
81
|
+
}, "Apply <op> to the current line (<count> lines)")
|
|
82
|
+
reg_act("op.textobj", proc { |v, c|
|
|
83
|
+
buf.text_object_op(v[:op], c, v[:textobj] == :inner ? :i : :a)
|
|
84
|
+
}, "Apply <op> to text object <char>")
|
|
85
|
+
reg_act("sel.textobj", proc { |v, c|
|
|
86
|
+
buf.text_object_op(:select, c, v[:textobj] == :inner ? :i : :a)
|
|
87
|
+
}, "Select text object <char>")
|
|
88
|
+
reg_act("move.motion", proc { |v, c = nil|
|
|
89
|
+
vma.kbd.method_handles_repeat = true
|
|
90
|
+
buf.vim_motion_move(v[:motion], vma.kbd.next_command_count, c || v[:char])
|
|
91
|
+
}, "Move to where <motion> moves")
|
|
92
|
+
|
|
93
|
+
# vim ".": the last change, with the text typed after it (dot_repeat.rb)
|
|
94
|
+
reg_act("undo.repeat", proc {
|
|
95
|
+
vma.kbd.method_handles_repeat = true
|
|
96
|
+
vma.dot.repeat(vma.kbd.next_command_count)
|
|
97
|
+
}, "Repeat the last change (vim .)")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# ── the table: section => { keys => action } ─────────────────────────────────
|
|
101
|
+
# Same binding syntax as add_keys. Only Vim behavior goes here; the vim
|
|
102
|
+
# keymap's own deviations (C tab, C enter, browse mode, ...) stay in
|
|
103
|
+
# key_bindings_vim.rb.
|
|
104
|
+
|
|
105
|
+
VIM_BINDINGS = {
|
|
106
|
+
"vim motion" => {
|
|
107
|
+
"VCX up" => "move.line.prev",
|
|
108
|
+
"VCX down" => "move.line.next",
|
|
109
|
+
"VCX right" => "move.char.next",
|
|
110
|
+
"VCX left" => "move.char.prev",
|
|
111
|
+
"VC h" => "move.char.prev",
|
|
112
|
+
"VC l" => "move.char.next",
|
|
113
|
+
"VC j" => "move.line.next",
|
|
114
|
+
"VC k" => "move.line.prev",
|
|
115
|
+
"C space" => "move.char.next",
|
|
116
|
+
"C backspace" => "move.char.prev",
|
|
117
|
+
|
|
118
|
+
"VC e" => "move.word.end",
|
|
119
|
+
"VC b" => "move.word.prev",
|
|
120
|
+
"VC w" => "move.word.next",
|
|
121
|
+
|
|
122
|
+
# NOTE: "G(condition)" must be defined before "G"
|
|
123
|
+
"VC G(vma.kbd.next_command_count!=nil)" => "move.line.goto",
|
|
124
|
+
"VC G" => "move.buf.end",
|
|
125
|
+
"VC g g" => "move.buf.start",
|
|
126
|
+
"VC g ;" => "jump.edit.prev",
|
|
127
|
+
|
|
128
|
+
# Counts; "0" is BOL only when no count is pending
|
|
129
|
+
"VC /[1-9]/" => "kbd.count.digit",
|
|
130
|
+
"VC 0(vma.kbd.next_command_count!=nil)" => "kbd.count.digit",
|
|
131
|
+
"VC 0(vma.kbd.next_command_count==nil)" => "move.line.start",
|
|
132
|
+
"VC ^" => "move.line.first_char",
|
|
133
|
+
# "VC $": the vim motion (last character, not past it), from the
|
|
134
|
+
# "vim operators" templates
|
|
135
|
+
|
|
136
|
+
"VC f <char>" => "jump.char.next",
|
|
137
|
+
"VC F <char>" => "jump.char.prev",
|
|
138
|
+
"VC f space" => "jump.space.next",
|
|
139
|
+
"VC F space" => "jump.space.prev",
|
|
140
|
+
"VC ;" => "jump.char.repeat",
|
|
141
|
+
|
|
142
|
+
"VC *" => "search.word.next",
|
|
143
|
+
"VC /" => "search.buf",
|
|
144
|
+
"C :" => "mode.cmdline",
|
|
145
|
+
"C n" => "search.next",
|
|
146
|
+
"C N" => "search.prev",
|
|
147
|
+
|
|
148
|
+
"VCI pagedown" => "move.page.next",
|
|
149
|
+
"VCI pageup" => "move.page.prev",
|
|
150
|
+
"C ctrl-f" => "move.page.next",
|
|
151
|
+
"C ctrl-b" => "move.page.prev",
|
|
152
|
+
"C ctrl-d" => "move.page.next.cursor", # approx: full page, vim: half
|
|
153
|
+
"C ctrl-u" => "move.page.prev.cursor", # approx: full page, vim: half
|
|
154
|
+
"C ctrl-o" => "jump.edit.prev", # approx of vim jumplist back
|
|
155
|
+
"C z z" => "view.center",
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
"vim marks cat:marks" => {
|
|
159
|
+
"CV m <char>" => "mark.set",
|
|
160
|
+
'CV \' <char>' => "mark.jump",
|
|
161
|
+
"C ` <char>" => "mark.jump",
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
# Enter insert mode
|
|
165
|
+
"vim edit cat:insert" => {
|
|
166
|
+
"C i" => "mode.insert",
|
|
167
|
+
"C a" => "mode.insert.after",
|
|
168
|
+
"C A" => "mode.insert.line.end",
|
|
169
|
+
"C I" => "mode.insert.line.start",
|
|
170
|
+
"C o" => "mode.insert.line.below",
|
|
171
|
+
"C O" => "edit.line.above",
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
#TODO: should replace all eval actions like "buf.move ... with actual registered actions.
|
|
175
|
+
"vim edit" => {
|
|
176
|
+
# Delete
|
|
177
|
+
"C x" => "edit.delete.char.inline",
|
|
178
|
+
"C X" => "edit.delete.char.prev",
|
|
179
|
+
"C D" => "edit.delete.eol",
|
|
180
|
+
|
|
181
|
+
# Change / substitute
|
|
182
|
+
"C C" => "edit.change.eol",
|
|
183
|
+
"C S" => "edit.change.line",
|
|
184
|
+
"C s" => "edit.change.char",
|
|
185
|
+
|
|
186
|
+
# Yank / paste. "x selects register x for the next command (registers.rb)
|
|
187
|
+
"VC \" <char>" => "edit.register",
|
|
188
|
+
"C Y" => "edit.line.copy",
|
|
189
|
+
"C p" => "edit.paste.after",
|
|
190
|
+
"C P" => "edit.paste.before",
|
|
191
|
+
|
|
192
|
+
# Misc edits
|
|
193
|
+
"C r <char>" => "edit.replace.char",
|
|
194
|
+
"C r space" => "edit.replace.space",
|
|
195
|
+
"C J" => "edit.line.join",
|
|
196
|
+
"C ~" => "case.char.toggle",
|
|
197
|
+
"C ctrl-a" => "edit.word.increment", # vim ctrl-a: increment number
|
|
198
|
+
"C ." => "undo.repeat",
|
|
199
|
+
|
|
200
|
+
# Undo / redo
|
|
201
|
+
"C u" => "undo.last",
|
|
202
|
+
"C ctrl-r" => "undo.redo",
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
"vim visual" => {
|
|
206
|
+
"C v" => "mode.visual",
|
|
207
|
+
"V esc" => "mode.visual.exit",
|
|
208
|
+
"V ctrl-c" => "mode.visual.exit",
|
|
209
|
+
"V y" => "sel.copy",
|
|
210
|
+
"V d" => "sel.delete",
|
|
211
|
+
"V x" => "sel.cut",
|
|
212
|
+
"V s" => "sel.change",
|
|
213
|
+
"V c" => "sel.change",
|
|
214
|
+
"V J" => "sel.join",
|
|
215
|
+
"V u" => "case.sel.lower",
|
|
216
|
+
"V U" => "case.sel.upper",
|
|
217
|
+
"V ~" => "case.sel.swap",
|
|
218
|
+
"V g U" => "case.sel.upper",
|
|
219
|
+
"V g u" => "case.sel.lower",
|
|
220
|
+
"V >" => "sel.indent.more",
|
|
221
|
+
"V <" => "sel.indent.less",
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
"vim insert" => {
|
|
225
|
+
"I esc" => "mode.prev",
|
|
226
|
+
"I ctrl-c" => "mode.prev", # vim: ctrl-c leaves insert mode
|
|
227
|
+
"I <char>" => "edit.insert.char",
|
|
228
|
+
"I space" => "edit.insert.space",
|
|
229
|
+
"I enter" => "edit.newline",
|
|
230
|
+
"I backspace" => "edit.backspace",
|
|
231
|
+
"I ctrl-h" => "edit.backspace", # vim i_ctrl-h = backspace
|
|
232
|
+
"I ctrl-j" => "edit.newline", # vim i_ctrl-j = new line
|
|
233
|
+
"I ctrl-r <char>" => "edit.insert.register", # vim i_ctrl-r: insert register <char>
|
|
234
|
+
|
|
235
|
+
# Completion (vim i_ctrl-n / i_ctrl-p; popup guards first)
|
|
236
|
+
"I tab(vma.buf.view.autocp_active)" => "edit.complete.next",
|
|
237
|
+
"I shift-tab(vma.buf.view.autocp_active)" => "edit.complete.prev",
|
|
238
|
+
"I shift!(vma.buf.view.autocp_active)" => "edit.complete.accept",
|
|
239
|
+
"I ctrl-n" => "edit.complete",
|
|
240
|
+
"I ctrl-p" => "edit.complete",
|
|
241
|
+
"I ctrl-space" => "edit.complete",
|
|
242
|
+
|
|
243
|
+
"I tab" => "edit.tab",
|
|
244
|
+
"I shift-tab" => "edit.untab",
|
|
245
|
+
|
|
246
|
+
"I shift-up" => "sel.line.prev",
|
|
247
|
+
"I shift-down" => "sel.line.next",
|
|
248
|
+
"I shift-left" => "sel.char.prev",
|
|
249
|
+
"I shift-right" => "sel.char.next",
|
|
250
|
+
"I shift-pagedown" => "sel.page.next",
|
|
251
|
+
"I shift-pageup" => "sel.page.prev",
|
|
252
|
+
|
|
253
|
+
"I left" => "move.char.prev.unselect",
|
|
254
|
+
"I right" => "move.char.next.unselect",
|
|
255
|
+
"I down" => "move.line.next.unselect",
|
|
256
|
+
"I up" => "move.line.prev.unselect",
|
|
257
|
+
"I pagedown" => "move.page.next.unselect",
|
|
258
|
+
"I pageup" => "move.page.prev.unselect",
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
# vim R
|
|
262
|
+
"vim replace" => {
|
|
263
|
+
"C R" => "mode.replace",
|
|
264
|
+
"X esc" => "mode.prev",
|
|
265
|
+
"X <char>" => "edit.replace.char.next",
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
# Every operator with every motion and text object (vim_operators.rb):
|
|
269
|
+
# d w, c 3 e, y $, g U f x, > j, d i (, ...; d d, c c, > >, g U U
|
|
270
|
+
"vim operators" => {
|
|
271
|
+
"C <op> <motion>" => "op.motion",
|
|
272
|
+
"C <op> <textobj>" => "op.textobj",
|
|
273
|
+
"C <op> <same>" => "op.lines",
|
|
274
|
+
"V <textobj>" => "sel.textobj",
|
|
275
|
+
# Plain movement for the motions the keymap has no binding of its own
|
|
276
|
+
# for (W, B, E, t, T, ...); always bound only where free
|
|
277
|
+
"VC <motion>" => "move.motion",
|
|
278
|
+
},
|
|
279
|
+
|
|
280
|
+
"vim macros" => {
|
|
281
|
+
# q<char> records, q stops, @<char> runs, @@ repeats
|
|
282
|
+
"VC q <char>" => "macro.record",
|
|
283
|
+
"macro q" => "macro.record.stop",
|
|
284
|
+
"C @ @" => "macro.run.last",
|
|
285
|
+
"C @ <char>" => "macro.run",
|
|
286
|
+
|
|
287
|
+
# READCHAR mode (argument input for f/F, r, m, ', q, @)
|
|
288
|
+
"R <char>" => "readchar_new_char(<char>)",
|
|
289
|
+
},
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
# Vim keymap bindings left out of vimlike on purpose, with the reason. The
|
|
293
|
+
# conflicts report lists them separately instead of as missing.
|
|
294
|
+
VIM_KEYMAP_ONLY = {
|
|
295
|
+
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
# Whether keys are bound in mode m, with or without a condition ("C 0" is
|
|
299
|
+
# taken by "C 0(vma.kbd.next_command_count==nil)")
|
|
300
|
+
def vim_keys_taken?(kbd, m, keys)
|
|
301
|
+
node = kbd.root.children.find { |x| x.key_name == m }
|
|
302
|
+
keys.each { |k|
|
|
303
|
+
return false if node.nil?
|
|
304
|
+
node = node.children.find { |x| x.key_name == k.sub(/\(.*\)\z/, "") }
|
|
305
|
+
}
|
|
306
|
+
!node.nil?
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
# Bind VIM_BINDINGS into vma.kbd. With only_free, an entry is bound only if
|
|
310
|
+
# vma.kbd has nothing in its way (see vim_binding_status), and binding it
|
|
311
|
+
# doesn't change which keys the menus show for an action vimlike already
|
|
312
|
+
# binds. Records what was bound as [mode, keys] in vma.kbd.vim_added.
|
|
313
|
+
# Templates ("C <op> <motion>") are checked per expansion; the plain motion
|
|
314
|
+
# template is bound only where free in both keymaps.
|
|
315
|
+
def bind_vim_bindings(only_free: false)
|
|
316
|
+
reg_vim_actions
|
|
317
|
+
kbd = vma.kbd
|
|
318
|
+
# The keymap's own additions to a key set (key_set_add before this) stay
|
|
319
|
+
VIM_KEY_SETS.each { |name, entries| kbd.define_key_set(name, entries.merge(kbd.key_set(name) || {})) }
|
|
320
|
+
added = []
|
|
321
|
+
VIM_BINDINGS.each { |section, h|
|
|
322
|
+
h.each { |key, action|
|
|
323
|
+
if kbd.template_key?(key)
|
|
324
|
+
free = only_free || action == "move.motion"
|
|
325
|
+
filter = !free ? nil : proc { |m, keys, act|
|
|
326
|
+
ok = !vim_keys_taken?(kbd, m, keys) && vim_binding_status(kbd, m, keys, act)[:status] == :missing
|
|
327
|
+
added << [m, keys] if ok && only_free
|
|
328
|
+
ok
|
|
329
|
+
}
|
|
330
|
+
bindkey(key, action, keywords: section, filter: filter)
|
|
331
|
+
next
|
|
332
|
+
end
|
|
333
|
+
if !only_free
|
|
334
|
+
bindkey(key, action, keywords: section)
|
|
335
|
+
next
|
|
336
|
+
end
|
|
337
|
+
act = action.class == Array ? action[0] : action
|
|
338
|
+
key.split("||").each { |k|
|
|
339
|
+
mstr, keydef = k.strip.split(/\s+/, 2)
|
|
340
|
+
modes = mstr.match?(/\A\p{Lu}+\z/) ? mstr.chars : [mstr]
|
|
341
|
+
modes.each { |m|
|
|
342
|
+
keys = keydef.split
|
|
343
|
+
next if vim_binding_status(kbd, m, keys, act)[:status] != :missing
|
|
344
|
+
had = kbd.act_bindings.key?(m) && kbd.act_bindings[m].key?(act)
|
|
345
|
+
prev = had ? kbd.act_bindings[m][act] : nil
|
|
346
|
+
bindkey("#{m} #{keydef}", action, keywords: section)
|
|
347
|
+
kbd.act_bindings[m][act] = prev if had
|
|
348
|
+
added << [m, keys]
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
kbd.vim_added = added
|
|
354
|
+
added
|
|
355
|
+
end
|
|
356
|
+
end # module Vimamsa
|