vim: make it easy to reload plugin configs with :lua R('...').config()

This commit is contained in:
Fernando Schauenburg 2023-08-18 00:05:47 +02:00
parent 350d0073f7
commit b185ac5311
8 changed files with 177 additions and 168 deletions

View file

@ -9,15 +9,17 @@ M.lazy = false -- trows an error when lazy loading
local chars = { '', '¦', '', '', '', '', '', '', '', '' } local chars = { '', '¦', '', '', '', '', '', '', '', '' }
local show_first_level = false local show_first_level = false
M.opts = { M.config = function()
enabled = false, require('indent_blankline').setup {
use_treesitter = true, enabled = false,
show_first_indent_level = show_first_level, use_treesitter = true,
show_current_context = true, show_first_indent_level = show_first_level,
show_trailing_blankline_indent = false, show_current_context = true,
char_list = chars, show_trailing_blankline_indent = false,
context_char_list = chars, char_list = chars,
indent_level = #chars + (not show_first_level and 1 or 0), context_char_list = chars,
} indent_level = #chars + (not show_first_level and 1 or 0),
}
end
return M return M

View file

@ -8,20 +8,22 @@ M.keys = {
{ '<leader>gn', '<cmd>Neogit<cr>' }, { '<leader>gn', '<cmd>Neogit<cr>' },
} }
M.opts = { M.config = function()
disable_hint = true, require('neogit').setup {
signs = { disable_hint = true,
section = { '', '' }, signs = {
item = { '', '' }, section = { '', '' },
hunk = { '', '' }, item = { '', '' },
}, hunk = { '', '' },
mappings = {
status = {
o = 'GoToFile',
['='] = 'Toggle',
}, },
}, mappings = {
} status = {
o = 'GoToFile',
['='] = 'Toggle',
},
},
}
end
return M return M

View file

@ -10,68 +10,70 @@ M.keys = {
{ '<leader>nc', '<cmd>NvimTreeClose<cr>' }, { '<leader>nc', '<cmd>NvimTreeClose<cr>' },
} }
M.opts = { M.config = function()
disable_netrw = true, -- replace netrw with nvim-tree require('nvim-tree').setup {
hijack_cursor = true, -- keep the cursor on begin of the filename disable_netrw = true, -- replace netrw with nvim-tree
sync_root_with_cwd = true, -- watch for `DirChanged` and refresh the tree hijack_cursor = true, -- keep the cursor on begin of the filename
sync_root_with_cwd = true, -- watch for `DirChanged` and refresh the tree
on_attach = function(bufnr) on_attach = function(bufnr)
local api = require('nvim-tree.api') local api = require('nvim-tree.api')
api.config.mappings.default_on_attach(bufnr) api.config.mappings.default_on_attach(bufnr)
local opts = function(desc) local opts = function(desc)
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, silent = true } return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, silent = true }
end end
vim.keymap.set('n', 'l', api.node.open.edit, opts('open')) vim.keymap.set('n', 'l', api.node.open.edit, opts('open'))
vim.keymap.set('n', '<CR>', api.node.open.edit, opts('open')) vim.keymap.set('n', '<CR>', api.node.open.edit, opts('open'))
vim.keymap.set('n', 'o', api.node.open.edit, opts('open')) vim.keymap.set('n', 'o', api.node.open.edit, opts('open'))
vim.keymap.set('n', 'h', api.node.navigate.parent_close, opts('close directory')) vim.keymap.set('n', 'h', api.node.navigate.parent_close, opts('close directory'))
end, end,
git = { git = {
ignore = false, -- don't hide files from .gitignore ignore = false, -- don't hide files from .gitignore
}, },
view = { view = {
adaptive_size = true, -- resize the window based on the longest line adaptive_size = true, -- resize the window based on the longest line
width = 35, -- a little wider than the default 30 width = 35, -- a little wider than the default 30
}, },
filters = { filters = {
dotfiles = false, -- show files starting with a . dotfiles = false, -- show files starting with a .
custom = { '^\\.git' }, -- don't show .git directory custom = { '^\\.git' }, -- don't show .git directory
}, },
renderer = { renderer = {
add_trailing = true, -- add trailing / to folders add_trailing = true, -- add trailing / to folders
highlight_git = true, -- enable highlight based on git attributes highlight_git = true, -- enable highlight based on git attributes
icons = { icons = {
git_placement = 'after', git_placement = 'after',
glyphs = { glyphs = {
default = '', default = '',
symlink = '', symlink = '',
modified = '', modified = '',
folder = { folder = {
arrow_closed = '', --    arrow_closed = '', --   
arrow_open = '', --    arrow_open = '', --   
default = '', --   default = '', --  
open = '', --   open = '', --  
empty = '', empty = '',
empty_open = '', empty_open = '',
symlink = '', symlink = '',
symlink_open = '', symlink_open = '',
}, },
git = { git = {
untracked = '?', -- ★ untracked = '?', -- ★
unstaged = '', -- ✗ unstaged = '', -- ✗
staged = '', -- ✓ staged = '', -- ✓
deleted = '', deleted = '',
unmerged = '', unmerged = '',
renamed = '', renamed = '',
ignored = '', ignored = '',
},
}, },
}, },
}, },
}, }
} end
return M return M

View file

