vimamsa 0.1.27 → 0.1.28

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.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +139 -89
  3. data/custom_example.rb +18 -6
  4. data/doc/TODO.md +327 -110
  5. data/doc/action_names_plan.md +442 -0
  6. data/doc/bundling_plan.md +2 -1
  7. data/doc/delta_syntax_plan.md +293 -0
  8. data/doc/demo_recording_plan.md +288 -0
  9. data/doc/design_goals.md +27 -0
  10. data/doc/intro_page_plan.md +266 -0
  11. data/doc/key_bindings_report_plan.md +45 -0
  12. data/doc/line_tree_plan.md +89 -0
  13. data/doc/missing_vim_bindings.md +34 -44
  14. data/doc/modules_settings_plan.md +1 -1
  15. data/doc/registries_plan.md +202 -0
  16. data/doc/startup_speed_plan.md +97 -0
  17. data/doc/treap_visualizer.html +585 -0
  18. data/doc/vim_compatibility_plan.md +186 -31
  19. data/doc/vimlike_vim_conflicts.md +236 -228
  20. data/doc/vm_snapshots_plan.md +4 -4
  21. data/doc/wysiwyg_plan.md +231 -0
  22. data/exe/run_tests.rb +8 -1
  23. data/exe/vimamsa +49 -6
  24. data/help/intro.txt +30 -0
  25. data/help/vim_intro.txt +31 -0
  26. data/img/demo.gif +0 -0
  27. data/img/demo.mp4 +0 -0
  28. data/lang/hyperplaintext.lang +1 -1
  29. data/lib/vimamsa/ack.rb +2 -0
  30. data/lib/vimamsa/actions.rb +381 -36
  31. data/lib/vimamsa/bookmarks.rb +8 -8
  32. data/lib/vimamsa/buffer.rb +83 -37
  33. data/lib/vimamsa/buffer_changetext.rb +58 -36
  34. data/lib/vimamsa/buffer_list.rb +2 -2
  35. data/lib/vimamsa/buffer_manager.rb +6 -6
  36. data/lib/vimamsa/cli_help.rb +75 -0
  37. data/lib/vimamsa/clipboard.rb +6 -3
  38. data/lib/vimamsa/conf.rb +9 -0
  39. data/lib/vimamsa/crash_handler.rb +2 -2
  40. data/lib/vimamsa/debug.rb +2 -2
  41. data/lib/vimamsa/demo_player.rb +458 -0
  42. data/lib/vimamsa/demo_recorder.rb +277 -0
  43. data/lib/vimamsa/diff_buffer.rb +1 -1
  44. data/lib/vimamsa/dot_repeat.rb +104 -0
  45. data/lib/vimamsa/easy_jump.rb +54 -3
  46. data/lib/vimamsa/editor.rb +89 -46
  47. data/lib/vimamsa/file_history.rb +1 -1
  48. data/lib/vimamsa/file_manager.rb +23 -23
  49. data/lib/vimamsa/form_input.rb +388 -0
  50. data/lib/vimamsa/gui.rb +83 -13
  51. data/lib/vimamsa/gui_command_line.rb +44 -5
  52. data/lib/vimamsa/gui_form_generator.rb +17 -6
  53. data/lib/vimamsa/gui_key_hint.rb +165 -0
  54. data/lib/vimamsa/gui_keylog_panel.rb +164 -2
  55. data/lib/vimamsa/gui_menu.rb +69 -50
  56. data/lib/vimamsa/gui_select_window.rb +77 -43
  57. data/lib/vimamsa/gui_settings.rb +9 -5
  58. data/lib/vimamsa/gui_sourceview.rb +15 -81
  59. data/lib/vimamsa/gui_theme.rb +11 -2
  60. data/lib/vimamsa/hook.rb +2 -0
  61. data/lib/vimamsa/intro_page.rb +368 -0
  62. data/lib/vimamsa/key_actions.rb +315 -225
  63. data/lib/vimamsa/key_binding_tree.rb +228 -61
  64. data/lib/vimamsa/key_bindings_notepad.rb +18 -16
  65. data/lib/vimamsa/key_bindings_report.rb +290 -67
  66. data/lib/vimamsa/key_bindings_vim.rb +47 -297
  67. data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
  68. data/lib/vimamsa/key_names.rb +80 -0
  69. data/lib/vimamsa/line_tree.rb +367 -0
  70. data/lib/vimamsa/macro.rb +20 -3
  71. data/lib/vimamsa/rbvma.rb +15 -0
  72. data/lib/vimamsa/registers.rb +125 -0
  73. data/lib/vimamsa/run_ruby.rb +64 -0
  74. data/lib/vimamsa/search_replace.rb +4 -4
  75. data/lib/vimamsa/string_util.rb +17 -3
  76. data/lib/vimamsa/tests.rb +8 -8
  77. data/lib/vimamsa/text_objects.rb +11 -54
  78. data/lib/vimamsa/text_transforms.rb +4 -0
  79. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  80. data/lib/vimamsa/user_dirs.rb +83 -0
  81. data/lib/vimamsa/version.rb +1 -1
  82. data/lib/vimamsa/vim_core.rb +355 -0
  83. data/lib/vimamsa/vim_operators.rb +365 -0
  84. data/modules/calculator/calculator.rb +5 -5
  85. data/modules/color_highlight/color_highlight.rb +3 -3
  86. data/modules/dictation/dictation.rb +32 -32
  87. data/modules/ollama/ollama.rb +5 -5
  88. data/modules/terminal/terminal.rb +5 -5
  89. data/modules/tts/tts.rb +10 -10
  90. data/run_e2e_vm.sh +3 -3
  91. data/run_tests_vm.rb +138 -0
  92. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  93. data/scripts/demo/demo_files_steps.txt +52 -0
  94. data/scripts/demo/demo_steps.txt +9 -1
  95. data/scripts/demo/notes.txt +6 -0
  96. data/scripts/demo/record_demo.rb +60 -81
  97. data/scripts/demo/report.rb +7 -0
  98. data/scripts/demo/shapes.rb +1 -0
  99. data/scripts/demo/square/shapes.rb +29 -0
  100. data/scripts/demo/square/steps.txt +185 -0
  101. data/scripts/lib/perf_startup.rb +138 -0
  102. data/scripts/lib/script_helpers.rb +53 -0
  103. data/scripts/perf_compare.rb +34 -0
  104. data/scripts/profile_startup.rb +72 -0
  105. data/tests/test_action_ids.rb +232 -0
  106. data/tests/test_auto_format.rb +2 -2
  107. data/tests/test_autocomplete.rb +1 -1
  108. data/tests/test_basic_editing.rb +18 -18
  109. data/tests/test_bookmarks.rb +6 -6
  110. data/tests/test_bracket_match.rb +3 -0
  111. data/tests/test_cli_help.rb +64 -0
  112. data/tests/test_color_highlight.rb +2 -2
  113. data/tests/test_command_line.rb +1 -1
  114. data/tests/test_context_menu_file.rb +18 -0
  115. data/tests/test_copy_paste.rb +33 -33
  116. data/tests/test_custom_two_phase.rb +1 -1
  117. data/tests/test_demo_player.rb +301 -0
  118. data/tests/test_demo_recorder.rb +202 -0
  119. data/tests/test_dictation.rb +16 -16
  120. data/tests/test_dot_repeat.rb +88 -0
  121. data/tests/test_easy_jump.rb +93 -0
  122. data/tests/test_extract_file_links.rb +3 -3
  123. data/tests/test_file_panel.rb +2 -2
  124. data/tests/test_flash.rb +1 -1
  125. data/tests/test_fold.rb +1 -1
  126. data/tests/test_form_input.rb +203 -0
  127. data/tests/test_func_panel.rb +2 -2
  128. data/tests/test_gtk_sync.rb +7 -7
  129. data/tests/test_intro_page.rb +437 -0
  130. data/tests/test_key_categories.rb +163 -0
  131. data/tests/test_keylog_panel.rb +163 -3
  132. data/tests/test_line_ends.rb +51 -0
  133. data/tests/test_line_tree.rb +86 -0
  134. data/tests/test_lsp_clangd.rb +2 -2
  135. data/tests/test_macro.rb +2 -2
  136. data/tests/test_module_interface.rb +9 -9
  137. data/tests/test_notepad_bindings.rb +5 -5
  138. data/tests/test_perf_startup.rb +28 -0
  139. data/tests/test_random_edit.rb +27 -27
  140. data/tests/test_registers.rb +122 -0
  141. data/tests/test_run_ruby.rb +77 -0
  142. data/tests/test_startup_file.rb +1 -1
  143. data/tests/test_text_objects.rb +1 -1
  144. data/tests/test_text_transforms.rb +12 -0
  145. data/tests/test_tmp_user_dir.rb +79 -0
  146. data/tests/test_tts.rb +10 -10
  147. data/tests/test_undo.rb +34 -34
  148. data/tests/test_user_dirs.rb +122 -0
  149. data/tests/test_vim_bindings.rb +107 -6
  150. data/tests/test_vim_conflicts.rb +41 -4
  151. data/tests/test_vim_operators.rb +116 -0
  152. data/tests/test_window_layout.rb +83 -0
  153. data/vimamsa.gemspec +1 -1
  154. data/vm_guest_run.sh +22 -2
  155. metadata +58 -3
  156. data/run_tests_vm.sh +0 -130
