From aa069922ca88d936ca5d2b5a682cc762dccc55a8 Mon Sep 17 00:00:00 2001 From: Evan Minsk Date: Mon, 6 May 2019 17:02:22 -0700 Subject: [PATCH 1/3] vim mode: remember last run macro `vimGlobalState.macroModeState.latestRegister` was only ever updated when defining a macro. This change updates it when running a macro too so that `@@` actually repeats the last macro as it does in vim --- keymap/vim.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/keymap/vim.js b/keymap/vim.js index 5758823867..a0a0ef6d57 100644 --- a/keymap/vim.js +++ b/keymap/vim.js @@ -2315,6 +2315,8 @@ var macroModeState = vimGlobalState.macroModeState; if (registerName == '@') { registerName = macroModeState.latestRegister; + } else { + macroModeState.latestRegister = registerName; } while(repeat--){ executeMacroRegister(cm, vim, macroModeState, registerName); From 718d274b41c6b8788844aa04a7fc6d202c70c7bc Mon Sep 17 00:00:00 2001 From: Evan Minsk Date: Mon, 6 May 2019 17:42:25 -0700 Subject: [PATCH 2/3] vim test for @@ test for rerunning the last run macro --- test/vim_test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/vim_test.js b/test/vim_test.js index f38efd0245..24c24f9634 100644 --- a/test/vim_test.js +++ b/test/vim_test.js @@ -2644,6 +2644,14 @@ testVim('macro_last_ex_command_register', function (cm, vim, helpers) { eq('bbbaa', cm.getValue()); helpers.assertCursorAt(0, 2); }, { value: 'aaaaa'}); +testVim('macro_last_run_macro', function (cm, vim, helpers) { + cm.setCursor(0, 0); + helpers.doKeys('q', 'a', 'C', 'a', '', 'q'); + helpers.doKeys('q', 'b', 'C', 'b', '', 'q'); + helpers.doKeys('@', 'a'); + helpers.doKeys('@', '@'); + eq('a', cm.getValue()); +}, { value: ''}); testVim('macro_parens', function(cm, vim, helpers) { cm.setCursor(0, 0); helpers.doKeys('q', 'z', 'i'); From 8752bedf83c55ee1d9200bef908932dfe9efbce9 Mon Sep 17 00:00:00 2001 From: Evan Minsk Date: Mon, 6 May 2019 17:48:05 -0700 Subject: [PATCH 3/3] make @@ test more robust delete any leftover characters to ensure that the `a` expected at the end of the test actually came from `@@` --- test/vim_test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/vim_test.js b/test/vim_test.js index 24c24f9634..b93845fdbb 100644 --- a/test/vim_test.js +++ b/test/vim_test.js @@ -2649,6 +2649,7 @@ testVim('macro_last_run_macro', function (cm, vim, helpers) { helpers.doKeys('q', 'a', 'C', 'a', '', 'q'); helpers.doKeys('q', 'b', 'C', 'b', '', 'q'); helpers.doKeys('@', 'a'); + helpers.doKeys('d', 'd'); helpers.doKeys('@', '@'); eq('a', cm.getValue()); }, { value: ''});