diff --git a/init.lua b/init.lua index dceb32d..911acb3 100644 --- a/init.lua +++ b/init.lua @@ -507,3 +507,52 @@ vim.api.nvim_set_keymap('n', 's', 'YSurround', {}) vim.api.nvim_set_keymap('n', 'ss', 'lua vim.lsp.buf.signature_help()', { noremap = true, silent = true }) + +vim.api.nvim_set_keymap('v', '', [["hy:%s/h//gc]], { noremap = true }) + + +require('refactoring').setup({ + prompt_func_return_type = { + go = true, + java = true, + + cpp = true, + c = true, + h = true, + hpp = true, + cxx = true, + }, + prompt_func_param_type = { + go = true, + java = true, + + cpp = true, + c = true, + h = true, + hpp = true, + cxx = true, + }, + printf_statements = {}, + print_var_statements = {}, +}) + +-- Remaps for the refactoring operations currently offered by the plugin +vim.api.nvim_set_keymap("v", "re", [[ lua require('refactoring').refactor('Extract Function')]], + { noremap = true, silent = true, expr = false }) +vim.api.nvim_set_keymap("v", "rf", + [[ lua require('refactoring').refactor('Extract Function To File')]], + { noremap = true, silent = true, expr = false }) +vim.api.nvim_set_keymap("v", "rv", [[ lua require('refactoring').refactor('Extract Variable')]], + { noremap = true, silent = true, expr = false }) +vim.api.nvim_set_keymap("v", "ri", [[ lua require('refactoring').refactor('Inline Variable')]], + { noremap = true, silent = true, expr = false }) + +-- Extract block doesn't need visual mode +vim.api.nvim_set_keymap("n", "rb", [[ lua require('refactoring').refactor('Extract Block')]], + { noremap = true, silent = true, expr = false }) +vim.api.nvim_set_keymap("n", "rbf", [[ lua require('refactoring').refactor('Extract Block To File')]], + { noremap = true, silent = true, expr = false }) + +-- Inline variable can also pick up the identifier currently under the cursor without visual mode +vim.api.nvim_set_keymap("n", "ri", [[ lua require('refactoring').refactor('Inline Variable')]], + { noremap = true, silent = true, expr = false }) diff --git a/lua/custom/plugins/refactoring.lua b/lua/custom/plugins/refactoring.lua new file mode 100644 index 0000000..44a997e --- /dev/null +++ b/lua/custom/plugins/refactoring.lua @@ -0,0 +1,4 @@ +return { + 'ThePrimeagen/refactoring.nvim', + requires = { { 'nvim-lua/plenary.nvim' }, { 'nvim-lua/plenary.nvim' } }, +}