-- vim: fen fdm=marker fdl=0 ---@diagnostic disable: undefined-global -- load by calling `lua require('plugins')` from your init.vim local g = vim.g -- force packer into a system directory -- local datadir = vim.fn.stdpath('data_dirs')[1] local datadir = vim.fn.stdpath('data') local install_path = require('packer.util').join_paths(datadir, '/site/pack/packer/start/packer.nvim') if vim.fn.empty(vim.fn.glob(install_path)) > 0 then vim.fn.system({ 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path }) vim.api.nvim_command 'packadd packer.nvim' end if not vim.fn.filewritable(vim.fn.stdpath('cache')) == 2 then return end local function disable_distribution_plugins() -- {{{ g.loaded_gzip = 1 g.loaded_tar = 1 g.loaded_tarPlugin = 1 g.loaded_zip = 1 g.loaded_zipPlugin = 1 g.loaded_getscript = 1 g.loaded_getscriptPlugin = 1 g.loaded_vimball = 1 g.loaded_vimballPlugin = 1 g.loaded_matchit = 1 -- g.loaded_matchparen = 1 g.loaded_2html_plugin = 1 g.loaded_logiPat = 1 g.loaded_rrhelper = 1 g.loaded_netrw = 1 g.loaded_netrwPlugin = 1 g.loaded_netrwSettings = 1 g.loaded_netrwFileHandlers = 1 end -- }}} -- we change the packer.compile_path below, so we need to require it here... require('packer_compiled') return require('packer').startup({function() -- disable built-in plugins disable_distribution_plugins() -- manage packer itself use {'wbthomason/packer.nvim'} -- improve startup time by optimizing lua `require` use {'lewis6991/impatient.nvim'} -- git status in the sign column use {'lewis6991/gitsigns.nvim', --- {{{ requires = {'nvim-lua/plenary.nvim'}, config = function() require('gitsigns').setup { signs = { change = {hl='GitSignsChange', text='│', numhl='GitSignsChangeLn'}, add = {hl='GitSignsAdd', text='│', numhl='GitSignsAddLn'}, delete = {hl='GitSignsDelete', text='_', numhl='GitSignsDeleteLn'}, topdelete = {hl='GitSignsDelete', text='‾', numhl='GitSignsDeleteLn'}, changedelete = {hl='GitSignsChange', text='~', numhl='GitSignsChangeLn'}, }, signcolumn = true, numhl = true, linehl = true, word_diff = true, keymaps = { noremap = true, ['n ]h'] = { 'Gitsigns next_hunk'}, ['n [h'] = { 'Gitsigns prev_hunk'}, -- text objects -- ['o ih'] = ':Gitsigns select_hunk', -- ['x ih'] = ':Gitsigns select_hunk' } } end} -- }}} use {'numToStr/Comment.nvim', -- {{{ config = function() require('Comment').setup { opleader = { block = 'gC', } } end} -- }}} use {'windwp/nvim-autopairs', -- {{{ config = function() require('nvim-autopairs').setup() end} -- }}} use {'tpope/vim-surround'} -- edit surroundings in pairs use {'justinmk/vim-dirvish', config = function() -- vim.cmd [[ call dirvish#add_icon_fn({ p -> p[-1:]=='/'?'':' '}) ]] end} use {'ggandor/lightspeed.nvim', disable = true, config = function() -- vim.cmd [[ vunmap x ]] end} use {'jose-elias-alvarez/null-ls.nvim', -- {{{ requires = {'nvim-lua/plenary.nvim'}, config = function() local nls = require('null-ls') local h = require('null-ls.helpers') nls.config { -- debug = true, sources = { nls.builtins.diagnostics.shellcheck, -- *sh -- nls.builtins.formatting.clang_format, -- c* -- nls.builtins.formatting.gofumpt, -- go -- nls.builtins.formatting.json_tool, -- json -- nls.builtins.formatting.rustfmt, -- rust nls.builtins.formatting.shfmt, -- *sh nls.builtins.formatting.yapf, -- python h.make_builtin({ method = nls.methods.DIAGNOSTICS, filetypes = { 'go' }, generator_opts = { command = 'sh', args = { '-c', 'golangci-lint run --fix=false --out-format=tab -E gocritic | grep ^$RELNAME', }, to_stdin = false, check_exit_code = {0, 1}, format = 'line', on_output = h.diagnostics.from_patterns({ { pattern = [[(.+):(%d+):(%d+)%s+([%w%_%-]+)%s+(.*)]], groups = { 'data', 'row', 'col', 'source', 'message' }, } }) }, factory = h.generator_factory, }) } } require('lspconfig')['null-ls'].setup { on_attach = require('lsp').my_attach } end} -- }}} use {'neovim/nvim-lspconfig', -- {{{ requires = {'~/devel/projects/spinner.nvim'}, config = function() require('lsp').setup() end} -- }}} use {'kosayoda/nvim-lightbulb', -- {{{ -- branch = 'virtual-text-column', config = function() _G.lightbulb_config = { sign = { enabled = false, priority = 10, }, float = { enabled = false, text = '󰌵', win_opts = {}, }, virtual_text = { enabled = false, text = '← 󰌵', text_pos = 'eol', column = -1, }, -- status text only works on master status_text = { enabled = true, text = '󰌵', test_unavailable = '', } } -- vim.fn.sign_define({{name='LightBulbSign', text='󰌵', texthl='LightBulbVirtualText'}}) augroup { lightbulb = { {'CursorHold', '*', [[lua require('nvim-lightbulb').update_lightbulb(_G.lightbulb_config)]]} } } end} -- }}} use {'weilbith/nvim-code-action-menu', -- {{{ cmd = 'CodeActionMenu', } -- }}} use {'nvim-treesitter/nvim-treesitter', -- {{{ run = ':TSUpdate', requires = { 'nvim-treesitter/completion-treesitter', 'nvim-treesitter/nvim-treesitter-refactor', 'nvim-treesitter/nvim-treesitter-textobjects', }, config = function() local enabled = { 'bash', 'c', 'c_sharp', 'comment', 'css', 'dockerfile', 'go', 'gomod', 'html', 'javascript', 'json', 'jsonc', 'ledger', 'lua', 'org', 'regex', 'rust', 'scss', 'toml', 'typescript', 'vim', 'yaml', 'zig', } local tsconf = require('nvim-treesitter.parsers').get_parser_configs() tsconf.org = { install_info = { url = 'https://github.com/milisims/tree-sitter-org', files = {'src/parser.c', 'src/scanner.cc'}, revision = 'main', } } require('nvim-treesitter.configs').setup { ensure_installed = enabled, highlight = { enable = true, additional_vim_regex_highlighting = {'org'}, }, indent = { enable = true, }, incremental_selection = { enable = true, keymaps = { init_selection = 'gnn', node_incremental = 'grn', node_decremental = 'grm', }, }, refactor = { navigation = { enable = true, keymaps = { goto_definition = "", }, }, smart_rename = { enable = true, keymaps = { smart_rename = "grr", }, }, }, textobjects = { select = { enable = true, keymaps = { ["ib"] = '@block.inner', ["ob"] = '@block.outer', ["ic"] = '@conditional.inner', ["oc"] = '@conditional.outer', ["if"] = '@function.inner', ["of"] = '@function.outer', ["il"] = '@loop.inner', ["ol"] = '@loop.outer', ["is"] = '@scopename.inner', ["os"] = '@scopename.outer', }, }, }, } augroup { treesitter = {{ 'FileType', table.concat(enabled, ','), [[ set foldmethod=expr foldexpr=nvim_treesitter#foldexpr() ]] }} } end} -- }}} use {'hrsh7th/nvim-cmp', -- {{{ requires = { 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-nvim-lua', 'hrsh7th/cmp-nvim-lsp', -- 3rd party 'dcampos/cmp-snippy', 'f3fora/cmp-spell', }, config = function() local cmp = require('cmp') cmp.setup { completion = { -- autocomplete = { cmp.TriggerEvent.TextChanged } }, preselect = cmp.PreselectMode.Item, documentation = { -- border = 'single', border = { '', '', '', ' ', '', '', '', ' ' }, }, mapping = { [''] = cmp.mapping.confirm(), [''] = cmp.mapping.complete(), [''] = cmp.mapping.close(), }, snippet = { expand = function(args) require('snippy').expand_snippet(args.body) end, }, sources = { { name = 'nvim_lsp' }, { name = 'snippy' }, { name = 'nvim_lua' }, { name = 'orgmode' }, { name = 'spell' }, { name = 'path' }, { name = 'buffer' }, }, experimental = { -- ghost_text = { hl_group = 'Comment' } } } end} -- }}} use {'nvim-telescope/telescope.nvim', --- {{{ requires = { 'nvim-lua/popup.nvim', 'nvim-lua/plenary.nvim', -- telescope plugins: -- 'nvim-telescope/telescope-fzf-writer.nvim', }, config = function() local nnoremap = require('astronauta.keymap').nnoremap require('telescope').setup{ defaults = { -- initial_mode = 'input', prompt_prefix = '> ', selection_caret = '* ', sorting_strategy = 'ascending', preview_title = '', layout_strategy = 'bottom_pane', layout_config = { preview_cutoff = 1, height = 20, }, border = true, borderchars = { 'z', prompt = { '─', ' ', ' ', ' ', '─', '─', ' ', ' ' }, results = { ' ' }, -- results = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' }, preview = { '─', '│', '─', '│', '┌', '┐', '┘', '└'}, -- "center" -- { '─', '│', '─', '│', '┌', '┐', '┘', '└'}, -- prompt = {'─', '│', ' ', '│', '┌', '┐', '│', '│'}, -- results = {'─', '│', '─', '│', '├', '┤', '┘', '└'}, -- preview = { '─', '│', '─', '│', '┌', '┐', '┘', '└'}, }, file_previewer = require('telescope.previewers').vim_buffer_cat.new, grep_previewer = require('telescope.previewers').vim_buffer_vimgrep.new, qflist_previewer = require('telescope.previewers').vim_buffer_qflist.new, extensions = { fzf_writer = { use_highlighter = true, minimum_grep_characters = 4, shorten_path = true, } } } } nnoremap { ';Q', require('telescope.builtin').quickfix } nnoremap { ';C', require('telescope.builtin').loclist } nnoremap { ';H', require('telescope.builtin').help_tags } nnoremap { ';b', require('telescope.builtin').buffers } nnoremap { ';c', require('telescope.builtin').commands } nnoremap { ';f', require('telescope.builtin').fd } nnoremap { ';g', require('telescope.builtin').live_grep } nnoremap { ';h', require('telescope.builtin').command_history } nnoremap { ';l', require('telescope.builtin').current_buffer_fuzzy_find } nnoremap { ';o', require('telescope.builtin').oldfiles } nnoremap { ';t', require('telescope.builtin').tags } nnoremap { ';w', require('telescope.builtin').file_browser } nnoremap { ';v', function() require('telescope.builtin').find_files({ prompt_title = 'vimrc', previewer = false, cwd = vim.fn.stdpath('config'), }) end } -- LSP stuff nnoremap { ';s', require('telescope.builtin').lsp_workspace_symbols } nnoremap { ';a', require('telescope.builtin').lsp_code_actions } nnoremap { ';d', require('telescope.builtin').lsp_workspace_diagnostics } nnoremap { ';r', require('telescope.builtin').lsp_references } end} -- }}} -- TODO(robert): look into this more use {'tjdevries/sg.nvim', disable = true, requires = {'nvim-lua/plenary.nvim'}, config = function() end} -- polyfill for some missing stuff use {'tjdevries/astronauta.nvim'} -- snippets use {'dcampos/nvim-snippy', -- {{{ requires = { 'honza/vim-snippets' }, config = function() local S = require('snippy') local K = require('astronauta.keymap') K.inoremap { '', function() if S.can_jump(1) then S.next() else return '' end end } K.inoremap { '', function() if S.can_jump(-1) then S.previous() else return '' end end } K.snoremap { '', function() if S.can_jump(1) then S.next() else return '' end end } K.snoremap { '', function() if S.can_jump(-1) then S.previous() else return '' end end } end} -- }}} use {'junegunn/vim-easy-align'} use {'editorconfig/editorconfig-vim', -- {{{ config = function() augroup { editorconfig = { { 'FileType', 'gitcommit', 'let b:EditorConfig_disable = 1' }, } } end} -- }}} use {'lukas-reineke/indent-blankline.nvim', -- {{{ config = function() require('indent_blankline').setup { char = '▏', char_highlight_list = {'Whitespace'}, -- space_char = ' ', -- space_char_highlight_list = {}, show_first_indent_level = true, show_trailing_blankline_indent = false, show_end_of_line = true, use_treesitter = true, disable_with_nolist = true, buftype_exclude = {'terminal'}, bufname_exclude = {'README.md'}, strict_tabs = true, show_current_context = true, context_patterns = {'class', 'function', 'method', 'block'}, -- context_highlight_list = {'Folded'}, context_highlight_list = {'deEmph'}, } end} -- }}} use {'tpope/vim-repeat'} -- extend '.' to plugins use {'michaeljsmith/vim-indent-object'} -- indentation text-objects use {'kshenoy/vim-signature', disable = true} -- toggle, display and navigate marks use {'norcalli/nvim-colorizer.lua', -- {{{ config = function() require('colorizer').setup(nil, { name = true; RRGGBB = true; RRGGBBAA = false; rgb_fn = true; hsl_fn = true; mode = 'background'; }) end} -- }}} use {'rhysd/git-messenger.vim', -- {{{ config = function() -- vim.g.git_messenger_include_diff = false vim.g.git_messenger_always_into_popup = true vim.g.git_messenger_close_on_cursor_moved = true vim.g.git_messenger_no_default_mappings = true require('astronauta.keymap').nnoremap { 'gm', function() vim.cmd [[GitMessenger]] end } end} -- }}} use {'liuchengxu/vista.vim'} use {'rhysd/conflict-marker.vim', disable = true} use {'kassio/neoterm', disable = true} use {'kristijanhusak/orgmode.nvim', -- {{{ ft = {'org'}, config = function() require('orgmode').setup { org_agenda_files = {vim.env.HOME..'/Documents/org/*.org'}, org_default_notes_file = vim.env.HOME..'/Documents/org/todo.org', org_todo_keywords = {'TODO', 'DONE'}, org_indent_mode = 'noindent', org_agenda_templates = { t = { description = 'Todo', template = '* TODO %?', }, n = { description = 'Note', template = '* %?', target = vim.env.HOME..'/Documents/org/notes.org', }, }, mappings = { agenda = { org_agenda_close = nil, } }, } local pickers = require('telescope.pickers') local finders = require('telescope.finders') require('astronauta.keymap').nnoremap { ';O', function() pickers.new(opts, { prompt_title = 'Orgmode', finder = finders.new_table(require('orgmode.config'):get_all_files()), }):find() end } -- vim.cmd [[ command! Orgmode lua require('orgmode').action('agenda.prompt') ]] -- vim.cmd [[ command! OrgmodeCapture lua require('orgmode').action('capture.refile') ]] -- vim.cmd [[ command! OrgmodeInsert lua require('orgmode').action('org_mappings.insert_heading_respect_content') ]] -- vim.cmd [[ command! OrgmodeTodoCycle('orgmode').action('org_mappings.todo_next_state') ]] -- vim.cmd [[ command! OrgmodeTag lua require('orgmode').action('org_mappings.set_tags') ]] -- vim.cmd [[ command! OrgmodeArchive lua require('orgmode').action('org_mappings.toggle_archive_tag') ]] end} -- }}} -- languages -- NOTE: these should only be loaded when they are required... -- use {'rhysd/vim-grammarous', -- ft = {'markdown', 'latex', 'tex'} -- } use {'lervag/vimtex', -- {{{ ft = {'latex', 'tex'}, config = function() vim.g.tex_flavor = 'latex' vim.g.vimtex_compiler_enabled = 0 vim.g.vimtex_compiler_method = 'tectonic' vim.g.vimtex_compiler_tectonic = "{'executable': 'tectonic'}" vim.g.vimtex_view_method = 'zathura' -- vim.g.vimtex_view_zathura_check_libsynctex = false -- vim.g.vimtex_view_use_temp_files = true -- vim.g.vimtex_view_forward_search_on_start = false end} -- }}} use {'plasticboy/vim-markdown', -- {{{ ft = {'markdown'}, config = function() vim.g.vim_markdown_folding_disabled = true vim.g.vim_markdown_math = true vim.g.vim_markdown_frontmatter = true vim.g.vim_markdown_json_frontmatter = true vim.g.vim_markdown_toml_frontmatter = true vim.g.vim_markdown_yaml_frontmatter = true -- vim.g.vim_markdown_folding_level = 2 vim.g.vim_markdown_strikethrough = true vim.g.vim_markdown_auto_insert_bullets = true vim.g.vim_markdown_new_list_item_indent = false vim.g.vim_markdown_conceal = true vim.g.vim_markdown_conceal_code_blocks = true end} -- }}} -- use {'masukomi/vim-markdown-folding', ft = {'markdown'}} use {'jjo/vim-cue', ft = {'cue'}} use {'gentoo/gentoo-syntax'} -- polyglot: multi-language support with lazy loading {{{ -- NOTE: put language specific plugs before this to avoid conflicsts g.polyglot_disabled = { 'bash', 'c', 'c_sharp', 'dockerfile', 'go', 'gomod', 'html', 'javascript', 'json', 'jsonc', 'ledger', 'lua', 'rust', 'scss', 'sh', 'toml', 'typescript', 'vim', 'yaml', } use {'sheerun/vim-polyglot'} -- }}} use {'folke/zen-mode.nvim', -- {{{ config = function() require('zen-mode').setup { window = { backdrop = 1, width = 0.3, -- height = 1, options = { number = false, list = false, }, }, plugins = { options = { enabled = true, ruler = false, showcmd = false, }, twilight = { enabled = true }, } } end} -- }}} use {'folke/twilight.nvim', -- {{{ config = function() require('twilight').setup { context = 15, dimming = { alpha = 0.3, color = { 'Normal', '#ffffff' }, }, } end} -- }}} use {'goolord/alpha-nvim', -- {{{ config = function() local alpha = require('alpha') local them = require('alpha.themes.startify') local hr = function() local margin = 3; return string.rep(' ', margin) .. string.rep('─', vim.o.columns-(2*margin)) end them.opts.layout = { {type = 'padding', val = 1}, them.section.header, {type = 'padding', val = 1}, { type = 'text', val = function() local j = require('plenary.job'):new({ command = 'fortune', args = {vim.env.HOME..'/devel/projects/zig/fortune/fortunes'}, enable_recording = true, }) local lines = j:sync() local new = {} for i = 1, #lines do if not (vim.trim(lines[i]) == '') then new[#new+1] = string.rep(' ', 3) .. lines[i] end end return new end, opts = { hl = 'AlphaFortune', } }, {type = 'padding', val = 1}, {type = 'text', val = hr, opts = {hl = 'Comment'}}, {type = 'padding', val = 1}, { type = 'group', val = { them.button('e', '󰈔 new', [[ene startinsert]]), them.button('r', '󰈸 live grep', [[lua require('misc').live_grep()]]), them.button('f', '󰝰 find files', [[lua require('misc').find_files()]]), them.button('m', '󰥔 mru', [[lua require('telescope.builtin').oldfiles()]]), them.button('t', '󰗇 tasks', [[lua require('packer').loader('orgmode.nvim'); require('orgmode').action('agenda.todos')]]), them.button('a', '󰃶 agenda', [[lua require('packer').loader('orgmode.nvim'); require('orgmode').action('agenda.agenda')]]), them.button('u', '󰚰 update plugins', [[lua require('packer').sync()]]), them.button('c', '󰂓 edit config', [[lua require('telescope.builtin').find_files({search_dirs={vim.env.HOME..'/.vim/'}})]]), } }, {type = 'padding', val = 1}, {type = 'text', val = function() return ' ❱ ' .. vim.loop.cwd() end, opts = {hl = 'Title'}}, {type = 'padding', val = 1}, { type = 'group', val = function() local cwd = vim.loop.cwd() local oldfiles = {} for _, v in pairs(vim.v.oldfiles) do if #oldfiles == 10 then break end if vim.startswith(v, cwd) then oldfiles[#oldfiles+1] = v end end local val = {} for i, fn in pairs(oldfiles) do local shortfn = vim.fn.fnamemodify(fn, ':.') val[#val+1] = them.button(tostring(i-1), shortfn, ":e " .. fn .. " ") end return val end, }, {type = 'padding', val = 1}, {type = 'text', val = hr, opts = {hl = 'Comment'}}, {type = 'padding', val = 1}, { type = 'group', val = { them.button('q', 'quit', [[:quit]]), }, }, } alpha.setup(them.opts) augroup { alpha_indent = { { 'FileType', 'alpha', [[ IndentBlanklineDisable ]] }, } } end} -- }}} use {'ruifm/gitlinker.nvim', -- {{{ requires = {'nvim-lua/plenary.nvim'}, config = function() require('gitlinker').setup { opts = { action_callback = require('gitlinker.actions').copy_to_clipboard, }, } end} -- }}} use {'lewis6991/spellsitter.nvim', disable = true, -- {{{ config = function() require('spellsitter').setup { enable = true, spellchecker = 'ffi' } end} -- }}} use {'rktjmp/lush.nvim'} end, config = { package_root = require('packer.util').join_paths(datadir, 'site/pack'), compile_path = require('packer.util').join_paths(vim.fn.stdpath('config'), 'lua/packer_compiled.lua'), git = { subcommands = { update = 'pull --ff-only --progress --rebase=true', } } }})