From d575feaa751cabc935268d1b0f6cbe7b5623c57e Mon Sep 17 00:00:00 2001 From: tea Date: Sun, 18 Aug 2024 14:17:27 +0200 Subject: [PATCH] nvim: start rewriting config - switch to lazy - rip out obsolete stuff - hopefully better organization --- .config/nvim/init.lua | 34 +- .config/nvim/lua/my/coding.lua | 104 ------ .config/nvim/lua/my/commands.lua | 9 - .config/nvim/lua/my/completion.lua | 109 ------- .config/nvim/lua/my/early.lua | 2 + .config/nvim/lua/my/filetypes.lua | 75 +---- .config/nvim/lua/my/functions.lua | 180 ----------- .config/nvim/lua/my/git.lua | 83 ----- .config/nvim/lua/my/keymaps.lua | 115 ------- .config/nvim/lua/my/lazy.lua | 26 ++ .config/nvim/lua/my/lsp.lua | 264 ---------------- .config/nvim/lua/my/net.lua | 46 --- .../nvim/lua/my/{settings.lua => options.lua} | 25 -- .config/nvim/lua/my/plugins.lua | 297 ------------------ .config/nvim/lua/my/plugins/completion.lua | 127 ++++++++ .config/nvim/lua/my/plugins/plugins.lua | 99 ++++++ .config/nvim/lua/my/tools.lua | 177 ----------- 17 files changed, 265 insertions(+), 1507 deletions(-) delete mode 100644 .config/nvim/lua/my/coding.lua delete mode 100644 .config/nvim/lua/my/commands.lua delete mode 100644 .config/nvim/lua/my/completion.lua create mode 100644 .config/nvim/lua/my/early.lua delete mode 100644 .config/nvim/lua/my/git.lua delete mode 100644 .config/nvim/lua/my/keymaps.lua create mode 100644 .config/nvim/lua/my/lazy.lua delete mode 100644 .config/nvim/lua/my/lsp.lua delete mode 100644 .config/nvim/lua/my/net.lua rename .config/nvim/lua/my/{settings.lua => options.lua} (72%) delete mode 100644 .config/nvim/lua/my/plugins.lua create mode 100644 .config/nvim/lua/my/plugins/completion.lua create mode 100644 .config/nvim/lua/my/plugins/plugins.lua delete mode 100644 .config/nvim/lua/my/tools.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index ae3081d..bf0a85d 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,8 +1,11 @@ -local version_required = 'nvim-0.7.0' +local version_required = 'nvim-0.8.0' -- 0.7.0 features we need: -- - autocommands in Lua -- - bind key mappings directly to Lua functions -- - desc in keymaps +-- 0.8.0 features we need: +-- - dunno, needed for lazy.nvim +-- - CursorHold fix if vim.fn.has(version_required) == 0 then print("💥 need " .. version_required .. ", config files will NOT be read!") return nil @@ -13,31 +16,8 @@ if vim.fn.isdirectory('/usr/share/vim/vimfiles') == 1 then vim.opt.runtimepath:append('/usr/share/vim/vimfiles') end -require('my/plugins') +require('my/early') require('my.functions') -require('my/settings') -require('my/keymaps') +require('my/lazy') +require('my/options') require('my/filetypes') -require('my/completion') -require('my/lsp') -require('my/tools') -require('my/coding') -require('my/git') -require('my/net') -require('my/commands') - --- reload config file after writing -vim.api.nvim_create_augroup('config_init', { clear = true }) -vim.api.nvim_create_autocmd({ 'BufWritePost' }, { - group = 'config_init', - pattern = { - vim.fn.stdpath('config') .. '/lua/my/*.lua', - vim.fn.stdpath('config') .. '/init.lua' - }, - callback = function() - -- exclude plugins.lua, because it is sourced in another autocmd - if not vim.api.nvim_buf_get_name(0):match('plugins.lua$') then - vim.cmd([[source ]]) - end - end -}) diff --git a/.config/nvim/lua/my/coding.lua b/.config/nvim/lua/my/coding.lua deleted file mode 100644 index c46a6e6..0000000 --- a/.config/nvim/lua/my/coding.lua +++ /dev/null @@ -1,104 +0,0 @@ -local map = require('my.functions').map - -require('Comment').setup({ - toggler = { - line = 'cc', - block = 'CC' - }, - opleader = { - line = 'c', - block = 'C' - }, - extra = { - above = 'cO', - below = 'co', - eol = 'cA', - }, - pre_hook = require('ts_context_commentstring.integrations.comment_nvim') - .create_pre_hook(), -}) - -require("nvim-autopairs").setup({}) - -require('luasnip.loaders.from_lua').load({ - paths = vim.fn.stdpath('config') .. '/snippets' -}) - - --- icons for diagnostics in the symbol column -local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } -for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) -end - -local dap = require('dap') - -if vim.fn.executable('lldb-vscode') > 0 then - dap.adapters.lldb = { - type = 'executable', - command = 'lldb-vscode', - name = 'lldb' - } - - dap.configurations.cpp = { - { - name = 'Launch', - type = 'lldb', - request = 'launch', - program = function() - return vim.fn.input('Path to executable: ', - vim.fn.getcwd() .. '/', 'file') - end, - cwd = '${workspaceFolder}', - stopOnEntry = false, - args = {}, - }, - { - name = "Attach to process", - type = 'lldb', - request = 'attach', - pid = require('dap.utils').pick_process, - args = {}, - } - } - dap.configurations.c = dap.configurations.cpp -end - -require('which-key').add({{ 'd', group = 'DAP' }}) -map('n', 'dc', dap.continue, 'Continue') -map('n', '', dap.step_over, 'DAP: step over') -map('n', '', dap.step_into, 'DAP: step into') -map('n', '', dap.step_out, 'DAP: step out') -map('n', 'db', dap.toggle_breakpoint, 'Toggle breakpoint') -map('n', 'dB', function() - dap.set_breakpoint(vim.fn.input('Breakpoint condition: ')) -end, 'Set breakpoint') -map('n', 'dr', dap.repl.open, 'Open REPL') -map('n', 'dl', dap.run_last, 'Run last') -map('n', 'dj', function() - require('dap.ext.vscode').load_launchjs( - vim.fn.input('Path to launch.json: ', - vim.fn.getcwd() .. '/launch.json', 'file')) -end, 'Load launch.json') - -require('dapui').setup({}) -map('n', 'du', require("dapui").toggle, 'Toggle UI') - -require('nvim-dap-virtual-text').setup({}) - -require('femaco').setup({}) -map('n', 'E', require('femaco.edit').edit_code_block, - 'Edit inline code block') - -require('projections').setup({ - workspaces = { '~/Projekte', '~/Dokumente' }, - patterns = require('my.functions').project_root_markers -}) - -require('neogen').setup({ - snippet_engine = 'luasnip', - languages = { - ['cpp.doxygen'] = require('neogen.configurations.cpp') - } -}) diff --git a/.config/nvim/lua/my/commands.lua b/.config/nvim/lua/my/commands.lua deleted file mode 100644 index 41112e6..0000000 --- a/.config/nvim/lua/my/commands.lua +++ /dev/null @@ -1,9 +0,0 @@ -vim.api.nvim_create_user_command('PkgCommit', function() - vim.cmd(string.format('vsplit | ' .. - 'terminal cd %s && pkgdev --verbose commit --signoff --edit', - vim.fn.expand('%:p:h'))) -end, {}) -vim.api.nvim_create_user_command('PkgManifest', function() - vim.cmd(string.format('vsplit | ' .. - 'terminal cd %s && pkgdev --verbose manifest', vim.fn.expand('%:p:h'))) -end, {}) diff --git a/.config/nvim/lua/my/completion.lua b/.config/nvim/lua/my/completion.lua deleted file mode 100644 index 9c00c40..0000000 --- a/.config/nvim/lua/my/completion.lua +++ /dev/null @@ -1,109 +0,0 @@ -local cmp = require('cmp') -local luasnip = require('luasnip') -local lspkind = require('lspkind') - -if cmp and luasnip then - cmp.setup({ - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - formatting = { - format = lspkind.cmp_format({ - mode = "symbol_text", - maxwidth = math.floor(vim.o.columns / 2), - ellipsis_char = '…', - menu = ({ - buffer = "[Buffer]", - nvim_lsp = "[LSP]", - luasnip = "[LuaSnip]", - nvim_lua = "[Lua]", - latex_symbols = "[Latex]", - }) - }), - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = false }), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expandable() then - luasnip.expand({}) - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end) - }), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'nvim_lua' }, - { name = 'dictionary' }, - { name = 'zsh' }, - { name = 'doxygen' }, - }, { - { name = 'buffer' }, - -- { name = 'spell' }, - }) - }) - - -- Use LSP symbols and buffer source for `/` - cmp.setup.cmdline('/', { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = 'nvim_lsp_document_symbol' } - }, { - { name = 'buffer' } - }) - }) - - -- Use cmdline & path source for ':' - cmp.setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = 'path' } - }, { - { name = 'cmdline' } - }) - }) - - require('cmp_dictionary').setup({ - dic = { - ['gitcommit'] = - vim.fn.stdpath('config') .. '/resources/git.dict', - -- doesn't work, filetype is probably set too late - ['NeogitCommitMessage'] = - vim.fn.stdpath('config') .. '/resources/git.dict', - } - }) - - -- add jump maps for select mode - local map = require('my.functions').map - map('s', '', function() luasnip.jump(1) end) - map('s', '', function() luasnip.jump(-1) end) - - require('cmp_zsh').setup({ - filetypes = { 'zsh', 'bash', 'sh' } - }) -end diff --git a/.config/nvim/lua/my/early.lua b/.config/nvim/lua/my/early.lua new file mode 100644 index 0000000..c3dd3d1 --- /dev/null +++ b/.config/nvim/lua/my/early.lua @@ -0,0 +1,2 @@ +vim.g.mapleader = ' ' -- +vim.g.maplocalleader = ' ' -- (2 spaces) diff --git a/.config/nvim/lua/my/filetypes.lua b/.config/nvim/lua/my/filetypes.lua index 4836e56..154b41f 100644 --- a/.config/nvim/lua/my/filetypes.lua +++ b/.config/nvim/lua/my/filetypes.lua @@ -1,91 +1,24 @@ -require 'nvim-treesitter.configs'.setup { - ensure_installed = 'all', - ignore_install = { 'comment', 'help' }, - sync_install = true, - highlight = { - enable = true, - additional_vim_regex_highlighting = { 'cpp', 'org' } - } -} - -require('ts_context_commentstring').setup({ - enable = true, - enable_autocmd = false -- handled by Comment (?) -}) -vim.g.skip_ts_context_commentstring_module = true; -- disable backwards compat - -require('orgmode').setup {} -require('which-key').add({{ 'o', group = 'Orgmode' }}) - -local ffgroup = vim.api.nvim_create_augroup('config_ff', { clear = true }) vim.api.nvim_create_autocmd({ 'FileType' }, { - group = ffgroup, - pattern = { 'org' }, - callback = function() - -- allow to hide stuff, like links - vim.opt_local.conceallevel = 2 - vim.opt_local.concealcursor = 'nc' - end -}) - -vim.api.nvim_create_autocmd({ 'FileType' }, { - group = ffgroup, + group = ftgroup, pattern = { 'gentoo-package-*' }, command = [[set tabstop=2 shiftwidth=2]] }) vim.api.nvim_create_autocmd({ 'BufEnter' }, { - group = ffgroup, + group = ftgroup, pattern = { '*.m3u8', '*.m3u' }, command = [[set textwidth=0]] }) vim.api.nvim_create_autocmd({ 'BufEnter' }, { - group = ffgroup, + group = ftgroup, pattern = { '*.log' }, command = [[AnsiEsc]] }) --- vim.api.nvim_create_autocmd({ 'FileType' }, { - group = ffgroup, - pattern = { 'cpp' }, - command = [[set ft=cpp.doxygen]] -}) - -vim.api.nvim_create_autocmd({ 'FileType' }, { - group = ffgroup, + group = ftgroup, pattern = { 'mail' }, command = [[set textwidth=72]] }) -require("todo-comments").setup({ - signs = false, - highlight = { - keyword = 'bg', - after = '' - } -}) - -vim.g.vimtex_compiler_latexmk_engines = { _ = '-xelatex' } - -require('colorizer').setup({ - filetypes = { '*' }, - user_default_options = { - mode = 'virtualtext', - rgb_fn = true, - hsl_fn = true, - RRGGBBAA = true, - } -}) - --- workarounds for missing syntax highlighting -require('paint').setup({ - highlights = { - { - filter = { filetype = 'cpp.doxygen' }, - pattern = '%s*%*!?%s*(@%w+)', - hl = 'Constant' - }, - } -}) diff --git a/.config/nvim/lua/my/functions.lua b/.config/nvim/lua/my/functions.lua index d552f2f..5044d6f 100644 --- a/.config/nvim/lua/my/functions.lua +++ b/.config/nvim/lua/my/functions.lua @@ -1,183 +1,3 @@ local M = {} -function M.map(mode, shortcut, command, description, buffer) - local opts = { noremap = true, silent = true } - opts.desc = description or nil - opts.buffer = buffer or nil - vim.keymap.set(mode, shortcut, command, opts) -end - -function M.remove_trailing_whitespace() - if vim.b.cleanup_file == false then - return - end - local curpos = vim.api.nvim_win_get_cursor(0) - vim.cmd([[keeppatterns %s/\s\+$//e]]) - vim.api.nvim_win_set_cursor(0, curpos) -end - -vim.api.nvim_create_augroup('config_functions', { clear = true }) -vim.api.nvim_create_autocmd({ 'BufWritePre' }, { - group = 'config_functions', - pattern = { - '*.lua', '*.cpp', '*.hpp', - '*.conf', '*.cfg', '*.ini', '*.adoc' - }, - callback = M.remove_trailing_whitespace -}) - --- Insert or update a modeline at the bottom of the buffer -function M.insert_modeline() - local comment_string = vim.o.commentstring - if comment_string == '' then - comment_string = '%s' - end - local space_maybe = '' - if string.match(comment_string, '%%s(.*)') ~= '' then - space_maybe = ' ' - end - - local fenc = vim.o.fileencoding - if fenc == '' then - fenc = 'utf-8' - end - - local modeline_elements = { - ' vim: set', - ' ts=' .. vim.o.tabstop, - ' sw=' .. vim.o.shiftwidth, - (vim.o.expandtab and ' et' or ' noet'), - ' tw=' .. vim.o.textwidth, - ' ft=' .. vim.o.filetype, - (vim.o.spell and ' spell' .. ' spl=' .. vim.o.spelllang or ''), - (vim.o.wrap and ' wrap' or ' nowrap'), - ':', - space_maybe - } - local modeline = comment_string:gsub('%%s', table.concat(modeline_elements)) - modeline = modeline:gsub(' ', ' ') - - local buffer = vim.api.nvim_win_get_buf(0) - local current = vim.api.nvim_buf_get_lines(buffer, -2, -1, true)[1] - if current == modeline then - print('modeline already exists') - elseif string.match(current, 'vim:') then - vim.api.nvim_buf_set_lines(buffer, -2, -1, true, { modeline }) - print('modeline updated') - else - vim.api.nvim_buf_set_lines(buffer, -1, -1, true, { '', modeline }) - print('modeline inserted') - end -end - -vim.api.nvim_create_user_command('ModelineInsert', M.insert_modeline, {}) - --- Files that could indicate the project's root directory -M.project_root_markers = { - '.git', '.hg', '.svn', '.bzr', '_darcs', - '.projectile', '.luarc.json', '.editorconfig', 'Cargo.toml' -} - -function M.get_project_root() - local lsp_root = vim.lsp.buf.list_workspace_folders()[1] - if lsp_root ~= nil then - return lsp_root - end - - local path = vim.api.nvim_buf_get_name(0) - local sep = '/' - - repeat - path = path:gsub(string.format('%s[^%s]*$', sep, sep), '') - for _, marker in ipairs(M.project_root_markers) do - if path ~= os.getenv('HOME') and io.open(path .. sep .. marker) then - return path - end - end - until path == '' - - return nil -end - -function M.shell_capture(command) - local handle = io.popen(command) - if not handle then return nil end - local result = handle:read() or nil - handle:close() - return result -end - --- return colours from highlight groups in web notation (#rrggbb) -function M.get_hl_hex(hl_group) - local hl = vim.api.nvim_get_hl_by_name(hl_group, true) - local hl_hex = {} - if hl.foreground then - hl_hex.foreground = string.format('#%.6x', hl.foreground) - end - if hl.background then - hl_hex.background = string.format('#%.6x', hl.background) - end - return hl_hex -end - --- return true if 'Symbols Nerd Font' is known to fontconfig -function M.nerdfont_installed() - if vim.fn.executable('fc-list') == 1 and - os.execute([[fc-list -q 'Symbols Nerd Font']]) == 0 then - return true - end - return false -end - --- return LSP status -function M.lsp_status() - local status = '' - for _, msg in ipairs(require('lsp-status/messaging').messages()) do - if msg.progress then - status = '⏳' - elseif msg.status then - -- clangd parsing includes and whatnot - if msg.content ~= 'idle' then - status = '⌛' - end - end - end - - return status -end - -function M.lsp_sig_status() - if not vim.lsp.buf.server_ready() then - return "" - end - - local width = vim.o.columns / 3 - if width < 40 then - return "" - end - if width > 50 then - width = width * 1.5 - end - - local label = require('lsp_signature').status_line().label - if label:len() > width then - label = label:sub(1, math.floor(width)) .. '…' - end - - return label -end - -function M.not_firenvim() - return vim.g.started_by_firenvim == nil -end - --- returns the name of the current function in brackets or an empty string -function M.current_function() - local curfun = vim.b.lsp_current_function - if curfun and curfun ~= '' then - return '(' .. curfun .. ')' - end - return '' -end - return M diff --git a/.config/nvim/lua/my/git.lua b/.config/nvim/lua/my/git.lua deleted file mode 100644 index 1282f4b..0000000 --- a/.config/nvim/lua/my/git.lua +++ /dev/null @@ -1,83 +0,0 @@ -local map = require('my.functions').map - -local neogit = require('neogit') -neogit.setup { - disable_commit_confirmation = true, - kind = 'tab', - integrations = { - diffview = true - }, - disable_insert_on_commit = false -} -map('n', 'gg', neogit.open, 'Open Neogit') - -local gitgroup = vim.api.nvim_create_augroup('config_git', { clear = true }) --- enable spell checking -vim.api.nvim_create_autocmd({ 'FileType' }, { - group = gitgroup, - pattern = { 'gitcommit' }, - command = [[setlocal spell]] -}) - --- start git commits in insert mode -vim.api.nvim_create_autocmd({ 'FileType' }, { - group = gitgroup, - pattern = { 'gitcommit', 'gitrebase' }, - command = [[startinsert | 1]] -}) - --- split Neogit commit messages vertically if possible -vim.api.nvim_create_autocmd({ 'FileType' }, { - group = gitgroup, - pattern = { 'NeogitCommitMessage' }, - callback = require('autosplit') -}) - --- fugitive and Neogit buffers -vim.api.nvim_create_autocmd({ 'FileType' }, { - group = gitgroup, - pattern = { 'git', 'Neogit*' }, - callback = function() - vim.o.list = false - -- this messes up the path of the current file for some reason - --vim.cmd.lcd(require('my.functions').get_project_root()) - end -}) - -require('gitsigns').setup({ - on_attach = function(bufnr) - local gs = package.loaded.gitsigns - - map('n', 'gb', function() gs.blame_line({ full = true }) end, - 'Show blame for current line', bufnr) - end -}) - -require('gitlinker').setup({ - callbacks = { - ['schlomp.space'] = require('gitlinker.hosts').get_gitea_type_url, - ['git.gentoo.org'] = function(url_data) - url_data.host = 'gitweb.gentoo.org' - return require('gitlinker.hosts').get_cgit_type_url(url_data) - end, - ['anongit.gentoo.org'] = function(url_data) - url_data.host = 'gitweb.gentoo.org' - url_data.repo = url_data.repo:gsub('^git/', '', 1) - return require('gitlinker.hosts').get_cgit_type_url(url_data) - end, - } -}) - -require('which-key').add({{ 'g', group = 'Git' }}) -require('which-key').add({{ 'gc', group = 'commit' }}) -map('n', 'gcc', ':Git commit', 'commit') -map('n', 'gca', ':Git commit --amend', 'amend') -map('n', 'gP', ':Git push', 'push') -require('which-key').add({{ 'gp', group = 'pull' }}) -map('n', 'gpo', ':Git pull origin', 'origin') -map('n', 'gpu', ':Git pull upstream', 'upstream') -require('which-key').add({{ 'ga', group = 'add' }}) -map('n', 'gau', ':Git add --update --patch', '--update --patch') -map('n', 'ga%', ':Git add %', 'This file') -map('n', 'gl', ':Git log --decorate', 'log') -map('n', 'gs', ':Git status', 'status') diff --git a/.config/nvim/lua/my/keymaps.lua b/.config/nvim/lua/my/keymaps.lua deleted file mode 100644 index 704e5bd..0000000 --- a/.config/nvim/lua/my/keymaps.lua +++ /dev/null @@ -1,115 +0,0 @@ ----@format disable -local map = require('my.functions').map - -vim.g.mapleader = ' ' -- -vim.g.maplocalleader = ' ' -- (2 spaces) - -local format = string.format - --- buffers -map('n', 'b', ':buffers:buffer', 'Show open buffers') -for key, cmd in pairs({ Left = 'bprevious', Right = 'bnext' }) do - map('n', format('', key), format(':%s', cmd)) - map('i', format('', key), format(':%s', cmd)) -end ----- move buffer without moving cursor -map({ 'n', 'v' }, '', '') -map({ 'n', 'v' }, '', '') - --- windows -for key, letter in pairs({ Left = 'h', Down = 'j', Up = 'k', Right = 'l' }) do - map('n', format('', key), format(':wincmd %s', letter)) - map('i', format('', key), format(':wincmd %s', letter)) -end - --- remove word -map('n', '', 'db') -map('n', '', 'db') -vim.cmd([[map! ]]) -- map('c', … doesn't work -vim.cmd([[map!  ]]) -map('n', '', 'db') -- terminal sends M-BS for C-BS -vim.cmd([[map! ]]) -map('n', '', 'dw') -map('i', '', 'dw') - --- remove whitespace around cursor -map({ 'n', 'i' }, '', - function() - local row, pos_cursor = unpack(vim.api.nvim_win_get_cursor(0)) - pos_cursor = pos_cursor + 1 -- api / lua is off by one - local line = vim.api.nvim_get_current_line() - local pos_start, pos_end = 0, 0 - - while pos_start ~= nil do - if pos_start <= pos_cursor and pos_end >= pos_cursor then - local before = line:sub(1, pos_start - 1) - local after = line:sub(pos_end + 1) - local space = '' - if before:len() > 0 and after:len() > 0 then - space = ' ' - end - vim.api.nvim_set_current_line(before .. space .. after) - vim.api.nvim_win_set_cursor(0, { row, pos_start - 1 }) - break - end - pos_start, pos_end = line:find('%s+', pos_end + 1) - end - end -) - --- system clipboard (clipboard = , selection = middle mouse button) -map({ 'v', 'n' }, 'y', '"+y', 'Yank to system clipboard') -map({ 'v', 'n' }, '', '"*y', 'Yank to system selection') - -map('n', 'p', '"+p', 'Paste from system clipboard') -map('n', 'P', '"+P', 'Paste from system clipboard') -map('n', '', '"*p', 'Paste from system selection') -map('n', '', '"*P', 'Paste from system selection') - - --- toggle between beginning of line and beginning of text -map({ 'n', 'i', 'v' }, '', - function() - local row, col = unpack(vim.api.nvim_win_get_cursor(0)) - if col == 0 then - local col_new = vim.api.nvim_get_current_line():match('^%s*'):len() - vim.api.nvim_win_set_cursor(0, { row, col_new }) - else - vim.api.nvim_win_set_cursor(0, { row, 0 }) - end - end -) - -map({ 'n', 'v' }, '', '==') -- re-indent line - --- select text with shift + arrow -for _, key in ipairs({ 'Left', 'Up', 'Down', 'Right' }) do - map({ 'n', 'i' }, format('', key), format('v<%s>', key)) - map({ 'v' }, format('', key), format('<%s>', key)) -end - -map('n', '', '', 'Follow symbol') -map('n', '', '', 'Go back to previous pos') -map('v', 'f', 'gq', 'Reformat text') -map('n', '', ':bdelete', 'Close buffer') - --- use ui.select for spelling suggestions so dressing can make it look nice -local function spellsugg_select() - local word = vim.fn.expand('') - local suggestions = vim.fn.spellsuggest(word) - vim.ui.select(suggestions, {}, vim.schedule_wrap(function(selected) - if selected then - vim.api.nvim_feedkeys('ciw' .. selected, 'n', true) - vim.api.nvim_feedkeys( - vim.api.nvim_replace_termcodes('', true, true, true), - 'n', true) - end - end)) -end - -map('n', 'z=', spellsugg_select) - --- use easier keys for spell -map('n', '', '[s', 'Previous misspelled word') -- -map('n', '', ']s', 'Next misspelled word') -- -map('n', '', spellsugg_select, 'Spelling suggestions') -- diff --git a/.config/nvim/lua/my/lazy.lua b/.config/nvim/lua/my/lazy.lua new file mode 100644 index 0000000..b435587 --- /dev/null +++ b/.config/nvim/lua/my/lazy.lua @@ -0,0 +1,26 @@ +-- Bootstrap lazy.nvim +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, + { out, "WarningMsg" }, + { "\nPress any key to exit..." }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end +end +vim.opt.rtp:prepend(lazypath) + +-- Setup lazy.nvim +require("lazy").setup({ + spec = { + -- import your plugins + { import = "my/plugins" }, + }, + -- automatically check for plugin updates + checker = { enabled = true }, +}) diff --git a/.config/nvim/lua/my/lsp.lua b/.config/nvim/lua/my/lsp.lua deleted file mode 100644 index c16a0ad..0000000 --- a/.config/nvim/lua/my/lsp.lua +++ /dev/null @@ -1,264 +0,0 @@ -local map = require('my.functions').map - --- only do this after the language server attaches to the current buffer -local on_attach = function(client, bufnr) - ---@format disable - map('n', '', vim.diagnostic.goto_prev, 'Prev diagnostic', bufnr) - map('n', '', vim.diagnostic.goto_next, 'Next diagnostic', bufnr) - map('n', 'gD', vim.lsp.buf.declaration, 'Go to declaration', bufnr) - map('n', 'gd', vim.lsp.buf.definition, 'Go to definition', bufnr) - map('n', '', vim.lsp.buf.definition, 'Go to definition', bufnr) - map('n', 'gi', vim.lsp.buf.implementation, 'Go to implementation', - bufnr) - map('n', 'gr', vim.lsp.buf.references, 'Show references', bufnr) - map('n', 'K', vim.lsp.buf.hover, 'Hover', bufnr) - map('i', '', vim.lsp.buf.hover, 'Hover', bufnr) - require('which-key').add({{ 'l', group = 'LSP' }}) - require('which-key').add({{ 'lw', group = 'workspace' }}) - map('n', 'lwa', vim.lsp.buf.add_workspace_folder, - 'Add workspace folder', bufnr) - map('n', 'lwr', vim.lsp.buf.remove_workspace_folder, - 'Remove workspace folder', bufnr) - map('n', 'lwl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, 'List workspace folders', bufnr) - map('n', 'lr', vim.lsp.buf.rename, 'Rename symbol', bufnr) - map('n', 'la', vim.lsp.buf.code_action, 'Code action', bufnr) - if vim.fn.has('nvim-0.8.0') == 1 then - map('n', 'lf', vim.lsp.buf.format, 'Format buffer', bufnr) - else - map('n', 'lf', vim.lsp.buf.formatting, 'Format buffer', bufnr) - end - - - -- highlight symbol under cursor - local has_highlight = false - if vim.fn.has('nvim-0.8.0') == 1 then - if client.server_capabilities.documentHighlightProvider then - has_highlight = true - end - else - if client.resolved_capabilities.document_highlight then - has_highlight = true - end - end - - if has_highlight then - vim.api.nvim_create_augroup('config_lsp', { clear = false }) - vim.api.nvim_clear_autocmds({ - buffer = bufnr, - group = 'config_lsp', - }) - vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { - group = 'config_lsp', - buffer = bufnr, - callback = vim.lsp.buf.document_highlight, - }) - vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { - group = 'config_lsp', - buffer = bufnr, - callback = vim.lsp.buf.clear_references, - }) - - -- Don't autoformat code like text - vim.bo.formatoptions = vim.o.formatoptions:gsub('t', '') - -- Let LSP autoformat on save - require('lsp-format').on_attach(client) - - -- virtual text hint for parameters - require ('lsp_signature').on_attach({ - bind = true, - handler_opts = { - border = 'rounded' - }, - floating_window = false - }, bufnr) - end - - -- -- show help on hover () - -- if client.server_capabilities.hoverProvider then - -- vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { - -- group = 'config_lsp', - -- buffer = bufnr, - -- callback = vim.lsp.buf.hover - -- }) - -- end - - require('lsp-status').on_attach(client) -end - --- add completion capabilities -local capabilities = require('cmp_nvim_lsp').default_capabilities() - --- add progress capabilities -local lsp_status = require('lsp-status') -lsp_status.register_progress() -capabilities = vim.tbl_extend('keep', capabilities, lsp_status.capabilities) - --- opens lsp.util.open_floating_preview() -> nvim_open_win() -vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { - border = 'rounded', - width = 60, - focusable = false, - -- next 2 lines do nothing, overwritten by open_floating_preview() - relative = 'win', - anchor = 'NE', -}) - --- setup servers -local lspconfig = require('lspconfig') - --- set up language servers that don't need any special configuration -local simple_ls = { - ['vscode-html-language-server'] = 'html', - ['vscode-css-language-server'] = 'cssls', - ['vscode-json-language-server'] = 'jsonls', - ['gopls'] = 'gopls', - ['cmake-language-server'] = 'cmake', - ['yaml-language-server'] = 'yamlls', - ['docker-langserver'] = 'dockerls', -} -for exe, ls in pairs(simple_ls) do - if vim.fn.executable(exe) > 0 then - lspconfig[ls].setup({ - on_attach = on_attach, - capabilities = capabilities - }) - end -end - -if vim.fn.executable('clangd') > 0 then - require("clangd_extensions").setup({ - server = { - cmd = { - 'clangd', - '--compile-commands-dir=build', - '--clang-tidy', -- needs >=clangd-9 - '--ranking-model=decision_forest' -- needs >=clangd-12 - }, - init_options = { clangdFileStatus = true }, - on_attach = on_attach, - capabilities = capabilities, - handlers = lsp_status.extensions.clangd.setup(), - }, - extensions = { - inlay_hints = { - show_parameter_hints = false - } - } - }) -end - --- TODO: re-check config recommendation, looks like some things changed --- -if vim.fn.executable('lua-language-server') > 0 then - lspconfig.lua_ls.setup({ - settings = { - Lua = { - runtime = { - version = 'LuaJIT', - }, - diagnostics = { - globals = { 'vim' }, - }, - workspace = { - library = vim.api.nvim_get_runtime_file('', true), - }, - telemetry = { - enable = false, - }, - completion = { - -- complete full function signature - callSnippet = 'Replace', - }, - }, - }, - on_attach = on_attach, - capabilities = capabilities - }) -end - -if vim.fn.executable('pylsp') > 0 then - lspconfig.pylsp.setup({ - settings = { - pylsp = { - } - }, - on_attach = on_attach, - capabilities = capabilities - }) -end - -if vim.fn.executable('lemminx') > 0 then - lspconfig.lemminx.setup({ - filetypes = { - 'xml', 'xsd', 'xsl', 'xslt', 'svg', 'gentoo-metadata' - }, - settings = { - xml = { - server = { -- path for cached XML Schemas - workDir = vim.fn.stdpath('cache') .. '/lemminx' - } - } - }, - on_attach = on_attach, - capabilities = capabilities - }) -end - -if vim.fn.glob('/usr/lib64/perl5/vendor_perl/5.*/Perl/LanguageServer.pm') ~= '' -then - lspconfig.perlls.setup({ - on_attach = on_attach, - capabilities = capabilities - }) -end - -if vim.fn.executable('qml-lsp') > 0 then - lspconfig.qml_lsp.setup({ - filetypes = { 'qml', 'qmljs' }, - on_attach = on_attach, - capabilities = capabilities - }) -end - -if vim.fn.executable('bash-language-server') > 0 then - lspconfig.bashls.setup({ - filetypes = { 'sh', 'bash', 'ebuild', 'gentoo-init-d.sh' }, - on_attach = on_attach, - capabilities = capabilities - }) -end - -if vim.fn.executable('typescript-language-server') > 0 then - lspconfig.tsserver.setup({ - cmd = { - 'typescript-language-server', '--stdio', - '--tsserver-path', 'tsserver' - }, - on_attach = on_attach, - capabilities = capabilities - }) -end - -require('lsp-format').setup({ - sync = true -- seems to be needed to not interfere with Neogit -}) - -local rt = require("rust-tools") -rt.setup({ - server = { - on_attach = on_attach, - capabilities = capabilities, - settings = { - ["rust-analyzer"] = { - -- checkOnSave = { - -- command = "clippy", - -- }, - -- diagnostics = { - -- enable = true, - -- }, - } - } - }, -}) diff --git a/.config/nvim/lua/my/net.lua b/.config/nvim/lua/my/net.lua deleted file mode 100644 index 0bd2643..0000000 --- a/.config/nvim/lua/my/net.lua +++ /dev/null @@ -1,46 +0,0 @@ -if not vim.g.started_by_firenvim then - local sockdir = (vim.env['XDG_RUNTIME_DIR'] - or vim.env['XDG_STATE_HOME'] or vim.env['HOME'] .. '/.local/state') - vim.fn.mkdir(sockdir, 'p') - if vim.fn.filereadable(sockdir .. '/nvim.sock') == 0 then - vim.fn.serverstart(sockdir .. '/nvim.sock'); - end -else - vim.g.firenvim_config = { - localSettings = { - [".*"] = { - priority = 0, - takeover = 'never', - } - } - } - - vim.o.wrap = true - vim.o.guifont = 'Source_Code_Pro:h10' - vim.o.textwidth = 0 - - local fv_fileprefix = vim.env['XDG_RUNTIME_DIR'] .. '/firenvim/' - vim.api.nvim_create_augroup('firenvim', { clear = true }) - vim.api.nvim_create_autocmd({ 'BufEnter' }, { - group = 'firenvim', - pattern = { - fv_fileprefix .. 'schlomp.space_*', - fv_fileprefix .. 'codeberg.org_*', - fv_fileprefix .. 'gitlab.com_*', - fv_fileprefix .. 'github.com_*', - fv_fileprefix .. 'very.tastytea.de_*', - fv_fileprefix .. 'bookwyrm.social_*', - fv_fileprefix .. 'openlibrary.org_*', - fv_fileprefix .. 'bugs.gentoo.org_*', - }, - command = [[set filetype=markdown | set tw=0]] - }) - vim.api.nvim_create_autocmd({ 'BufEnter' }, { - group = 'firenvim', - pattern = { - fv_fileprefix .. 'wiki.gentoo.org_*', - fv_fileprefix .. '*.wikipedia.org_*', - }, - command = [[set filetype=mediawiki | set tw=0]] - }) -end diff --git a/.config/nvim/lua/my/settings.lua b/.config/nvim/lua/my/options.lua similarity index 72% rename from .config/nvim/lua/my/settings.lua rename to .config/nvim/lua/my/options.lua index 25d8422..432d40c 100644 --- a/.config/nvim/lua/my/settings.lua +++ b/.config/nvim/lua/my/options.lua @@ -32,28 +32,3 @@ local options = { for k, v in pairs(options) do vim.o[k] = v end - --- fire CursorHold autocommand event (FixCursorHold.nvim) -vim.g.cursorhold_updatetime = 500 - -vim.api.nvim_create_user_command('Ht', 'tab help ', { - nargs = 1, complete = 'help' -}) - --- split these vertically if there is enough space -vim.g.autosplit_bt = { 'help', 'terminal' } -vim.g.autosplit_ft = { - 'man', 'fugitive', 'gitcommit', 'gitrebase', 'git' -} - --- theme -vim.o.termguicolors = true -- 24 bit colours -vim.cmd('colorscheme amora') ----- make comments a bit lighter -vim.api.nvim_set_hl(0, 'AmoraComment', { fg = '#7C4180', ctermfg = 61 }) -vim.api.nvim_set_hl(0, 'AmoraCommentBold', - { fg = '#7C4180', ctermfg = 61, bold = true }) - --- if require('my.functions').nerdfont_installed() then --- require('nvim-web-devicons').setup({}) --- end diff --git a/.config/nvim/lua/my/plugins.lua b/.config/nvim/lua/my/plugins.lua deleted file mode 100644 index a8bdcda..0000000 --- a/.config/nvim/lua/my/plugins.lua +++ /dev/null @@ -1,297 +0,0 @@ -local install_path = vim.fn.stdpath('data') .. - '/site/pack/packer/start/packer.nvim' -local packer_bootstrap -if vim.fn.empty(vim.fn.glob(install_path)) > 0 then - packer_bootstrap = vim.fn.system({ - 'git', - 'clone', - 'https://github.com/wbthomason/packer.nvim', - install_path - }) - vim.cmd [[packadd packer.nvim]] -end - -require('packer').startup({ - function(use) - use { 'https://github.com/wbthomason/packer.nvim' } - - -- settings - use { 'https://github.com/owozsh/amora' } - use { 'https://github.com/editorconfig/editorconfig-vim' } - use { 'https://github.com/antoinemadec/FixCursorHold.nvim' } - use { 'https://github.com/ii14/autosplit.nvim' } - - -- filetypes - use { - 'https://github.com/nvim-treesitter/nvim-treesitter', - tag = '*', - run = [[:TSUpdateSync]] - } - use { - 'https://github.com/nvim-orgmode/orgmode', - tag = '*' - } - use { - 'https://github.com/JoosepAlviste/nvim-ts-context-commentstring', - requires = 'https://github.com/nvim-treesitter/nvim-treesitter' - } - if vim.version().api_level >= 10 then -- >=0.8.0 - use { - 'https://github.com/folke/todo-comments.nvim', - requires = { 'https://github.com/nvim-lua/plenary.nvim' } - } - else - use { - 'https://github.com/folke/todo-comments.nvim', - requires = { 'https://github.com/nvim-lua/plenary.nvim' }, - branch = 'neovim-pre-0.8.0' - } - end - use { 'https://github.com/powerman/vim-plugin-AnsiEsc' } - use { - 'https://github.com/lervag/vimtex', - tag = '*', - cond = vim.fn.executable('xelatex') == 1 - } - use { 'https://github.com/NvChad/nvim-colorizer.lua' } - use { 'https://github.com/chikamichi/mediawiki.vim' } - if vim.version().api_level >= 10 then -- >=0.8.0 - use { 'https://github.com/folke/paint.nvim' } - end - use { - 'https://github.com/gennaro-tedesco/nvim-jqx', - tag = '*', - ft = { "json", "yaml" } - } - use { 'https://github.com/isobit/vim-caddyfile' } - - -- completion - use { - 'https://github.com/hrsh7th/nvim-cmp', - requires = { - 'https://github.com/hrsh7th/cmp-nvim-lsp', - 'https://github.com/hrsh7th/cmp-buffer', - 'https://github.com/hrsh7th/cmp-path', - 'https://github.com/hrsh7th/cmp-cmdline', - { - 'https://github.com/saadparwaiz1/cmp_luasnip', - requires = 'https://github.com/L3MON4D3/LuaSnip' - }, - 'https://github.com/hrsh7th/cmp-nvim-lua', - 'https://github.com/uga-rosa/cmp-dictionary', - 'https://github.com/f3fora/cmp-spell', - 'https://github.com/hrsh7th/cmp-nvim-lsp-document-symbol', - 'https://github.com/tamago324/cmp-zsh', - { - 'https://github.com/paopaol/cmp-doxygen', - requires = { - 'https://github.com/nvim-treesitter/nvim-treesitter', - 'https://github.com/nvim-treesitter/nvim-treesitter-textobjects' - } - }, - 'https://github.com/onsails/lspkind.nvim' - } - } - - -- lsp - use { - 'https://github.com/neovim/nvim-lspconfig', - tag = '*', - requires = 'https://github.com/hrsh7th/cmp-nvim-lsp' - } - use { - 'https://github.com/lukas-reineke/lsp-format.nvim', - tag = '*' - } - use { 'https://github.com/ray-x/lsp_signature.nvim' } - use { 'https://github.com/p00f/clangd_extensions.nvim' } - use { - 'https://github.com/simrat39/rust-tools.nvim', - requires = { 'neovim/nvim-lspconfig' } - } - - -- tools - local nerdfont_installed = require('my.functions').nerdfont_installed() - use { - 'https://github.com/kyazdani42/nvim-web-devicons', - cond = nerdfont_installed - } - - use { 'https://github.com/folke/which-key.nvim' } - use { - 'https://github.com/nvim-telescope/telescope.nvim', - tag = '*', - requires = { - 'https://github.com/nvim-lua/plenary.nvim', - 'https://github.com/nvim-treesitter/nvim-treesitter', - { - 'https://github.com/kyazdani42/nvim-web-devicons', - cond = nerdfont_installed - } - }, - } - use { - 'https://github.com/nvim-telescope/telescope-fzf-native.nvim', - run = [[make]] - } - use { - 'https://github.com/kyazdani42/nvim-tree.lua', - tag = '*', - requires = { - { - 'https://github.com/kyazdani42/nvim-web-devicons', - cond = nerdfont_installed - } - } - } - use { - 'https://github.com/nvim-lualine/lualine.nvim', - requires = { - { - 'https://github.com/kyazdani42/nvim-web-devicons', - cond = nerdfont_installed - }, - 'https://github.com/nvim-lua/lsp-status.nvim' - } - } - use { 'https://codeberg.org/tastytea/bug-reference.nvim' } - use { - 'https://github.com/phaazon/mind.nvim', - tag = '*' - } - use { - 'https://github.com/dhruvasagar/vim-table-mode', - tag = '*' - } - use { 'https://github.com/stevearc/dressing.nvim' } - use { - 'https://github.com/rcarriga/nvim-notify', - tag = '*' - } - use { - 'https://github.com/gaoDean/autolist.nvim', - tag = '*' - } - use { - 'https://github.com/ThePrimeagen/harpoon', - requires = { - 'https://github.com/nvim-lua/plenary.nvim' - } - } - use { - 'https://github.com/lambdalisue/suda.vim', - tag = '*' - } - use { - 'https://github.com/LittleMorph/copyright-updater.nvim' - } - - -- coding - use { - 'https://github.com/numToStr/Comment.nvim', - tag = '*' - } - use { 'https://github.com/windwp/nvim-autopairs' } - use { 'https://github.com/L3MON4D3/LuaSnip' } - use { - 'https://github.com/GnikDroy/projections.nvim', - branch = 'pre_release' } - use { - 'https://github.com/mfussenegger/nvim-dap', - tag = '*' - } - use { - 'https://github.com/rcarriga/nvim-dap-ui', - tag = '*', - requires = { - 'https://github.com/mfussenegger/nvim-dap', - 'https://github.com/nvim-neotest/nvim-nio' - } - } - use { - 'https://github.com/nvim-telescope/telescope-dap.nvim', - requires = 'https://github.com/mfussenegger/nvim-dap' - } - use { - 'https://github.com/theHamsta/nvim-dap-virtual-text', - requires = 'https://github.com/mfussenegger/nvim-dap' - } - use { - 'https://github.com/krady21/compiler-explorer.nvim', - requires = { 'https://github.com/nvim-lua/plenary.nvim' } - } - use { - 'https://github.com/AckslD/nvim-FeMaco.lua' - } - use { - 'https://github.com/danymat/neogen', - requires = 'https://github.com/nvim-treesitter/nvim-treesitter', - tag = '*' - } - - -- git - use { - 'https://github.com/TimUntersberger/neogit', - requires = { - 'https://github.com/nvim-lua/plenary.nvim', - 'https://github.com/folke/which-key.nvim', - 'https://github.com/sindrets/diffview.nvim' - } - } - use { - 'https://github.com/tpope/vim-fugitive', - tag = '*' - } - use { - 'https://github.com/lewis6991/gitsigns.nvim', - tag = '*' - } - -- use { - -- 'https://github.com/ruifm/gitlinker.nvim', - -- requires = { 'https://github.com/nvim-lua/plenary.nvim' } - -- } - use { -- - 'https://github.com/tastytea/gitlinker.nvim', - requires = { 'https://github.com/nvim-lua/plenary.nvim' }, - branch = 'fix-cgit' - } - - -- net - use { -- embed nvim in browsers - 'https://github.com/glacambre/firenvim', - tag = '*', - run = [[call firenvim#install(0)]] - } - - -- ensure plugins are installed and compiled - if packer_bootstrap then - require('packer').sync() - end - end, - config = { - git = { - depth = 999999 - }, - display = { - open_fn = require('packer.util').float - } - } -}) - --- source file, install and compile plugins when this file is written -vim.api.nvim_create_augroup('config_plugins', { clear = true }) -vim.api.nvim_create_autocmd({ 'BufWritePost' }, { - group = 'config_plugins', - pattern = { vim.fn.stdpath('config') .. '/lua/my/plugins.lua' }, - command = [[source | PackerInstall]] -}) -vim.api.nvim_create_autocmd({ 'User' }, { - group = 'config_plugins', - pattern = 'PackerComplete', - command = [[PackerCompile]] -}) -vim.api.nvim_create_autocmd({ 'User' }, { - group = 'config_plugins', - pattern = 'PackerCompileDone', - command = [[echo 'plugins compiled']] -}) diff --git a/.config/nvim/lua/my/plugins/completion.lua b/.config/nvim/lua/my/plugins/completion.lua new file mode 100644 index 0000000..b139206 --- /dev/null +++ b/.config/nvim/lua/my/plugins/completion.lua @@ -0,0 +1,127 @@ +return { + { 'https://github.com/hrsh7th/nvim-cmp', + dependencies = { + 'https://github.com/hrsh7th/cmp-nvim-lsp', + 'https://github.com/hrsh7th/cmp-buffer', + 'https://github.com/hrsh7th/cmp-path', + 'https://github.com/hrsh7th/cmp-cmdline', + { 'https://github.com/saadparwaiz1/cmp_luasnip', + dependencies = 'https://github.com/L3MON4D3/LuaSnip', + }, + 'https://github.com/hrsh7th/cmp-nvim-lua', + { 'https://github.com/uga-rosa/cmp-dictionary', + opts = { + dic = { + ['gitcommit'] = + vim.fn.stdpath('config') .. '/resources/git.dict', + -- doesn't work, filetype is probably set too late + ['NeogitCommitMessage'] = + vim.fn.stdpath('config') .. '/resources/git.dict', + }, + }, + }, + 'https://github.com/f3fora/cmp-spell', + { 'https://github.com/tamago324/cmp-zsh', + opts = { + filetypes = { 'zsh', 'bash', 'sh' }, + } + }, + { 'https://github.com/paopaol/cmp-doxygen', + dependencies = { + 'nvim-treesitter', + 'https://github.com/nvim-treesitter/nvim-treesitter-textobjects', + }, + }, + 'https://github.com/onsails/lspkind.nvim', + }, + config = function() + local cmp = require('cmp') + local luasnip = require('luasnip') + local lspkind = require('lspkind') + cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + formatting = { + format = lspkind.cmp_format({ + mode = "symbol_text", + maxwidth = math.floor(vim.o.columns / 2), + ellipsis_char = '…', + menu = ({ + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + luasnip = "[LuaSnip]", + nvim_lua = "[Lua]", + latex_symbols = "[Latex]", + }) + }), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = false }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand({}) + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end) + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'nvim_lua' }, + { name = 'dictionary' }, + { name = 'zsh' }, + { name = 'doxygen' }, + }, { + { name = 'buffer' }, + -- { name = 'spell' }, + }) + }) + + -- Use LSP symbols and buffer source for `/` + cmp.setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'nvim_lsp_document_symbol' } + }, { + { name = 'buffer' } + }) + }) + + -- Use cmdline & path source for ':' + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) + end + }, +} diff --git a/.config/nvim/lua/my/plugins/plugins.lua b/.config/nvim/lua/my/plugins/plugins.lua new file mode 100644 index 0000000..93a3de1 --- /dev/null +++ b/.config/nvim/lua/my/plugins/plugins.lua @@ -0,0 +1,99 @@ +local function has_api_level(desired) + return vim.version().api_level >= desired +end + +return { + -- common dependencies + { 'https://github.com/nvim-lua/plenary.nvim', + lazy = true + }, + + -- basics + { 'https://github.com/owozsh/amora', + init = function() + vim.o.termguicolors = true -- 24 bit colors + end, + config = function() + vim.cmd('colorscheme amora') + -- make comments a bit lighter + vim.api.nvim_set_hl(0, 'AmoraComment', { fg = '#7C4180', ctermfg = 61 }) + vim.api.nvim_set_hl(0, 'AmoraCommentBold', + { fg = '#7C4180', ctermfg = 61, bold = true }) + end, + }, + { 'https://github.com/editorconfig/editorconfig-vim', + -- 0.9.0 has EditorConfig support included + enabled = not has_api_level(11) + }, + { 'https://github.com/ii14/autosplit.nvim', + init = function() + -- split these vertically if there is enough space + vim.g.autosplit_bt = { 'help', 'terminal' } + vim.g.autosplit_ft = { + 'man', 'fugitive', 'gitcommit', 'gitrebase', 'git' + } + end, + }, + + -- filetypes + { 'https://github.com/nvim-treesitter/nvim-treesitter', + version = '*', + build = [[:TSUpdateSync]], + opts = { + ensure_installed = 'all', + ignore_install = { 'comment', 'help' }, + sync_install = true, + highlight = { + enable = true, + additional_vim_regex_highlighting = { 'cpp' } + } + }, + }, + { 'https://github.com/JoosepAlviste/nvim-ts-context-commentstring', + dependencies = 'nvim-treesitter', + enabled = has_api_level(11), + opts = { + enable = true, + enable_autocmd = false + }, + init = function() + vim.g.skip_ts_context_commentstring_module = true + end, + }, + { 'https://github.com/folke/todo-comments.nvim', + version = '*', + dependencies = { 'plenary.nvim' }, + enabled = has_api_level(11), + opts = { + signs = false, + highlight = { + keyword = 'bg', + after = '' + } + }, + init = function() + vim.g.vimtex_compiler_latexmk_engines = { _ = '-xelatex' } + end, + }, + { 'https://github.com/powerman/vim-plugin-AnsiEsc' }, + { 'https://github.com/lervag/vimtex', + version = '*', + enabled = has_api_level(11) and vim.fn.executable('xelatex') == 1 + }, + { 'https://github.com/NvChad/nvim-colorizer.lua', + opts = { + filetypes = { '*' }, + user_default_options = { + mode = 'virtualtext', + rgb_fn = true, + hsl_fn = true, + RRGGBBAA = true, + } + }, + }, + { 'https://github.com/gennaro-tedesco/nvim-jqx', + version = '*', + ft = { "json", "yaml" }, + }, + { 'https://github.com/isobit/vim-caddyfile' }, +} diff --git a/.config/nvim/lua/my/tools.lua b/.config/nvim/lua/my/tools.lua deleted file mode 100644 index cbd2e36..0000000 --- a/.config/nvim/lua/my/tools.lua +++ /dev/null @@ -1,177 +0,0 @@ -require('which-key').setup({}) - -local map = require('my.functions').map -local telescope = require('telescope') -local t_actions = require('telescope.actions') -telescope.load_extension('projections') -telescope.load_extension('dap') -telescope.load_extension('fzf') - -telescope.setup({ - mappings = { - i = { - [""] = t_actions.which_key, - }, - n = { - ["?"] = t_actions.which_key, - } - }, - defaults = { - file_ignore_patterns = { '^\\.git', '^fun' }, - }, - pickers = { - find_files = { - -- show hidden files by default - find_command = { "rg", "--files", "--hidden", "--glob", "!.git/*" } - } - } -}) - -local t_builtin = require('telescope.builtin') -local my = require('my.functions') -require('which-key').add({{ 't', group = 'Telescope' }}) -map('n', 'tb', t_builtin.buffers, 'Buffers') -map('n', 'tf', function() - t_builtin.find_files({ cwd = my.get_project_root() }) -end, 'Files') -map('n', 'tF', t_builtin.find_files, 'Files in cwd') -map('n', 'to', t_builtin.oldfiles, 'Recently opened files') -map('n', 'tg', function() - t_builtin.live_grep({ cwd = my.get_project_root() }) -end, 'Live-grep') -map('n', 'tm', t_builtin.man_pages, 'Man pages') -map('n', 'tr', t_builtin.registers, 'Registers') -map('n', 'gh', t_builtin.git_bcommits, 'History of this file') -map('n', '', t_builtin.diagnostics, 'Show diagnostics') -map('n', 'tp', telescope.extensions.projections.projections, 'Projects') -map('n', 'tt', - require("telescope._extensions.todo-comments").exports.todo, - 'Display TODO comments in project') -map('n', 'tn', telescope.extensions.notify.notify, 'Notifications') - -local nerdfont_installed = require('my.functions').nerdfont_installed() - -require("nvim-tree").setup({ - filters = { - dotfiles = false, - custom = { '^\\.git' } - }, - sync_root_with_cwd = true, - respect_buf_cwd = true, - update_focused_file = { - enable = true, - update_root = true - }, - renderer = { - icons = { - show = { - file = nerdfont_installed, - folder = nerdfont_installed, - folder_arrow = nerdfont_installed, - git = nerdfont_installed - } - } - } -}) -map('n', '', require("nvim-tree.api").tree.toggle, 'Open nvim-tree') -map('i', '', require("nvim-tree.api").tree.toggle, 'Open nvim-tree') - -vim.o.showmode = false -local not_firenvim = require('my.functions').not_firenvim -require('lualine').setup({ - options = { - icons_enabled = nerdfont_installed, - component_separators = {}, - section_separators = {}, - extensions = {}, - globalstatus = true - }, - sections = { - lualine_a = { { 'mode' } }, - lualine_b = { - { 'branch', icons_enabled = true }, - { 'diff' }, - { require('my.functions').lsp_status, padding = 0 }, - { 'diagnostics' } - }, - lualine_c = { - { - 'filename', - path = 1, - newfile_status = true, - cond = not_firenvim - }, - { - require('my.functions').current_function, - padding = 0, - color = 'StatusLineNC' - } - }, - lualine_x = { { - require('my.functions').lsp_sig_status, - color = 'StatusLineNC' - }, { 'filetype' } }, - lualine_y = { { 'progress' } }, - lualine_z = { { 'location' }, { '"🍄"', padding = 0 } - } - }, -}) - -if vim.version().api_level >= 10 then -- >=0.8.0 - require('lualine').setup({ - inactive_winbar = { - lualine_c = { { 'filename', cond = not_firenvim } }, - } - }) -end - -map('n', 'B', require('bug-reference').open, 'Open bug under cursor') - -local mind = require('mind') -mind.setup({ - ui = { - width = 50 - } -}) -local function mind_project() - vim.cmd.lcd(require('my.functions').get_project_root()) - mind.open_project() -end - -map('n', '', mind.open_main, 'Open main mind') -map('n', '', mind.open_main, 'Open main mind') -- = -map('n', '', mind_project, 'Open project mind') -map('n', '', mind_project, 'Open project mind') -- = - -vim.g.table_mode_map_prefix = 'T' -require('which-key').add({{ 'T', group = 'Table mode' }}) - -require('dressing').setup({ - input = { - relative = 'win', - min_width = { 60, 0.4 }, - } -}) - -require('notify').setup({ - on_open = function(win) - vim.api.nvim_win_set_option(win, 'wrap', true) -- does not work - end, - stages = 'static', -}) -vim.notify = require('notify') - -require('autolist').setup({}) - -require('which-key').add({{ 'j', group = 'Jump' }}) -map('n', 'ja', require('harpoon.mark').add_file, 'Add file') -map('n', 'jm', require('harpoon.ui').toggle_quick_menu, 'Quick menu') - -require('copyright-updater').setup({ - enabled = true, - return_cursor = true, - mappings = nil, - limiters = { - range = '1,10' - } -})