Allow refactoring (plus minor tweaks)

This commit is contained in:
Fabian Missbrenner 2025-03-12 12:36:38 +01:00
parent 2be2cae29c
commit 3569e4ec8e
5 changed files with 89 additions and 11 deletions

View File

@ -154,7 +154,7 @@ vim.opt.inccommand = 'split'
vim.opt.cursorline = true
-- Minimal number of screen lines to keep above and below the cursor.
-- vim.opt.scrolloff = 10
vim.opt.scrolloff = 10
-- [[ Basic Keymaps ]]
-- See `:help vim.keymap.set()`
@ -384,11 +384,20 @@ require('lazy').setup({
-- You can put your default mappings / updates / etc. in here
-- All the info you're looking for is in `:help telescope.setup()`
--
-- defaults = {
defaults = {
-- mappings = {
-- i = { ['<c-enter>'] = 'to_fuzzy_refine' },
-- },
-- },
layout_strategy = 'vertical',
layout_config = {
vertical = {
width = 0.9,
height = 0.9,
preview_height = 0.6,
preview_cutoff = 0,
},
},
},
-- pickers = {}
extensions = {
['ui-select'] = {

View File

@ -22,6 +22,7 @@
"nvim-treesitter-context": { "branch": "master", "commit": "198720b4016af04c9590f375d714d5bf8afecc1a" },
"nvim-web-devicons": { "branch": "master", "commit": "ab4cfee554e501f497bce0856788d43cf2eb93d7" },
"plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" },
"refactoring.nvim": { "branch": "master", "commit": "5268cc6add06ba8862492063341a568d18d65fb6" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "2a5ceff981501cff8f46871d5402cd3378a8ab6a" },
"telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },
"telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },

View File

@ -2,8 +2,12 @@
-- I promise not to create any merge conflicts in this directory :)
--
-- See the kickstart.nvim README for more information
--
-- When a file has been detected to have been changed outside of Vim and it has not been changed inside of Vim, automatically read it again.
vim.opt.autoread = true
return {
vim.keymap.set('n', '<leader>sm', function()
require('telescope.builtin').live_grep { search_dirs = { '/home/ccs/missbrenner/Documents/ns-3/ns3-mmwave-iab/src/mmwave/' } }
end, { desc = '[S]earch [M]mwave files' }),
end, { desc = '[S]earch [M]mwave File Contents' }),
}

View File

@ -0,0 +1,61 @@
return {
'ThePrimeagen/refactoring.nvim',
dependencies = {
'nvim-lua/plenary.nvim',
'nvim-treesitter/nvim-treesitter',
},
lazy = false,
config = function()
require('refactoring').setup {
prompt_func_return_type = {
go = false,
java = false,
cpp = false,
c = false,
h = false,
hpp = false,
cxx = false,
},
prompt_func_param_type = {
go = false,
java = false,
cpp = false,
c = false,
h = false,
hpp = false,
cxx = false,
},
printf_statements = {},
print_var_statements = {},
show_success_message = true, -- shows a message with information about the refactor on success
-- i.e. [Refactor] Inlined 3 variable occurrences
}
end,
vim.keymap.set({ 'n', 'x' }, '<leader>cr', function()
return require('refactoring').refactor 'Code Refactor'
end, { expr = true, desc = '[C]ode [R]efactor' }),
vim.keymap.set({ 'n', 'x' }, '<leader>cre', function()
return require('refactoring').refactor 'Extract Function'
end, { expr = true, desc = '[R]efactor [E]xtract Function' }),
vim.keymap.set({ 'n', 'x' }, '<leader>crf', function()
return require('refactoring').refactor 'Extract Function To File'
end, { expr = true, desc = '[R]efactor Extract Function To [F]ile' }),
vim.keymap.set({ 'n', 'x' }, '<leader>crv', function()
return require('refactoring').refactor 'Extract Variable'
end, { expr = true, desc = '[R]efactor Extract [V]ariable' }),
vim.keymap.set({ 'n', 'x' }, '<leader>crI', function()
return require('refactoring').refactor 'Inline Function'
end, { expr = true, desc = '[R]efactor [I]nline Function' }),
vim.keymap.set({ 'n', 'x' }, '<leader>cri', function()
return require('refactoring').refactor 'Inline Variable'
end, { expr = true, desc = '[R]efactor [I]nline Variable' }),
vim.keymap.set({ 'n', 'x' }, '<leader>crbb', function()
return require('refactoring').refactor 'Extract Block'
end, { expr = true, desc = '[R]efactor Extract [B]lock' }),
vim.keymap.set({ 'n', 'x' }, '<leader>crbf', function()
return require('refactoring').refactor 'Extract Block To File'
end, { expr = true, desc = '[R]efactor Extract [B]lock To [F]ile' }),
}

View File

@ -1,15 +1,15 @@
return {
"nvim-treesitter/nvim-treesitter-context",
'nvim-treesitter/nvim-treesitter-context',
config = function()
require'treesitter-context'.setup{
require('treesitter-context').setup {
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
multiwindow = false, -- Enable multiwindow support.
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
min_window_height = 0, -- Minimum editor window height to enable context. Values <= 0 mean no limit.
line_numbers = true,
multiline_threshold = 20, -- Maximum number of lines to show for a single context
trim_scope = 'outer', -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
mode = 'topline', -- Line used to calculate context. Choices: 'cursor', 'topline'
trim_scope = 'inner', -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
mode = 'cursor', -- Line used to calculate context. Choices: 'cursor', 'topline'
-- Separator between context and content. Should be a single character string, like '-'.
-- When separator is set, the context will only show up when there are at least 2 lines above cursorline.
separator = nil,
@ -17,4 +17,7 @@ return {
on_attach = nil, -- (fun(buf: integer): boolean) return false to disable attaching
}
end,
vim.keymap.set('n', '[c', function()
require('treesitter-context').go_to_context(vim.v.count1)
end, { silent = true, desc = '[C]ontext (upwards)' }),
}