@ -118,7 +118,7 @@ M.keys = {
{ '<leader>f<leader>', pickers.resume '󰐎 Resume' , desc = ' Telescope Resume ' }, { '<leader>f<leader>', pickers.resume '󰐎 Resume' , desc = ' Telescope Resume ' },
} }
M.opts = function() M.config = function()
local actions = require('telescope.actions') local actions = require('telescope.actions')
local layout = require('telescope.actions.layout') local layout = require('telescope.actions.layout')
local trouble = vim.F.npcall(require, 'trouble.providers.telescope') or {} local trouble = vim.F.npcall(require, 'trouble.providers.telescope') or {}
@ -136,7 +136,7 @@ M.opts = function()
['<c-b>'] = trouble.smart_open_with_trouble, ['<c-b>'] = trouble.smart_open_with_trouble,
} }
return { require('telescope').setup {
defaults = { defaults = {
mappings = { mappings = {
i = mappings, i = mappings,
@ -182,10 +182,7 @@ M.opts = function()
}, },
}, },
} }
end
M.config = function(_, opts)
require('telescope').setup(opts)
require('telescope').load_extension 'fzf' require('telescope').load_extension 'fzf'
vim.api.nvim_create_autocmd('User', { vim.api.nvim_create_autocmd('User', {

View file

@ -14,17 +14,19 @@ M.keys = {
{ '<leader>ft', '<cmd>TodoTelescope<cr>' }, { '<leader>ft', '<cmd>TodoTelescope<cr>' },
} }
M.opts = { M.config = function()
keywords = { require('todo-comments').setup {
TODO = { icon = '󰄬 ' }, keywords = {
FIX = { icon = '' }, TODO = { icon = '󰄬 ' },
HACK = { icon = '' }, FIX = { icon = '' },
WARN = { icon = '' }, HACK = { icon = '' },
PERF = { icon = '󰓅 ' }, WARN = { icon = '' },
NOTE = { icon = '' }, PERF = { icon = '󰓅 ' },
TEST = { icon = '󰙨 ' }, NOTE = { icon = '' },
}, TEST = { icon = '󰙨 ' },
} },
}
end
return M return M

View file

@ -27,84 +27,84 @@ M.keys = {
{ '<leader>tn', '<cmd>TSNodeUnderCursor<cr>' }, { '<leader>tn', '<cmd>TSNodeUnderCursor<cr>' },
} }
M.main = 'nvim-treesitter.configs' M.config = function()
require('nvim-treesitter.configs').setup {
M.opts = { ensure_installed = {
ensure_installed = { 'bash',
'bash', 'c',
'c', 'cpp',
'cpp', 'haskell',
'haskell', 'html',
'html', 'javascript',
'javascript', 'latex',
'latex', 'lua',
'lua', 'make',
'make', 'markdown',
'markdown', 'markdown_inline',
'markdown_inline', 'python',
'python', 'query',
'query', 'toml',
'toml', 'vim',
'vim',
'vimdoc',
'yaml',
},
highlight = {
enable = true,
disable = {
'vimdoc', 'vimdoc',
'yaml',
}, },
}, highlight = {
incremental_selection = {
enable = true,
keymaps = {
init_selection = 'gnn', -- mapped in normal mode
node_incremental = '<CR>', -- mapped in visual mode
node_decremental = '<BS>', -- mapped in visual mode
scope_incremental = nil, -- disabled, normally mapped in visual mode
},
},
refactor = {
highlight_definitions = { enable = true },
highlight_current_scope = { enable = false },
smart_rename = {
enable = true, enable = true,
keymaps = { disable = {
smart_rename = 'grr', 'vimdoc',
}, },
}, },
navigation = { incremental_selection = {
enable = true, enable = true,
keymaps = { keymaps = {
goto_definition = 'gd', -- default: 'gnd' init_selection = 'gnn', -- mapped in normal mode
list_definitions = nil, -- disabled, default: 'gnD' node_incremental = '<CR>', -- mapped in visual mode
list_definitions_toc = 'gO', node_decremental = '<BS>', -- mapped in visual mode
goto_next_usage = '<a-*>', scope_incremental = nil, -- disabled, normally mapped in visual mode
goto_previous_usage = '<a-#>',
}, },
}, },
}, refactor = {
textobjects = { highlight_definitions = { enable = true },
select = { highlight_current_scope = { enable = false },
smart_rename = {
enable = true,
keymaps = {
smart_rename = 'grr',
},
},
navigation = {
enable = true,
keymaps = {
goto_definition = 'gd', -- default: 'gnd'
list_definitions = nil, -- disabled, default: 'gnD'
list_definitions_toc = 'gO',
goto_next_usage = '<a-*>',
goto_previous_usage = '<a-#>',
},
},
},
textobjects = {
select = {
enable = true,
keymaps = {
['ab'] = '@block.outer',
['ib'] = '@block.inner',
['ac'] = '@conditional.outer',
['ic'] = '@conditional.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['al'] = '@loop.outer',
['il'] = '@loop.inner',
['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner',
},
},
},
playground = {
enable = true, enable = true,
keymaps = {
['ab'] = '@block.outer',
['ib'] = '@block.inner',
['ac'] = '@conditional.outer',
['ic'] = '@conditional.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['al'] = '@loop.outer',
['il'] = '@loop.inner',
['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner',
},
}, },
}, }
playground = { end
enable = true,
},
}
return M return M

View file

@ -10,10 +10,12 @@ M.keys = {
{ '<leader>ld', '<cmd>TroubleToggle document_diagnostics<cr>' }, { '<leader>ld', '<cmd>TroubleToggle document_diagnostics<cr>' },
} }
M.opts = { M.config = function()
padding = false, -- don't add an extra new line of top of the list require('trouble').setup {
auto_preview = false, -- don't preview automatically padding = false, -- don't add an extra new line of top of the list
} auto_preview = false, -- don't preview automatically
}
end
return M return M

View file

@ -17,9 +17,11 @@ M.keys = {
{ '<leader>sc', toggle_colorcolumn, desc = 'Toggle virtual colunn' }, { '<leader>sc', toggle_colorcolumn, desc = 'Toggle virtual colunn' },
} }
M.opts = { M.config = function()
char = '', require('virt-column').setup {
} char = '',
}
end
return M return M