|
53 | 53 | { keys: '<Down>', type: 'keyToKey', toKeys: 'j' }, |
54 | 54 | { keys: '<Space>', type: 'keyToKey', toKeys: 'l' }, |
55 | 55 | { keys: '<BS>', type: 'keyToKey', toKeys: 'h', context: 'normal'}, |
56 | | - { keys: '<BS>', type: 'motion', motion: 'moveByCharacters', motionArgs: { forward: false }, context: 'insert'}, |
57 | 56 | { keys: '<C-Space>', type: 'keyToKey', toKeys: 'W' }, |
58 | 57 | { keys: '<C-BS>', type: 'keyToKey', toKeys: 'B', context: 'normal' }, |
59 | 58 | { keys: '<S-Space>', type: 'keyToKey', toKeys: 'w' }, |
|
73 | 72 | { keys: '<PageUp>', type: 'keyToKey', toKeys: '<C-b>' }, |
74 | 73 | { keys: '<PageDown>', type: 'keyToKey', toKeys: '<C-f>' }, |
75 | 74 | { keys: '<CR>', type: 'keyToKey', toKeys: 'j^', context: 'normal' }, |
| 75 | + { keys: '<Ins>', type: 'action', action: 'toggleOverwrite', context: 'insert' }, |
76 | 76 | // Motions |
77 | 77 | { keys: 'H', type: 'motion', motion: 'moveToTopLine', motionArgs: { linewise: true, toJumplist: true }}, |
78 | 78 | { keys: 'M', type: 'motion', motion: 'moveToMiddleLine', motionArgs: { linewise: true, toJumplist: true }}, |
|
277 | 277 |
|
278 | 278 | function cmKey(key, cm) { |
279 | 279 | if (!cm) { return undefined; } |
| 280 | + if (this[key]) { return this[key]; } |
280 | 281 | var vimKey = cmKeyToVimKey(key); |
281 | 282 | if (!vimKey) { |
282 | 283 | return false; |
|
289 | 290 | } |
290 | 291 |
|
291 | 292 | var modifiers = {'Shift': 'S', 'Ctrl': 'C', 'Alt': 'A', 'Cmd': 'D', 'Mod': 'A'}; |
292 | | - var specialKeys = {Enter:'CR',Backspace:'BS',Delete:'Del'}; |
| 293 | + var specialKeys = {Enter:'CR',Backspace:'BS',Delete:'Del',Insert:'Ins'}; |
293 | 294 | function cmKeyToVimKey(key) { |
294 | 295 | if (key.charAt(0) == '\'') { |
295 | 296 | // Keypress character binding of format "'a'" |
|
2175 | 2176 | var registerName = actionArgs.selectedCharacter; |
2176 | 2177 | macroModeState.enterMacroRecordMode(cm, registerName); |
2177 | 2178 | }, |
| 2179 | + toggleOverwrite: function(cm) { |
| 2180 | + if (!cm.state.overwrite) { |
| 2181 | + cm.toggleOverwrite(true); |
| 2182 | + cm.setOption('keyMap', 'vim-replace'); |
| 2183 | + CodeMirror.signal(cm, "vim-mode-change", {mode: "replace"}); |
| 2184 | + } else { |
| 2185 | + cm.toggleOverwrite(false); |
| 2186 | + cm.setOption('keyMap', 'vim-insert'); |
| 2187 | + CodeMirror.signal(cm, "vim-mode-change", {mode: "insert"}); |
| 2188 | + } |
| 2189 | + }, |
2178 | 2190 | enterInsertMode: function(cm, actionArgs, vim) { |
2179 | 2191 | if (cm.getOption('readOnly')) { return; } |
2180 | 2192 | vim.insertMode = true; |
|
2220 | 2232 | return; |
2221 | 2233 | } |
2222 | 2234 | } |
2223 | | - cm.setOption('keyMap', 'vim-insert'); |
2224 | 2235 | cm.setOption('disableInput', false); |
2225 | 2236 | if (actionArgs && actionArgs.replace) { |
2226 | 2237 | // Handle Replace-mode as a special case of insert mode. |
2227 | 2238 | cm.toggleOverwrite(true); |
2228 | 2239 | cm.setOption('keyMap', 'vim-replace'); |
2229 | 2240 | CodeMirror.signal(cm, "vim-mode-change", {mode: "replace"}); |
2230 | 2241 | } else { |
| 2242 | + cm.toggleOverwrite(false); |
2231 | 2243 | cm.setOption('keyMap', 'vim-insert'); |
2232 | 2244 | CodeMirror.signal(cm, "vim-mode-change", {mode: "insert"}); |
2233 | 2245 | } |
|
4779 | 4791 | }; |
4780 | 4792 |
|
4781 | 4793 | CodeMirror.keyMap['vim-replace'] = { |
| 4794 | + 'Backspace': 'goCharLeft', |
4782 | 4795 | fallthrough: ['vim-insert'], |
4783 | 4796 | attach: attachVimMap, |
4784 | 4797 | detach: detachVimMap, |
|
0 commit comments