@@ -0,0 +1,355 @@
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
+
234
+ # Completion (vim i_ctrl-n / i_ctrl-p; popup guards first)
235
+ "I tab(vma.buf.view.autocp_active)" => "edit.complete.next",
236
+ "I shift-tab(vma.buf.view.autocp_active)" => "edit.complete.prev",
237
+ "I shift!(vma.buf.view.autocp_active)" => "edit.complete.accept",
238
+ "I ctrl-n" => "edit.complete",
239
+ "I ctrl-p" => "edit.complete",
240
+ "I ctrl-space" => "edit.complete",
241
+
242
+ "I tab" => "edit.tab",
243
+ "I shift-tab" => "edit.untab",
244
+
245
+ "I shift-up" => "sel.line.prev",
246
+ "I shift-down" => "sel.line.next",
247
+ "I shift-left" => "sel.char.prev",
248
+ "I shift-right" => "sel.char.next",
249
+ "I shift-pagedown" => "sel.page.next",
250
+ "I shift-pageup" => "sel.page.prev",
251
+
252
+ "I left" => "move.char.prev.unselect",
253
+ "I right" => "move.char.next.unselect",
254
+ "I down" => "move.line.next.unselect",
255
+ "I up" => "move.line.prev.unselect",
256
+ "I pagedown" => "move.page.next.unselect",
257
+ "I pageup" => "move.page.prev.unselect",
258
+ },
259
+
260
+ # vim R
261
+ "vim replace" => {
262
+ "C R" => "mode.replace",
263
+ "X esc" => "mode.prev",
264
+ "X <char>" => "edit.replace.char.next",
265
+ },
266
+
267
+ # Every operator with every motion and text object (vim_operators.rb):
268
+ # d w, c 3 e, y $, g U f x, > j, d i (, ...; d d, c c, > >, g U U
269
+ "vim operators" => {
270
+ "C <op> <motion>" => "op.motion",
271
+ "C <op> <textobj>" => "op.textobj",
272
+ "C <op> <same>" => "op.lines",
273
+ "V <textobj>" => "sel.textobj",
274
+ # Plain movement for the motions the keymap has no binding of its own
275
+ # for (W, B, E, t, T, ...); always bound only where free
276
+ "VC <motion>" => "move.motion",
277
+ },
278
+
279
+ "vim macros" => {
280
+ # q<char> records, q stops, @<char> runs, @@ repeats
281
+ "VC q <char>" => "macro.record",
282
+ "macro q" => "macro.record.stop",
283
+ "C @ @" => "macro.run.last",
284
+ "C @ <char>" => "macro.run",
285
+
286
+ # READCHAR mode (argument input for f/F, r, m, ', q, @)
287
+ "R <char>" => "readchar_new_char(<char>)",
288
+ },
289
+ }
290
+
291
+ # Vim keymap bindings left out of vimlike on purpose, with the reason. The
292
+ # conflicts report lists them separately instead of as missing.
293
+ VIM_KEYMAP_ONLY = {
294
+ "I ctrl-r <char>" => "no new ctrl chords in vimlike",
295
+ }
296
+
297
+ # Whether keys are bound in mode m, with or without a condition ("C 0" is
298
+ # taken by "C 0(vma.kbd.next_command_count==nil)")
299
+ def vim_keys_taken?(kbd, m, keys)
300
+ node = kbd.root.children.find { |x| x.key_name == m }
301
+ keys.each { |k|
302
+ return false if node.nil?
303
+ node = node.children.find { |x| x.key_name == k.sub(/\(.*\)\z/, "") }
304
+ }
305
+ !node.nil?
306
+ end
307
+
308
+ # Bind VIM_BINDINGS into vma.kbd. With only_free, an entry is bound only if
309
+ # vma.kbd has nothing in its way (see vim_binding_status), and binding it
310
+ # doesn't change which keys the menus show for an action vimlike already
311
+ # binds. Records what was bound as [mode, keys] in vma.kbd.vim_added.
312
+ # Templates ("C <op> <motion>") are checked per expansion; the plain motion
313
+ # template is bound only where free in both keymaps.
314
+ def bind_vim_bindings(only_free: false)
315
+ reg_vim_actions
316
+ kbd = vma.kbd
317
+ # The keymap's own additions to a key set (key_set_add before this) stay
318
+ VIM_KEY_SETS.each { |name, entries| kbd.define_key_set(name, entries.merge(kbd.key_set(name) || {})) }
319
+ added = []
320
+ VIM_BINDINGS.each { |section, h|
321
+ h.each { |key, action|
322
+ if kbd.template_key?(key)
323
+ free = only_free || action == "move.motion"
324
+ filter = !free ? nil : proc { |m, keys, act|
325
+ ok = !vim_keys_taken?(kbd, m, keys) && vim_binding_status(kbd, m, keys, act)[:status] == :missing
326
+ added << [m, keys] if ok && only_free
327
+ ok
328
+ }
329
+ bindkey(key, action, keywords: section, filter: filter)
330
+ next
331
+ end
332
+ if !only_free
333
+ bindkey(key, action, keywords: section)
334
+ next
335
+ end
336
+ act = action.class == Array ? action[0] : action
337
+ key.split("||").each { |k|
338
+ mstr, keydef = k.strip.split(/\s+/, 2)
339
+ modes = mstr.match?(/\A\p{Lu}+\z/) ? mstr.chars : [mstr]
340
+ modes.each { |m|
341
+ keys = keydef.split
342
+ next if vim_binding_status(kbd, m, keys, act)[:status] != :missing
343
+ had = kbd.act_bindings.key?(m) && kbd.act_bindings[m].key?(act)
344
+ prev = had ? kbd.act_bindings[m][act] : nil
345
+ bindkey("#{m} #{keydef}", action, keywords: section)
346
+ kbd.act_bindings[m][act] = prev if had
347
+ added << [m, keys]
348
+ }
349
+ }
350
+ }
351
+ }
352
+ kbd.vim_added = added
353
+ added
354
+ end
355
+ end # module Vimamsa