diff --git a/home/.config/nvim/init.lua b/home/.config/nvim/init.lua index c2f8b84..1b365f4 100644 --- a/home/.config/nvim/init.lua +++ b/home/.config/nvim/init.lua @@ -1,5 +1,6 @@ local async async = vim.loop.new_async(vim.schedule_wrap(function() + require('autocmd') require('plugins') require('mappings') async:close() @@ -10,5 +11,4 @@ local options = require('options') options.disable_default_plugins() options.load_options() require('colors.' .. vim.g.global_theme).highlight() -require('autocmd') async:send() diff --git a/home/.config/nvim/lua/autocmd.lua b/home/.config/nvim/lua/autocmd.lua index 85dc192..6a9b5cf 100644 --- a/home/.config/nvim/lua/autocmd.lua +++ b/home/.config/nvim/lua/autocmd.lua @@ -1,20 +1,16 @@ local definitions = { - -- ':h hex-editing' - -- binary = { - -- {'BufReadPre' , '*.bin,*.exe', 'let &bin=1'}, - -- {'BufReadPost' , '*.bin,*.exe', 'if &bin | %!xxd'}, - -- {'BufReadPost' , '*.bin,*.exe', 'set ft=xxd | endif'}, - -- {'BufWritePre' , '*.bin,*.exe', 'if &bin | %!xxd -r'}, - -- {'BufWritePre' , '*.bin,*.exe', 'endif'}, - -- {'BufWritePost', '*.bin,*.exe', 'if &bin | %!xxd'}, - -- {'BufWritePost', '*.bin,*.exe', 'set nomod | endif'} - -- }, - - -- Auto-hide UI elements in specific buffers - -- buf = { - -- {'BufEnter', 'term://*', 'setlocal norelativenumber nonumber'}, - -- {'BufEnter,BufWinEnter,WinEnter,CmdwinEnter', '*', [[if bufname('%') == 'NvimTree' | set laststatus=0 | else | set laststatus=2 | endif]]} - -- }, + bufs = { + -- Reload vim config automatically + {'BufWritePost', [[$VIM_PATH/{*.vim,*.yaml,vimrc} nested source $MYVIMRC | redraw]]}, + -- Reload Vim script automatically if setlocal autoread + {'BufWritePost,FileWritePost', '*.vim', [[nested if &l:autoread > 0 | source | echo 'source ' . bufname('%') | endif]]}, + -- No undo for temporary files + {'BufWritePre', '/tmp/*', 'setlocal noundofile'}, + {'BufWritePre', 'COMMIT_EDITMSG', 'setlocal noundofile'}, + {'BufWritePre', 'MERGE_MSG', 'setlocal noundofile'}, + {'BufWritePre', '*.tmp', 'setlocal noundofile'}, + {'BufWritePre', '*.bak', 'setlocal noundofile'} + }, wins = { -- Equalize window dimensions when resizing vim window @@ -22,7 +18,7 @@ local definitions = { -- Force writing shada on leaving nvim {'VimLeave', '*', [[if has('nvim') | wshada! | else | wviminfo! | endif]]}, -- Check if file changed when its window is focus, more eager than 'autoread' - -- {'FocusGained', '* checktime'} + {'FocusGained', '* checktime'} }, yank = { diff --git a/home/.config/nvim/lua/colors/nord.lua b/home/.config/nvim/lua/colors/nord.lua index 59ffe76..84748df 100644 --- a/home/.config/nvim/lua/colors/nord.lua +++ b/home/.config/nvim/lua/colors/nord.lua @@ -280,27 +280,27 @@ local function highlight_lsp() vim.api.nvim_command('hi! link LspCodeLens Comment') -- Theses are for neovim 0.6 - vim.api.nvim_command('hi! link DiagnosticVirtualTextWarn LspDiagnosticsVirtualTextWarning') - vim.api.nvim_command('hi! link DiagnosticUnderlineWarn LspDiagnosticsUnderlineWarning') - vim.api.nvim_command('hi! link DiagnosticFloatingWarn LspDiagnosticsFloatingWarning') - vim.api.nvim_command('hi! link DiagnosticSignWarn LspDiagnosticsSignWarning') - vim.api.nvim_command('hi! link DiagnosticVirtualTextError LspDiagnosticsVirtualTextError') - vim.api.nvim_command('hi! link DiagnosticUnderlineError LspDiagnosticsUnderlineError') - vim.api.nvim_command('hi! link DiagnosticFloatingError LspDiagnosticsFloatingError') - vim.api.nvim_command('hi! link DiagnosticSignError LspDiagnosticsSignError') - vim.api.nvim_command('hi! link DiagnosticVirtualTextInfo LspDiagnosticsVirtualTextInformation') - vim.api.nvim_command('hi! link DiagnosticUnderlineInfo LspDiagnosticsUnderlineInformation') - vim.api.nvim_command('hi! link DiagnosticFloatingInfo LspDiagnosticsFloatingInformation') - vim.api.nvim_command('hi! link DiagnosticSignInfo LspDiagnosticsSignInformation') - vim.api.nvim_command('hi! link DiagnosticVirtualTextHint LspDiagnosticsVirtualTextHint') - vim.api.nvim_command('hi! link DiagnosticUnderlineHint LspDiagnosticsUnderlineHint') - vim.api.nvim_command('hi! link DiagnosticFloatingHint LspDiagnosticsFloatingHint') - vim.api.nvim_command('hi! link DiagnosticSignHint LspDiagnosticsSignHint') + -- vim.api.nvim_command('hi! link DiagnosticVirtualTextWarn LspDiagnosticsVirtualTextWarning') + -- vim.api.nvim_command('hi! link DiagnosticUnderlineWarn LspDiagnosticsUnderlineWarning') + -- vim.api.nvim_command('hi! link DiagnosticFloatingWarn LspDiagnosticsFloatingWarning') + -- vim.api.nvim_command('hi! link DiagnosticSignWarn LspDiagnosticsSignWarning') + -- vim.api.nvim_command('hi! link DiagnosticVirtualTextError LspDiagnosticsVirtualTextError') + -- vim.api.nvim_command('hi! link DiagnosticUnderlineError LspDiagnosticsUnderlineError') + -- vim.api.nvim_command('hi! link DiagnosticFloatingError LspDiagnosticsFloatingError') + -- vim.api.nvim_command('hi! link DiagnosticSignError LspDiagnosticsSignError') + -- vim.api.nvim_command('hi! link DiagnosticVirtualTextInfo LspDiagnosticsVirtualTextInformation') + -- vim.api.nvim_command('hi! link DiagnosticUnderlineInfo LspDiagnosticsUnderlineInformation') + -- vim.api.nvim_command('hi! link DiagnosticFloatingInfo LspDiagnosticsFloatingInformation') + -- vim.api.nvim_command('hi! link DiagnosticSignInfo LspDiagnosticsSignInformation') + -- vim.api.nvim_command('hi! link DiagnosticVirtualTextHint LspDiagnosticsVirtualTextHint') + -- vim.api.nvim_command('hi! link DiagnosticUnderlineHint LspDiagnosticsUnderlineHint') + -- vim.api.nvim_command('hi! link DiagnosticFloatingHint LspDiagnosticsFloatingHint') + -- vim.api.nvim_command('hi! link DiagnosticSignHint LspDiagnosticsSignHint') end -- Specify groups for plugins local function highlight_plugins() - -- nvim-cmp (experimental custom menu) + -- nvim-cmp hi('CmpItemAbbr', c.fg, '', '', '') hi('CmpItemAbbrMatch', c.yellow, '', '', '') hi('CmpItemAbbrMatchFuzzy', c.yellow, '', '', '') @@ -365,8 +365,13 @@ local function highlight_plugins() hi('IndentBlanklineChar', c.grey1, '', '', '') hi('IndentBlanklineContextChar', c.grey1, '', '', '') + -- window-picker.nvim + hi('WindowPicker', c.fg, c.blue, 'bold', '') + hi('WindowPickerSwap', c.fg, c.orange, 'bold', '') + -- vim-illuminate vim.api.nvim_command('hi! link illuminatedWord Underline') + vim.api.nvim_command('hi! link illuminatedCurWord Underline') -- trouble.nvim hi('LspTroubleText', c.blue, '', 'bold', '') diff --git a/home/.config/nvim/lua/colors/onedark.lua b/home/.config/nvim/lua/colors/onedark.lua index d797127..84e1525 100644 --- a/home/.config/nvim/lua/colors/onedark.lua +++ b/home/.config/nvim/lua/colors/onedark.lua @@ -1,15 +1,5 @@ local M = {} -local function hi(group, guifg, guibg, attr, guisp) - local fg = guifg ~= '' and 'guifg=' .. guifg or 'guifg=NONE' - local bg = guibg ~= '' and 'guibg=' .. guibg or 'guibg=NONE' - local style = attr ~= '' and 'gui=' .. attr or 'gui=NONE' - local sp = guisp ~= '' and 'guisp=' .. guisp or '' - - local hl = 'hi ' .. group .. ' ' .. fg .. ' ' .. bg .. ' ' .. style .. ' ' .. sp - vim.api.nvim_command(hl) -end - M.colors = { black = '#282C34', grey1 = '#3E4452', @@ -34,6 +24,16 @@ M.colors = { local c = M.colors +local function hi(group, guifg, guibg, attr, guisp) + local fg = guifg ~= '' and 'guifg=' .. guifg or 'guifg=NONE' + local bg = guibg ~= '' and 'guibg=' .. guibg or 'guibg=NONE' + local style = attr ~= '' and 'gui=' .. attr or 'gui=NONE' + local sp = guisp ~= '' and 'guisp=' .. guisp or '' + + local hl = 'hi ' .. group .. ' ' .. fg .. ' ' .. bg .. ' ' .. style .. ' ' .. sp + vim.api.nvim_command(hl) +end + function M.highlight() hi('ModeMsg', c.green, '', '', '') end diff --git a/home/.config/nvim/lua/mappings.lua b/home/.config/nvim/lua/mappings.lua index 82daf07..16bd075 100644 --- a/home/.config/nvim/lua/mappings.lua +++ b/home/.config/nvim/lua/mappings.lua @@ -18,9 +18,6 @@ local function pandoc_convert(ofiletype) vim.fn.jobstart(cmd) end --- No one likes Esc -api.nvim_set_keymap('i', 'jk', [[]], {noremap = true, silent = true}) - -- Escape to normal mode in terminal buffer api.nvim_set_keymap('t', '', '', {noremap = true, silent = true}) @@ -28,17 +25,13 @@ api.nvim_set_keymap('t', '', '', {noremap = true, silent = true} api.nvim_set_keymap('v', '<', '', '>gv', {noremap = true, silent = true}) --- vim-eft -api.nvim_set_keymap('n', 'f', '(eft-f)', {}) -api.nvim_set_keymap('x', 'f', '(eft-f)', {}) -api.nvim_set_keymap('n', 'F', '(eft-F)', {}) -api.nvim_set_keymap('x', 'F', '(eft-F)', {}) -api.nvim_set_keymap('n', 't', '(eft-t)', {}) -api.nvim_set_keymap('x', 't', '(eft-t)', {}) -api.nvim_set_keymap('n', 'T', '(eft-T)', {}) -api.nvim_set_keymap('x', 'T', '(eft-T)', {}) -api.nvim_set_keymap('n', ';', '(eft-repeat)', {}) -api.nvim_set_keymap('x', ';', '(eft-repeat)', {}) +-- winshift.nvim +api.nvim_set_keymap('n', '', ':WinShift', {noremap = true, silent = true}) +api.nvim_set_keymap('n', 'm', ':WinShift', {noremap = true, silent = true}) +api.nvim_set_keymap('n', '', ':WinShift left', {noremap = true, silent = true}) +api.nvim_set_keymap('n', '', ':WinShift down', {noremap = true, silent = true}) +api.nvim_set_keymap('n', '', ':WinShift up', {noremap = true, silent = true}) +api.nvim_set_keymap('n', '', ':WinShift right', {noremap = true, silent = true}) ----------------- -- Normal mode -- @@ -51,18 +44,14 @@ wk.register({ H = {'^', 'Start of the line'}, L = {'$', 'End of the line'}, - -- Easier moving between windows - -- [''] = {'h', 'Go to the left window'}, - -- [''] = {'l', 'Go to the right window'}, - -- [''] = {'j', 'Go to the down window'}, - -- [''] = {'k', 'Go to the up window'}, - [''] = {'q', 'Quit a window'}, + -- Close a window + [''] = {'q', 'Quit current window'}, -- Copy the whole buffer - [''] = {'%y+', 'Copy whole buffer'}, + [''] = {':%y+', 'Copy whole buffer'}, -- Close buffer - [''] = {':bd!', 'Close buffer'}, + [''] = {':bdelete', 'Close current buffer'}, -- Remove trailing whitespace [''] = {':%s/\\s\\+$//e', 'Remove trailing'}, @@ -108,14 +97,17 @@ wk.register({ D = 'Go to declaration', i = 'Go to implementation', r = 'Go to references', - R = {'TroubleToggle lsp_references', 'Reference list'} + R = {':TroubleToggle lsp_references', 'Reference list'} }, K = {name = 'Hover'}, z = {name = 'Misc utils'}, + -- Window picker + ['-'] = {':WindowPick', 'Choose window'}, + -- Move between tabs - [''] = {'BufferLineCycleNext', 'Next buffer'}, - [''] = {'BufferLineCyclePrev', 'Previous buffer'}, + [''] = {':BufferLineCycleNext', 'Next buffer'}, + [''] = {':BufferLineCyclePrev', 'Previous buffer'}, -- NvimTree [''] = {':NvimTreeToggle', 'NvimTree'}, @@ -134,25 +126,21 @@ wk.register({ -- Normal mode (with leader key) -- ----------------------------------- wk.register({ - a = { - name = 'Action', - a = {':EasyAlign', 'Align elements'}, - s = {':ISwapWith', 'Swap elements'} - }, - b = { - name = 'Buffer/Tab', + name = 'Buffer', c = {':ColorizerToggle', 'Colorizer'}, - d = {':bdelete', 'Close buffer'}, + d = { + name = 'Delete', + a = {':BDelete all', 'All buffers'}, + d = {':BDelete this', 'Current buffer'}, + h = {':BDelete hidden', 'Hidden buffers'}, + n = {':BDelete nameless', 'Buffers without name'}, + o = {':BDelete other', 'Other buffers'} + }, j = {':BufferLineCyclePrev', 'Previous buffer'}, k = {':BufferLineCycleNext', 'Next buffer'}, n = {':enew', 'New buffer'}, u = {':UndotreeToggle', 'Undotree'}, - z = {':ZenMode', 'Zen mode'}, - D = {'tabclose', 'Close tab'}, - J = {'tabprev', 'Previous tab'}, - K = {'tabnext', 'Next tab'}, - N = {'tabnew', 'New tab'}, v = { name = 'Convert', m = {function() pandoc_convert('md') end, 'To Markdown'}, @@ -166,23 +154,29 @@ wk.register({ d = { name = 'DAP', - b = {':lua require("dap").toggle_breakpoint()', 'Toggle breakpoint'}, - c = {':lua require("dapui").close()', 'Close UI'}, - e = {':lua require("dapui").eval()', 'Evaluate cursorword'}, - f = {':lua require("dapui").float_element()', 'Float elements'}, - i = {':lua require("dap").repl.open()', 'Inspect via REPL'}, - n = {':lua require("dap").step_into()', 'Step through code'}, - o = {':lua require("dapui").open()', 'Open UI'}, - s = {':lua require("dap").continue()', 'Debug session'}, - t = {':lua require("dapui").open()', 'Toggle UI'} + b = 'Toggle breakpoint', + B = 'Set breakpoint with condition', + c = 'Run to cursor', + d = 'Disconnect adapter', + e = 'Hover under cursor (UI)', + f = 'Open float window (UI)', + i = 'Step into function/method', + l = 'List breakpoints', + n = 'Resume the execution', + o = 'Step out of function/method', + r = 'Inspect in REPL', + t = 'Toggle UI', + v = 'Run again 1 step', + z = 'Re-run the last adapter' }, e = { - name = 'Session', - s = {':lua require("persistence").save()', 'Save session for current directory'}, - d = {':lua require("persistence").stop()', 'Stop automatically saving'}, - l = {':lua require("persistence").load({last = true})', 'Load last session'}, - r = {':lua require("persistence").load()', 'Load session for current directory'} + name = 'Editor', + a = {':EasyAlign', 'Align elements'}, + g = 'Generate annotations', + s = {':ISwapWith', 'Swap elements'}, + t = {':Twilight', 'Twilight mode'}, + z = {':ZenMode', 'Zen mode'} }, -- Telescope @@ -223,6 +217,8 @@ wk.register({ S = 'Stage buffer', u = 'Undo hunk', U = 'Reset buffer index', + y = 'Get remote url for cursorline', + Y = 'Get remote url', n = {':Neogit', 'Neogit'}, f = { name = 'Telescope', @@ -279,6 +275,13 @@ wk.register({ } }, + p = { + name = 'Find/Replace', + o = 'Open spectre', + p = 'Search in current file', + w = 'Find/replace cursorword' + }, + r = { name = 'REST', c = {'RestNvim', 'Run request under cursor'}, @@ -287,10 +290,11 @@ wk.register({ }, s = { - name = 'Find/Replace', - o = {':lua require("spectre").open()', 'Open spectre'}, - p = {'viw:lua require("spectre").open_file_search()', 'Search in current file'}, - w = {':lua require("spectre").open_visual({select_word = true})', 'Find/replace cursorword'}, + name = 'Session', + s = 'Save session for current directory', + d = 'Stop automatically saving', + l = 'Load last session', + r = 'Load session for current directory' }, -- t = { @@ -327,13 +331,14 @@ wk.register({ d = { name = 'DAP', - e = {':lua require("dapui").eval()', 'Evaluate highlighted text'} + e = 'Hover on range (UI)' }, g = { name = 'Git', r = 'Reset hunk', - s = 'Stage hunk' + s = 'Stage hunk', + y = 'Get remote url for range' }, j = { @@ -344,7 +349,7 @@ wk.register({ c = {'c=system(\'trans -brief -no-ansi :\', getreg(""))[:-2]', 'Translate and replace with direction'} }, - s = {':lua require("spectre").open_visual()', 'Find/Replace'} + p = 'Find/Replace' }, {mode = 'v', prefix = ''}) ------------------------ diff --git a/home/.config/nvim/lua/modules/completion.lua b/home/.config/nvim/lua/modules/completion.lua index febcd31..b44c3a1 100644 --- a/home/.config/nvim/lua/modules/completion.lua +++ b/home/.config/nvim/lua/modules/completion.lua @@ -62,22 +62,25 @@ function M.cmp_conf() return vim_item end }, + -- documentation = { + -- border = {'╭', '─', '╮', '│', '╯', '─', '╰', '│'} + -- }, mapping = { [''] = cmp.mapping.complete(), [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.close(), + [''] = cmp.mapping.close(), -- Change choice nodes for luasnip - [''] = cmp.mapping(function(fallback) + [''] = cmp.mapping(function(fallback) if luasnip.choice_active() then luasnip.change_choice(-1) else fallback() end end, {'i', 's'}), - [''] = cmp.mapping(function(fallback) + [''] = cmp.mapping(function(fallback) if luasnip.choice_active() then luasnip.change_choice(1) else @@ -132,21 +135,21 @@ end -- function M.tabnine_conf() -- local tabnine = require('cmp_tabnine.config') --- tabnine:setup({ +-- tabnine:setup { -- max_lines = 1000, -- max_num_results = 20, -- sort = true, -- run_on_every_keystroke = true --- }) +-- } -- end function M.autopairs_conf() require('nvim-autopairs').setup {fast_wrap = {}} - require('nvim-autopairs.completion.cmp').setup({ + require('nvim-autopairs.completion.cmp').setup { map_cr = true, -- map on insert mode map_complete = true, -- it will auto insert `(` after select function or method item auto_select = true -- automatically select the first item - }) + } end function M.snippets_conf() @@ -189,12 +192,12 @@ end -- end function M.autotag_conf() - require('nvim-ts-autotag').setup({ + require('nvim-ts-autotag').setup { filetypes = { 'html', 'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'svelte', 'vue' } - }) + } end return M diff --git a/home/.config/nvim/lua/modules/editor.lua b/home/.config/nvim/lua/modules/editor.lua index d3d277e..4721c0c 100644 --- a/home/.config/nvim/lua/modules/editor.lua +++ b/home/.config/nvim/lua/modules/editor.lua @@ -16,6 +16,11 @@ function M.colorizer_conf() }) end +function M.illuminate_conf() + vim.g.Illuminate_delay = 500 + vim.g.Illuminate_ftblacklist = {'alpha', 'NvimTree', 'undotree', 'packer'} +end + function M.blankline_conf() require('indent_blankline').setup { char = '│', @@ -55,7 +60,7 @@ function M.treesitter_conf() parser_configs.http = { install_info = { url = 'https://github.com/NTBBloodbath/tree-sitter-http', - files = { 'src/parser.c' }, + files = {'src/parser.c'}, branch = 'main' } } @@ -99,6 +104,13 @@ function M.treesitter_conf() } end +-- function M.spellsitter_conf() +-- require('spellsitter').setup { +-- hl = 'SpellBad', +-- captures = {'comment'} +-- } +-- end + function M.iswap_conf() require('iswap').setup { -- The keys that will be used as a selection, in order @@ -141,16 +153,91 @@ function M.matchup_conf() vim.g.matchup_matchparen_offscreen = {method = 'popup'} end +function M.twilight_conf() + require('twilight').setup { + dimming = { + alpha = 0.25, -- amount of dimming + -- we try to get the foreground from the highlight groups or fallback color + color = {'Normal', '#ffffff'}, + inactive = false -- when true, other windows will be fully dimmed (unless they contain the same buffer) + }, + context = 10, + treesitter = true, + expand = { -- for treesitter, we we always try to expand to the top-most ancestor with these types + 'function', + 'method', + 'table', + 'if_statement' + }, + exclude = {'alpha', 'packer', 'NvimTree', 'qf'} + } +end + +function M.zenmode_conf() + require('zen-mode').setup { + window = { + options = { + signcolumn = 'no', + number = false, + relativenumber = false, + cursorline = false, + cursorcolumn = false, + foldcolumn = '0' + } + }, + -- on_open = function() + -- vim.api.nvim_command('TSContextDisable') + -- vim.api.nvim_command('IndentBlanklineDisable') + -- end, + -- on_close = function() + -- vim.api.nvim_command('TSContextEnable') + -- vim.api.nvim_command('IndentBlanklineEnable') + -- end + } +end + +function M.betterescape_conf() + require('better_escape').setup { + mapping = {'jk', 'kj'}, + timeout = vim.opt.timeoutlen:get(), + clear_empty_lines = false, + keys = '' + } +end + function M.hop_conf() require('hop').setup {keys = 'etovxqpdygfblzhckisuran'} end function M.eft_conf() vim.g.eft_index_function = {all = function() return true end} + + -- Mappings + vim.api.nvim_set_keymap('n', 'f', '(eft-f)', {}) + vim.api.nvim_set_keymap('x', 'f', '(eft-f)', {}) + vim.api.nvim_set_keymap('n', 'F', '(eft-F)', {}) + vim.api.nvim_set_keymap('x', 'F', '(eft-F)', {}) + vim.api.nvim_set_keymap('n', 't', '(eft-t)', {}) + vim.api.nvim_set_keymap('x', 't', '(eft-t)', {}) + vim.api.nvim_set_keymap('n', 'T', '(eft-T)', {}) + vim.api.nvim_set_keymap('x', 'T', '(eft-T)', {}) + vim.api.nvim_set_keymap('n', ';', '(eft-repeat)', {}) + vim.api.nvim_set_keymap('x', ';', '(eft-repeat)', {}) end function M.comment_conf() - require('nvim_comment').setup({comment_empty = false}) + require('nvim_comment').setup {comment_empty = false} +end + +function M.neogen_conf() + require('neogen').setup { + enabled = true, + input_after_comment = true, + jump_map = '' + } + + -- Mappings + vim.api.nvim_set_keymap('n', 'eg', ':lua require("neogen").generate()', {noremap = true, silent = true}) end function M.project_conf() @@ -162,6 +249,40 @@ function M.project_conf() silent_chdir = true, datapath = vim.fn.stdpath('data') } + + -- cd on local window changes with 'lcd' (more eager) + -- see https://github.com/ahmedkhalf/project.nvim/issues/23 + -- _G.set_window_project_dir = function() + -- local root, _ = require('project_nvim.project').get_project_root() + -- if root then + -- vim.api.nvim_command('lcd ' .. root) + -- end + -- end + -- vim.api.nvim_command('autocmd BufEnter * lua set_window_project_dir()') +end + +function M.gitlinker_conf() + require('gitlinker').setup { + opts = { + remote = nil, -- force the use of a specific remote + -- adds current line nr in the url for normal mode + add_current_line_on_normal_mode = true, + -- callback for what to do with the url + action_callback = require('gitlinker.actions').copy_to_clipboard, + -- print the url after performing the action + print_url = true, + }, + callbacks = { + ['git.folliehiyuki.com'] = require('gitlinker.hosts').get_gitea_type_url, + ['git.disroot.org'] = require('gitlinker.hosts').get_gitea_type_url, + ['gitlab.alpinelinux.org'] = require('gitlinker.hosts').get_gitlab_type_url + }, + -- default mapping to call url generation with action_callback + mappings = 'gy' + } + + -- Mapping to get remote url + vim.api.nvim_set_keymap('n', 'gY', ':lua require("gitlinker").get_repo_url()', {noremap = true, silent = true}) end return M diff --git a/home/.config/nvim/lua/modules/lsp.lua b/home/.config/nvim/lua/modules/lsp.lua index bee141b..491e868 100644 --- a/home/.config/nvim/lua/modules/lsp.lua +++ b/home/.config/nvim/lua/modules/lsp.lua @@ -284,9 +284,9 @@ function M.lsp_conf() -- Replace the default lsp diagnostic letters with prettier symbols vim.fn.sign_define('LspDiagnosticsSignError', {text = ''}) - vim.fn.sign_define('LspDiagnosticsSignWarning', {text = ''}) + vim.fn.sign_define('LspDiagnosticsSignWarning', {text = ''}) vim.fn.sign_define('LspDiagnosticsSignInformation', {text = ''}) - vim.fn.sign_define('LspDiagnosticsSignHint', {text = ''}) + vim.fn.sign_define('LspDiagnosticsSignHint', {text = ''}) end function M.sqls_conf() @@ -295,6 +295,12 @@ function M.sqls_conf() } end +function M.lightbulb_conf() + vim.api.nvim_command [[ + autocmd CursorHold,CursorHoldI * lua require('nvim-lightbulb').update_lightbulb {sign = {enabled = false}, status_text = {enabled = true, text = ' Code action', text_unavailable = ''}} + ]] +end + function M.trouble_conf() require('trouble').setup { mode = 'lsp_workspace_diagnostics', @@ -307,9 +313,9 @@ function M.trouble_conf() }, signs = { error = '', - warning = '', - hint = '', + warning = '', information = '', + hint = '', other = '' } } @@ -379,13 +385,75 @@ end function M.dap_conf() local dap = require('dap') - vim.fn.sign_define('DapBreakpoint', {text='', texthl='Red'}) - vim.fn.sign_define('DapLogPoint', {text='', texthl='Red'}) - vim.fn.sign_define('DapStopped', {text='', texthl='Red'}) - vim.fn.sign_define('DapBreakpointRejected', {text='ﱢ', texthl='Red'}) + vim.fn.sign_define('DapBreakpoint', {text='', texthl='Orange'}) + vim.fn.sign_define('DapLogPoint', {text='', texthl='Orange'}) + vim.fn.sign_define('DapStopped', {text='ﱢ', texthl='Orange'}) + vim.fn.sign_define('DapBreakpointRejected', {text='', texthl='Red'}) + + -- Mappings + vim.api.nvim_command('n', 'dn', ':lua require("dap").continue()', {noremap = true, silent = true}) + vim.api.nvim_command('n', 'dd', ':lua require("dap").disconnect()', {noremap = true, silent = true}) + vim.api.nvim_command('n', 'db', ':lua require("dap").toggle_breakpoint()', {noremap = true, silent = true}) + vim.api.nvim_command('n', 'dB', ':lua require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: "))', {noremap = true, silent = true}) + vim.api.nvim_command('n', 'dl', ':lua require("dap").list_breakpoints()', {noremap = true, silent = true}) + vim.api.nvim_command('n', 'dc', ':lua require("dap").run_to_cursor()', {noremap = true, silent = true}) + vim.api.nvim_command('n', 'dz', ':lua require("dap").run_last()', {noremap = true, silent = true}) + vim.api.nvim_command('n', '', ':lua require("dap").step_over()', {noremap = true, silent = true}) + vim.api.nvim_command('n', 'dv', ':lua require("dap").step_over()', {noremap = true, silent = true}) + vim.api.nvim_command('n', '', ':lua require("dap").step_into()', {noremap = true, silent = true}) + vim.api.nvim_command('n', 'di', ':lua require("dap").step_into()', {noremap = true, silent = true}) + vim.api.nvim_command('n', '', ':lua require("dap").step_out()', {noremap = true, silent = true}) + vim.api.nvim_command('n', 'do', ':lua require("dap").step_out()', {noremap = true, silent = true}) + vim.api.nvim_command('n', 'dr', ':lua require("dap").repl.open()', {noremap = true, silent = true}) end function M.dapui_conf() + local dap, dapui = require('dap'), require('dapui') + dap.listeners.after.event_initialized['dapui_config'] = function() dapui.open() end + dap.listeners.before.event_terminated['dapui_config'] = function() dapui.close() end + dap.listeners.before.event_exited['dapui_config'] = function() dapui.close() end + + require('dapui').setup { + icons = {expanded = '', collapsed = ''}, + mappings = { + expand = {'', '<2-LeftMouse>'}, + open = 'o', + remove = 'd', + edit = 'e', + repl = 'r' + }, + sidebar = { + elements = { + -- Provide as ID strings or tables with 'id' and 'size' keys + -- 'size' can be float or integer > 1 + {id = 'scopes', size = 0.25}, + {id = 'breakpoints', size = 0.25}, + {id = 'stacks', size = 0.25}, + {id = 'watches', size = 0.25}, + }, + size = 40, + position = 'left' + }, + tray = { + elements = {'repl'}, + size = 10, + position = 'bottom' + }, + floating = { + max_height = nil, -- These can be integers or a float between 0 and 1. + max_width = nil, -- Floats will be treated as percentage of your screen. + mappings = { + close = {'q', ''} + } + }, + windows = {indent = 1} + } + + -- Mappings + vim.api.nvim_set_keymap('n', 'de', ':lua require("dapui").eval()', {noremap = true, silent = true}) + vim.api.nvim_set_keymap('v', 'de', ':lua require("dapui").eval()', {noremap = true, silent = true}) + vim.api.nvim_set_keymap('n', 'df', ':lua require("dapui").float_element()', {noremap = true, silent = true}) + vim.api.nvim_set_keymap('n', 'dt', ':lua require("dapui").toggle()', {noremap = true, silent = true}) end return M diff --git a/home/.config/nvim/lua/modules/tools.lua b/home/.config/nvim/lua/modules/tools.lua index bd73d52..ab71fea 100644 --- a/home/.config/nvim/lua/modules/tools.lua +++ b/home/.config/nvim/lua/modules/tools.lua @@ -34,7 +34,7 @@ function M.telescope_conf() }, extensions = { project = { - base_dirs = {{'~/Code', max_depth = 4}}, + base_dirs = {{os.getenv('HOME') .. '/Code', max_depth = 4}}, hidden_files = true }, fzf = { @@ -92,7 +92,7 @@ function M.markdown_preview_conf() end function M.rest_conf() - require('rest-nvim').setup({ + require('rest-nvim').setup { -- Open request results in a horizontal split result_split_horizontal = false, -- Skip SSL verification, useful for unknown certificates @@ -104,36 +104,13 @@ function M.rest_conf() }, -- Jump to request line on run jump_to_request = false, - }) -end - -function M.zenmode_conf() - require('zen-mode').setup { - window = { - options = { - signcolumn = 'no', - number = false, - relativenumber = false, - cursorline = false, - cursorcolumn = false, - foldcolumn = '0' - } - }, - on_open = function() - vim.api.nvim_command('TSContextDisable') - vim.api.nvim_command('IndentBlanklineDisable') - end, - on_close = function() - vim.api.nvim_command('TSContextEnable') - -- vim.api.nvim_command('IndentBlanklineEnable') - end } end function M.orgmode_conf() local c = require('colors.' .. vim.g.global_theme).colors - require('orgmode').setup({ + require('orgmode').setup { -- General settings org_agenda_files = {'~/Documents/Org/agenda/*'}, org_default_notes_file = '~/Documents/Org/notes.org', @@ -166,7 +143,7 @@ function M.orgmode_conf() -- Tags settings org_use_tag_inheritance = false - }) + } end function M.vimtex_conf() @@ -174,6 +151,12 @@ end function M.spectre_conf() require('spectre').setup() + + -- Mappings + vim.api.nvim_set_keymap('n', 'po', ':lua require("spectre").open()', {noremap = true, silent = true}) + vim.api.nvim_set_keymap('n', 'pp', 'viw:lua require("spectre").open_file_search()', {noremap = true, silent = true}) + vim.api.nvim_set_keymap('n', 'pw', ':lua require("spectre").open_visual({select_word = true})', {noremap = true, silent = true}) + vim.api.nvim_set_keymap('v', 'p', ':lua require("spectre").open_visual()', {noremap = true, silent = true}) end function M.translate_conf() @@ -302,10 +285,16 @@ function M.session_conf() dir = vim.fn.expand(vim.fn.stdpath('data') .. '/sessions/'), options = {'buffers', 'curdir', 'tabpages', 'winsize'} } + + -- Mappings + vim.api.nvim_set_keymap('n', 'ss', ':lua require("persistence").save()', {noremap = true, silent = true}) + vim.api.nvim_set_keymap('n', 'sd', ':lua require("persistence").stop()', {noremap = true, silent = true}) + vim.api.nvim_set_keymap('n', 'sl', ':lua require("persistence").load({last = true})', {noremap = true, silent = true}) + vim.api.nvim_set_keymap('n', 'sr', ':lua require("persistence").load()', {noremap = true, silent = true}) end function M.filetype_conf() - require('filetype').setup({ + require('filetype').setup { overrides = { extensions = { md = 'markdown', @@ -321,10 +310,51 @@ function M.filetype_conf() }, complex = { ['*_log'] = 'log', - ['G*_LOG'] = 'log' + ['G*_LOG'] = 'log', + ['.*waybar/config'] = 'jsonc' } } - }) + } +end + +function M.closebuf_conf() + require('close_buffers').setup { + preserve_window_layout = {'this'}, + next_buffer_cmd = function(windows) + require('bufferline').cycle(1) + local bufnr = vim.api.nvim_get_current_buf() + + for _, window in ipairs(windows) do + vim.api.nvim_win_set_buf(window, bufnr) + end + end + } +end + +function M.winshift_conf() + require('winshift').setup { + highlight_moving_win = true, -- Highlight the window being moved + focused_hl_group = 'Visual', -- The highlight group used for the moving window + moving_win_options = { + -- These are local options applied to the moving window while it's + -- being moved. They are unset when you leave Win-Move mode. + wrap = false, + cursorline = false, + cursorcolumn = false, + colorcolumn = '', + } + } +end + +function M.winpicker_conf() + require('window-picker').setup { + keys = 'alskdjfhgwoeiruty', + -- Swap windows by holding shift + letter + swap_shift = true, + exclude = {qf = true, NvimTree = true, packer = true, alpha = true}, + -- Flash the cursor line of the newly focused window + flash_duration = 300 + } end return M diff --git a/home/.config/nvim/lua/modules/ui.lua b/home/.config/nvim/lua/modules/ui.lua index 29d7070..f171ab9 100644 --- a/home/.config/nvim/lua/modules/ui.lua +++ b/home/.config/nvim/lua/modules/ui.lua @@ -71,7 +71,7 @@ function M.dashboard_conf() button('SPC f d', 'ﱮ Recent directories'), button('SPC f m', ' Bookmarks'), button('SPC f p', ' Projects'), - button('SPC e l', ' Load last session') + button('SPC s l', ' Load last session') }, opts = {spacing = 1} } @@ -89,8 +89,8 @@ function M.dashboard_conf() -- Hide tabline in dashboard buffer vim.api.nvim_command [[ -autocmd FileType alpha set showtabline=0 | autocmd BufUnload set showtabline=2 -]] + autocmd FileType alpha set showtabline=0 | autocmd BufUnload set showtabline=2 + ]] end function M.statusline_conf() @@ -181,33 +181,46 @@ function M.statusline_conf() hl = {fg = colors.fg, style = 'bold'}, right_sep = ' ' }, + codeact = { + provider = function() + local present, state = pcall(require, 'nvim-lightbulb') + if present then + return state.get_status_text() + else + return '' + end + end, + hl = {fg = colors.green, style = 'bold'} + }, diagerr = { provider = 'diagnostic_errors', icon = ' ', hl = {fg = colors.red}, - right_sep = ' ' + left_sep = ' ' }, diagwarn = { provider = 'diagnostic_warnings', - icon = ' ', + icon = ' ', hl = {fg = colors.yellow}, - right_sep = ' ' + left_sep = ' ' }, diaghint = { provider = 'diagnostic_hints', - icon = ' ', + icon = ' ', hl = {fg = colors.cyan}, - right_sep = ' ' + left_sep = ' ' }, diaginfo = { provider = 'diagnostic_info', icon = ' ', - hl = {fg = colors.blue} + hl = {fg = colors.blue}, + left_sep = ' ' }, lspclient = { provider = 'lsp_client_names', icon = ' LSP:', - hl = {fg = colors.purple, style = 'bold'} + hl = {fg = colors.purple, style = 'bold'}, + left_sep = ' ' }, format = { provider = file_osinfo, @@ -268,10 +281,11 @@ function M.statusline_conf() table.insert(components.active[1], comps.fileinfo) table.insert(components.active[1], comps.lineinfo) table.insert(components.active[1], comps.percent) - table.insert(components.active[1], comps.diagerr) - table.insert(components.active[1], comps.diagwarn) - table.insert(components.active[1], comps.diaghint) - table.insert(components.active[1], comps.diaginfo) + table.insert(components.active[3], comps.codeact) + table.insert(components.active[3], comps.diagerr) + table.insert(components.active[3], comps.diagwarn) + table.insert(components.active[3], comps.diaghint) + table.insert(components.active[3], comps.diaginfo) table.insert(components.active[3], comps.lspclient) table.insert(components.active[3], comps.format) table.insert(components.active[3], comps.encode) @@ -351,9 +365,9 @@ function M.nvimtree_conf() git = { unstaged = '', staged = '', - unmerged = '', + unmerged = '', renamed = '', - untracked = '★', + untracked = 'ﱡ', deleted = '', ignored = '' }, @@ -361,17 +375,11 @@ function M.nvimtree_conf() arrow_open = '', arrow_closed = '', default = '', - open = '', + open = 'ﱮ', empty = '', empty_open = '', symlink = '', - symlink_open = '' - }, - lsp = { - hint = '', - info = '', - warning = '', - error = '' + symlink_open = 'ﱮ' } } @@ -386,7 +394,15 @@ function M.nvimtree_conf() }, hijack_cursor = true, update_cwd = true, - lsp_diagnostics = true, + diagnostics = { + enable = true, + icons = { + hint = '', + info = '', + warning = '', + error = '' + } + }, update_focused_file = { enable = true, update_cwd = true, diff --git a/home/.config/nvim/lua/plugins.lua b/home/.config/nvim/lua/plugins.lua index 4824bf8..7a14a9c 100644 --- a/home/.config/nvim/lua/plugins.lua +++ b/home/.config/nvim/lua/plugins.lua @@ -60,7 +60,8 @@ return packer.startup(function(use) } use { 'RRethy/vim-illuminate', - event = 'CursorHold' + event = 'CursorHold', + setup = editor.illuminate_conf } -- use { -- TODO: config (lua -> fennel) + learn clojure, fennel, guile scheme -- 'Olical/conjure', @@ -73,6 +74,11 @@ return packer.startup(function(use) event = 'BufRead', config = editor.treesitter_conf } + -- use { + -- 'lewis6991/spellsitter.nvim', + -- event = {'BufRead', 'BufNew', 'BufNewFile'}, + -- config = editor.spellsitter_conf + -- } use { 'lukas-reineke/indent-blankline.nvim', after = 'nvim-treesitter', @@ -84,14 +90,8 @@ return packer.startup(function(use) -- Putting config into `treesitter_conf` doesn't work for some reason config = editor.rainbow_conf } - use { - 'romgrk/nvim-treesitter-context', - after = 'nvim-treesitter' - } - use { - 'nvim-treesitter/nvim-treesitter-textobjects', - after = 'nvim-treesitter' - } + use {'romgrk/nvim-treesitter-context', after = 'nvim-treesitter'} + use {'nvim-treesitter/nvim-treesitter-textobjects', after = 'nvim-treesitter'} use { 'mizlan/iswap.nvim', cmd = {'ISwapWith', 'ISwap'}, @@ -103,7 +103,24 @@ return packer.startup(function(use) after = 'nvim-treesitter', config = editor.matchup_conf } - use {'machakann/vim-sandwich', keys = 's'} + use {'machakann/vim-sandwich', keys = 's'} -- TODO: check out surround.nvim + use { + 'folke/zen-mode.nvim', + cmd = 'ZenMode', + wants = 'twilight.nvim', + requires = {{ + 'folke/twilight.nvim', + cmd = {'Twilight', 'TwilightEnable'}, + config = editor.twilight_conf, + opt = true + }}, + config = editor.zenmode_conf + } + use { + 'max397574/better-escape.nvim', + event = 'InsertCharPre', + config = editor.betterescape_conf + } use { 'phaazon/hop.nvim', cmd = {'HopChar1', 'HopChar2', 'HopWord', 'HopPattern', 'HopLine'}, @@ -111,21 +128,28 @@ return packer.startup(function(use) } use { 'hrsh7th/vim-eft', - event = {'BufRead', 'BufNewFile'}, - setup = editor.eft_conf - } - use { - 'junegunn/vim-easy-align', - cmd = 'EasyAlign' + keys = { + {'n', 'f'}, {'x', 'f'}, {'n', 'F'}, {'x', 'F'}, + {'n', 't'}, {'x', 't'}, {'n', 'T'}, {'x', 'T'}, + {'n', ';'}, {'x', ';'} + }, + config = editor.eft_conf } + use {'junegunn/vim-easy-align', cmd = 'EasyAlign'} use { 'terrortylor/nvim-comment', keys = 'gc', config = editor.comment_conf } + use { + 'danymat/neogen', + keys = 'eg', + wants = 'nvim-treesitter', + config = editor.neogen_conf + } use { 'editorconfig/editorconfig-vim', - event = {'BufNewFile', 'BufRead'} + event = {'BufRead', 'BufNewFile'} } use { -- TODO: move to nvim-parinfer (lua) 'eraserhd/parinfer-rust', @@ -137,6 +161,12 @@ return packer.startup(function(use) event = 'BufEnter', config = editor.project_conf } + use { + 'ruifm/gitlinker.nvim', + wants = 'plenary.nvim', + keys = {'gy', 'gY'}, + config = editor.gitlinker_conf + } --------- -- LSP -- @@ -155,6 +185,11 @@ return packer.startup(function(use) wants = 'nvim-lspconfig', config = lsp.sqls_conf } + use { + 'kosayoda/nvim-lightbulb', + after = 'nvim-lspconfig', + config = lsp.lightbulb_conf + } use { 'folke/trouble.nvim', cmd = {'Trouble', 'TroubleToggle', 'TroubleRefresh'}, @@ -179,9 +214,13 @@ return packer.startup(function(use) } use { -- TODO: config, scripts to install/update dap servers 'rcarriga/nvim-dap-ui', - event = 'BufReadPre', + keys = 'd', wants = 'nvim-dap', - requires = {{'mfussenegger/nvim-dap', config = lsp.dap_conf, opt = true}}, + requires = {{ + 'mfussenegger/nvim-dap', + config = lsp.dap_conf, + opt = true + }}, config = lsp.dapui_conf } @@ -312,13 +351,6 @@ return packer.startup(function(use) run = 'npm install --prefix server', cmd = 'Bracey' } - use { - 'folke/zen-mode.nvim', - cmd = 'ZenMode', - wants = 'twilight.nvim', - requires = {{'folke/twilight.nvim', opt = true}}, - config = tools.zenmode_conf - } use { -- shouldn't be lazy-loaded (global bindings don't work) 'kristijanhusak/orgmode.nvim', ft = 'org', @@ -326,7 +358,7 @@ return packer.startup(function(use) } use { 'windwp/nvim-spectre', - event = {'BufRead', 'BufNewFile'}, + keys = 'p', wants = 'plenary.nvim', config = tools.spectre_conf } @@ -373,18 +405,36 @@ return packer.startup(function(use) } use { 'folke/persistence.nvim', - event = 'BufEnter', + event = 'BufReadPre', + keys = 's', config = tools.session_conf } use { -- Replace default filetype.vim 'nathom/filetype.nvim', + event = {'BufRead', 'BufNewFile'}, config = tools.filetype_conf } + use { + 'kazhala/close-buffers.nvim', + cmd = {'BDelete', 'BWipeout'}, + wants = 'bufferline.nvim', + config = tools.closebuf_conf + } + use { + 'sindrets/winshift.nvim', + cmd = 'WinShift', + config = tools.winshift_conf + } + use { + 'ten3roberts/window-picker.nvim', + cmd = {'WindowPick', 'WindowSwap', 'WindowSwapStay'}, + config = tools.winpicker_conf + } use {'dstein64/vim-startuptime', cmd = 'StartupTime'} -- Just for benchmarking -- TODO: dial.nvim, rust-tools.nvim, crates.nvim, go.nvim, clojure-vim/*, -- nvim-bqf, nvim-comment-frame, nvim-revJ.lua, nvim-remote-containers, - -- tex.nvim, telescope-lsp-handlers.nvim + -- tex.nvim, telescope-lsp-handlers.nvim, telescope-dap.nvim -- Install plugins if missing packer.install()