-- vim: fdm=marker fdl=0 ---@diagnostic disable: undefined-global -- load by calling `lua require('plugins')` from init.vim local g = vim.g local augroup = vim.api.nvim_create_augroup local autocmd = vim.api.nvim_create_autocmd -- force packer into a system directory {{{ if not vim.fn.filewritable(vim.fn.stdpath('cache')) == 2 then return end -- local datadir = vim.fn.stdpath('data_dirs')[1] local datadir = vim.fn.stdpath('data') local install_path = datadir .. '/site/pack/packer/start/packer.nvim' if vim.fn.empty(vim.fn.glob(install_path)) > 0 then vim.notify('Installing packer.nvim...') vim.fn.system({ 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }) vim.api.nvim_command([[packadd packer.nvim]]) 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... local compilepath = vim.fn.stdpath('config') .. '/lua/packer_compiled.lua' if not (vim.fn.empty(vim.fn.glob(compilepath)) > 0) then require('packer_compiled') end -- auto-compile on save -- {{{ do vim.api.nvim_create_user_command( 'PackerRecompile', function() for _, client in pairs(vim.lsp.get_active_clients()) do if vim.tbl_contains(client.config.filetypes, 'lua') then client.stop() end end vim.cmd [[luafile $HOME/.vim/lua/plugins.lua]] vim.cmd [[PackerCompile]] vim.notify('packer: lazy-loading refreshed') end, {}) local group = vim.api.nvim_create_augroup('PackerAutoCompile', { clear = true }) vim.api.nvim_create_autocmd('BufWritePost', { pattern = 'plugins.lua', command = [[PackerRecompile]], group = group }) end -- }}} 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'} -- neat helper for when you don't remember your keymap use {'folke/which-key.nvim', -- {{{ config = function() require('which-key').setup { icons = { separator = '→ ', group = '🞱 ' }, triggers = {'', '', ';', 'g', '[', ']'}, } end} -- }}} 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 = false, linehl = false, word_diff = false, preview_config = { border = _G.floating_win_border, }, on_attach = function(bufnr) local gs = package.loaded.gitsigns vim.keymap.set('n', ']c', function() if vim.wo.diff then return ']c' end vim.schedule(gs.next_hunk) return '' end, {expr=true, buffer=bufnr}) vim.keymap.set('n', '[c', function() if vim.wo.diff then return '[c' end vim.schedule(gs.prev_hunk) return '' end, {expr=true, buffer=bufnr}) vim.keymap.set('n', 'hb', gs.toggle_current_line_blame, {buffer=bufnr}) vim.keymap.set('n', 'hB', function() gs.blame_line {full=true} end, {buffer=bufnr}) vim.keymap.set('n', 'hp', gs.preview_hunk, {buffer=bufnr}) vim.keymap.set('n', 'hd', gs.diffthis, {buffer=bufnr}) vim.keymap.set('n', 'hl', function() gs.setqflist(0, {open=false}) vim.schedule(function() require('telescope.builtin').quickfix() end) end, {buffer=bufnr}) wk_register { [']c'] = 'next git hunk', ['[c'] = 'previous git hunk', ['h'] = { name = '+GitSigns', b = 'toggle line blame', B = 'show full line blame', p = 'preview hunk', d = 'diffthis', l = 'list hunks' } } end, } 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} -- }}} -- gcc to comment out text use {'numToStr/Comment.nvim', -- {{{ config = function() require('Comment').setup { opleader = { block = 'gC', } } end} -- }}} use {'editorconfig/editorconfig-vim', -- {{{ config = function() local group = vim.api.nvim_create_augroup('EditorConfigDisable', { clear = true }) vim.api.nvim_create_autocmd('FileType', { pattern = {'gitcommit'}, command = [[let b:EditorConfig_disable = 1]], group = group, }) end} -- }}} use {'windwp/nvim-autopairs', -- {{{ config = function() require('nvim-autopairs').setup() end} -- }}} use {'elihunter173/dirbuf.nvim', -- {{{ config = function() require('dirbuf').setup { hash_padding = 4, sort_order = 'directories_first', } vim.api.nvim_create_autocmd('FileType', { pattern = 'dirbuf', callback = function() vim.keymap.set('n', 'gT', function() vim.loop.spawn('swaymsg', {args = {'exec', '--', 'foot', '-D', vim.fn.expand('%')}}) -- vim.fn.system('swaymsg exec -- foot -D ' .. vim.fn.expand('%')) end, { buffer = 0 }) wk_register { ['gT'] = {'Open in foot'} } end, group = vim.api.nvim_create_augroup('DirBufEnter', {}), }) end} -- }}} use {'ggandor/leap.nvim', -- {{{ config = function() require('leap').set_default_keymaps() end} -- }}} _G.treesitter_enabled = { -- {{{ 'bash', 'bibtex', 'c', 'c_sharp', 'cpp', 'cmake', 'comment', 'css', 'dockerfile', -- 'elixir', 'go', 'gomod', 'gowork', 'hcl', 'help', 'html', 'java', 'javascript', 'json', 'jsonc', 'latex', 'ledger', 'lua', 'make', 'markdown', 'ninja', 'norg', 'regex', 'rust', 'scss', 'toml', 'typescript', 'vim', 'yaml', 'zig', 'org', 'norg_meta', 'norg_table', 'hare', 'gotmpl', } -- }}} use {'nvim-treesitter/nvim-treesitter', -- {{{ run = ':TSUpdate', requires = { 'nvim-treesitter/nvim-treesitter-refactor', 'nvim-treesitter/nvim-treesitter-textobjects', 'nvim-treesitter/playground', }, config = function() 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', } } tsconf.norg_meta = { install_info = { url = 'https://github.com/nvim-neorg/tree-sitter-norg-meta', files = {'src/parser.c'}, branch = 'main' } } tsconf.norg_table = { install_info = { url = 'https://github.com/nvim-neorg/tree-sitter-norg-table', files = {'src/parser.c'}, branch = 'main' } } tsconf.hare = { install_info = { url = 'https://git.sr.ht/~ecmma/tree-sitter-hare', files = {'src/parser.c'}, } } tsconf.gotmpl = { install_info = { url = 'https://github.com/ngalaiko/tree-sitter-go-template', files = {'src/parser.c'}, }, filetype = 'gotmpl', used_by = {'gohtmltmpl', 'gotexttmpl', 'gotmpl', 'yaml'}, } require('nvim-treesitter.configs').setup { ensure_installed = _G.treesitter_enabled, disable = {'jsonc'}, highlight = { enable = true, additional_vim_regex_highlighting = {'markdown'}, }, 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', }, }, }, } end} -- }}} use {'neovim/nvim-lspconfig', -- {{{ require = { 'nvim-lua/lsp-status.nvim', }, config = function() require('lsp').setup() end} -- }}} use {'nvim-lua/lsp-status.nvim', -- {{{ config = function() local lspstatus = require('lsp-status') lspstatus.config { diagnostics = false, current_function = false, status_symbol = '', } lspstatus.register_progress() end} -- }}} use {'SmiteshP/nvim-navic', -- {{{ requires = {'neovim/nvim-lspconfig'}, config = function() local navic = require('nvim-navic') navic.setup { icons = package.loaded.lsp.symbols } end} -- }}} use {'kosayoda/nvim-lightbulb', -- {{{ -- branch = 'virtual-text-column', config = function() require('nvim-lightbulb').setup { ignore = {'null-ls'}, sign = { enabled = false }, virtual_text = { enabled = false, text = '← 󰌵' }, status_text = { enabled = true, text = '󰌵', text_unavailable = '' } } vim.fn.sign_define({{name='LightBulbSign', text='󰌵', texthl='LightBulbSign'}}) vim.api.nvim_create_autocmd({'CursorHold', 'CursorHoldI'}, { callback = require('nvim-lightbulb').update_lightbulb, group = vim.api.nvim_create_augroup('LightBulbUpdate', {}), }) end} -- }}} use {'weilbith/nvim-code-action-menu', module = 'code_action_menu', -- {{{ setup = function() -- vim.lsp.buf.code_action = function(_) -- require('code_action_menu').open_code_action_menu() -- end end, config = function() 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.setup { -- debug = true, sources = { nls.builtins.diagnostics.shellcheck, nls.builtins.formatting.shfmt, nls.builtins.formatting.yapf, -- python -- nls.builtins.formatting.clang_format, -- nls.builtins.formatting.gofumpt, -- nls.builtins.formatting.json_tool, -- nls.builtins.formatting.rustfmt, -- nls.builtins.formatting.stylua, }, on_attach = require('lsp').my_attach, } end} -- }}} use {'mfussenegger/nvim-dap', module = {'dap'}, -- {{{ requires = {'nvim-telescope/telescope-dap.nvim'}, config = function() require('debugger') end} -- }}} use {'hrsh7th/nvim-cmp', -- {{{ requires = { 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-path', 'hrsh7th/cmp-nvim-lua', 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-nvim-lsp-document-symbol', 'hrsh7th/cmp-nvim-lsp-signature-help', 'saadparwaiz1/cmp_luasnip', 'f3fora/cmp-spell', 'windwp/nvim-autopairs', 'neovim/nvim-lspconfig', }, config = function() local cmp = require('cmp') local luasnip = require('luasnip') cmp.setup { completion = { -- autocomplete = { cmp.TriggerEvent.TextChanged } }, preselect = cmp.PreselectMode.Item, window = { documentation = { border = _G.floating_win_border, }, }, mapping = { [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.confirm({ select = true }) elseif luasnip.expandable() then luasnip.expand() else fallback() end end), [''] = cmp.mapping.complete(), [''] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close(), }), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else fallback() end end, { 'c', 'i', 's'}), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif luasnip.jumpable(-1) then luasnip.jump(-1) else fallback() end end, { 'c', 'i', 's'}), [''] = cmp.mapping({ i = function(fallback) if cmp.visible() then cmp.confirm({ select = true }) elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else fallback() end end, s = function(fallback) if cmp.visible() then cmp.select_next_item() elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else fallback() end end, c = function(fallback) if cmp.visible() then cmp.select_next_item() else fallback() end end, }), [''] = cmp.mapping({ s = function(fallback) if cmp.visible() then cmp.select_prev_item() else fallback() end end, c = function(fallback) if cmp.visible() then cmp.select_prev_item() else fallback() end end, }), -- map c-j/k for luasnip choice nodes [''] = cmp.mapping(function(fallback) if luasnip.choice_active() then luasnip.change_choice(1) else fallback() end end, { 'i', 's'}), [''] = cmp.mapping(function(fallback) if luasnip.choice_active() then luasnip.change_choice(-1) else fallback() end end, { 'i', 's'}), }, snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) end, }, sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'nvim_lsp_signature_help' }, { name = 'luasnip' }, { name = 'nvim_lua' }, }, { { name = 'neorg' }, -- { name = 'orgmode' }, { name = 'spell', keyword_length = 3, max_item_count = 10 }, { name = 'path' }, { name = 'buffer', keyword_length = 3 }, }), formatting = { fields = {'kind', 'abbr', 'menu'}, format = function(entry, item) local menus = { nvim_lsp = '░ lsp', luasnip = '░ snip', nvim_lua = '░ nvim', -- orgmode = '░ org', spell = '░ spell', path = '░ path', buffer = '░ buf', } item.kind = package.loaded.lsp.symbols[item.kind] or '' item.menu = menus[entry.source.name] return item end, }, } cmp.setup.cmdline('/', { sources = cmp.config.sources({ { name = 'nvim_lsp_document_symbol' } }, { { name = 'buffer' } }), formatting = { fields = {'abbr', 'menu'}, }, }) cmp.setup.cmdline(':', { sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } }), formatting = { fields = {'abbr', 'menu'}, }, }) -- insert `(` after selecting function/method items cmp.event:on('confirm_done', require('nvim-autopairs.completion.cmp').on_confirm_done { map_char = { tex = '' } }) end} -- }}} use {'L3MON4D3/LuaSnip', -- {{{ config = function() require('snips') end} -- }}} use {'nvim-telescope/telescope.nvim', --- {{{ requires = { 'nvim-lua/popup.nvim', 'nvim-lua/plenary.nvim', -- telescope plugins: {'nvim-telescope/telescope-fzf-native.nvim', run = 'make'}, {'nvim-telescope/telescope-ui-select.nvim'}, {'gbrlsnchs/telescope-lsp-handlers.nvim'}, }, config = function() require('telescope').setup{ defaults = { -- initial_mode = 'input', prompt_prefix = '> ', selection_caret = '* ', sorting_strategy = 'ascending', preview = false, results_title = false, layout_strategy = 'bottom_pane', layout_config = { -- preview_cutoff = 1, -- height = 20, }, border = true, borderchars = { preview = { '─', '│', '─', '│', '┌', '┐', '┘', '└'}, prompt = { '─', ' ', ' ', ' ', '─', '─', ' ', ' ' }, results = { '' }, }, 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, mappings = { i = { [''] = require('telescope.actions.layout').toggle_preview, }, n = { [''] = require('telescope.actions.layout').toggle_preview, }, }, extensions = { fzf = { fuzzy = true, override_generic_sorter = true, override_file_sorter = true, case_mode = 'smart_case', }, lsp_handlers = { disable = { -- ['textDocument/codeAction'] = true, }, }, } } } -- local extension require('telescope').load_extension('jobs') -- required to get fzf-native working require('telescope').load_extension('fzf') require('telescope').load_extension('lsp_handlers') require('telescope').load_extension('ui-select') require('telescope').load_extension('zk') vim.keymap.set('n', ';Q', require('telescope.builtin').quickfix) vim.keymap.set('n', ';C', require('telescope.builtin').loclist) vim.keymap.set('n', ';H', require('telescope.builtin').help_tags) vim.keymap.set('n', ';b', require('telescope.builtin').buffers) vim.keymap.set('n', ';c', require('telescope.builtin').commands) vim.keymap.set('n', ';f', require('telescope.builtin').fd) vim.keymap.set('n', ';g', require('telescope.builtin').live_grep) vim.keymap.set('n', ';h', require('telescope.builtin').command_history) vim.keymap.set('n', ';l', require('telescope.builtin').current_buffer_fuzzy_find) vim.keymap.set('n', ';o', require('telescope.builtin').oldfiles) vim.keymap.set('n', ';d', require('telescope.builtin').diagnostics) -- vim.keymap.set('n', ';s', require('telescope.builtin').lsp_workspace_symbols) -- vim.keymap.set('n', ';r', require('telescope.builtin').lsp_references) vim.keymap.set('n', ';v', function() require('telescope.builtin').find_files({ prompt_title = 'vimrc', previewer = false, cwd = vim.fn.stdpath('config'), }) end) wk_register { [';'] = { name = '+Telescope', Q = {'quickfix'}, C = {'loclist'}, H = {'help'}, b = {'buffers'}, c = {'commands'}, f = {'fd'}, g = {'grep'}, h = {'command history'}, l = {'fuzzy find buffer'}, o = {'oldfiles (mcu)'}, v = {'vimrc'}, d = {'diagnostics'}, -- s = {'workspace symbols'}, -- r = {'references'}, } } end} -- }}} use {'tpope/vim-surround'} 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/conflict-marker.vim', disable = true} use {'kassio/neoterm', disable = true} use {'kristijanhusak/orgmode.nvim', ft = {'org'}, module = {'orgmode'}, disable = true, -- {{{ config = function() require('orgmode').setup_ts_grammar() 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') vim.keymap.set('s', ';O', function() pickers.new(opts, { prompt_title = 'Orgmode', finder = finders.new_table(require('orgmode.config'):get_all_files()), }):find() end) wk_register { ['o'] = { name = '+Orgmode', a = {'agenda prompt'}, c = {'capture prompt'}, r = {'refile'}, [','] = {'set priority'}, ['*'] = {'toggle headline'}, ['o'] = {'follow link/date'}, ['\''] = {'create source block'}, ['$'] = {'archive current headline'}, [''] = {'insert heading/item/row'}, t = {'set tags'}, A = {'toggle ARCHIVE tag'}, K = {'subtree up'}, J = {'subtree down'}, e = {'export'}, ['i'] = { name = '+Timestamp', d = {'set deadline'}, s = {'set scheduled'}, h = {'insert heading (respect content)'}, T = {'insert todo'}, t = {'insert todo (respect content)'}, ['.'] = {'set date'}, ['!'] = {'set inactive'}, }, ['x'] = { name = '+Clock', i = {'clock in'}, o = {'clock out'}, q = {'cancel active clock'}, j = {'jump to active clock'}, e = {'set effort estimate property'}, } }, } end} -- }}} use {'nvim-neorg/neorg', ft = {'norg'}, module = {'neorg'}, cmd = {'Neorg'}, -- {{{ requires = { 'nvim-lua/plenary.nvim', 'nvim-neorg/neorg-telescope', }, setup = vim.cmd [[autocmd BufRead,BufNewFile *.norg setlocal filetype=norg]], after = {'nvim-treesitter'}, config = function() require('neorg').setup { load = { ['core.defaults'] = {}, ['core.keybinds'] = { config = { default_keybinds = true, -- NOTE: neorg uses localleader by default, see init.lua:6 -- neorg_leader = 'n', } }, ['core.norg.concealer'] = { config = { icons = { todo = { enabled = true } }, } }, ['core.norg.dirman'] = { config = { workspaces = { default = '$HOME/Documents/neorg/default', work = '$HOME/Documents/neorg/work', gtd = '$HOME/Documents/neorg/gtd', } } }, ['core.norg.completion'] = { config = { engine = 'nvim-cmp' } }, ['core.integrations.telescope'] = {}, ['core.norg.qol.todo_items'] = {}, ['core.presenter'] = {}, ['core.gtd.base'] = { config = { workspace = 'gtd' } }, }, } end} -- }}} use {'mickael-menu/zk-nvim', module = {'zk', 'telescope._extensions.zk'}, -- {{{ config = function() local lsp = require('lsp') require('zk').setup { picker = 'telescope', lsp = { config = { cmd = {'/home/robert/devel/upstream/github.com/mickael-menu/zk/zk', 'lsp', '--log', '/tmp/zk-lsp.log'}, on_attach = lsp.my_attach, on_exit = lsp.my_exit, capabilities = lsp.capabilities(), }, auto_attach = { enabled = true, filetypes = { 'markdown', 'norg' }, }, }, } vim.keymap.set('n', ';z', function() require('zk').edit(nil, { multi_select = false }) end) wk_register { [';'] = { name = '+Telescope', z = {'zk'} } } 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 {'gentoo/gentoo-syntax'} use {'NMAC427/guess-indent.nvim', disable = false, -- {{{ config = function() require('guess-indent').setup { auto_cmd = true, filetype_exclude = {'netrw', 'tutor', 'dirbuf'}, buftype_exclude = {'help', 'nofile', 'terminal', 'prompt'}, } end} -- }}} use {'folke/zen-mode.nvim', cmd = {'ZenMode'}, -- {{{ module = {'zen-mode'}, 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', module = {'twilight'}, -- {{{ config = function() require('twilight').setup { context = 15, dimming = { alpha = 0.3, color = { 'Normal', '#ffffff' }, }, } end} -- }}} use {'goolord/alpha-nvim', cmd = 'Alpha', module = {'alpha'}, -- {{{ config = function() local MAX_WIDTH = 80 local alpha = require('alpha') local them = require('alpha.themes.theta') local button = function(...) -- {{{ local b = require('alpha.themes.dashboard').button(...) b.opts = vim.tbl_extend('force', b.opts, { hl = 'Normal', width = MAX_WIDTH, }) return b end -- }}} local fit_path = function(path, max_width) -- {{{ local Path = require('plenary.path') path = vim.fn.fnamemodify(path, ':.') if vim.fn.strdisplaywidth(path) > max_width then path = Path.new(path):shorten(1, {-2, -1}) end if vim.fn.strdisplaywidth(path) > max_width then path = '_ ' .. path:sub((vim.fn.strdisplaywidth(path) - max_width), -1) end return path end -- }}} local hr = function(margin, max_width, label, opts) -- {{{ max_width = max_width - (2*margin) label = label and (' ' .. label .. ' ') or '' opts = vim.tbl_extend('force', opts or {}, { position = 'center', hl = 'Comment' }) return { type = 'text', opts = opts, val = function() local label_len = vim.fn.strdisplaywidth(label) -- exit here if we're not showing a label if label_len == 0 then return string.rep(' ', margin) .. string.rep('─', max_width) .. string.rep(' ', margin) end if label_len > max_width then return error('overfull box: ' .. label) end max_width = max_width - label_len return string.rep(' ', margin) .. string.rep('─', max_width/2) .. label .. string.rep('─', max_width/2) .. string.rep(' ', margin) end, } end -- }}} local fortune = function(margin, max_width) -- {{{ max_width = max_width - (margin*2) local Job = require('plenary.job') local ok, j = pcall(Job.new, Job, { command = 'sh', args = {'-c', 'fortune ' .. vim.env.HOME..'/devel/projects/zig/fortune/fortunes' .. ' | fmt -w ' .. max_width}, enable_recording = true, }) if not ok then return {} end local lines, exit_code = j:sync() if not exit_code == 0 then return {} end local val = {} for i = 1, #lines do if vim.fn.strdisplaywidth(lines[i]) > max_width then return error('overful box: ' .. lines[i]) end table.insert(val, (string.rep(' ', margin) .. lines[i] .. string.rep(' ', margin))) end if vim.trim(val[#val]) == '' then table.remove(val, #val) end return { type = 'text', val = val, opts = { position = 'center', hl = 'AlphaFortune', }, } end -- }}} local mru = function(max_width) -- {{{ return { type = 'group', val = function() local items = {} -- initialize the oldfiles table local oldfiles = {} local cwd = vim.loop.cwd() for _, v in pairs(vim.v.oldfiles) do if #oldfiles == 10 then break end if vim.startswith(v, cwd) and (vim.fn.filereadable(v) == 1) then table.insert(oldfiles, v) end end -- exit early if there's nothing to show if not oldfiles or #oldfiles == 0 then return {} end table.insert(items, hr(0, max_width, 'MRU: ' .. fit_path(cwd, max_width))) table.insert(items, { type = 'padding', val = 1 }) for i, fn in pairs(oldfiles) do table.insert(items, button( tostring(i-1), -- keybind is fit_path(fn, max_width), ":edit " .. fn .. " ")) end return items end, opts = { position = 'center', }, } end -- }}} local buffers = function(max_width) -- {{{ return { type = 'group', val = function() local items = {} -- get listed buffers local bufnrs = vim.tbl_filter(function(bufnr) if 1 ~= vim.fn.buflisted(bufnr) then return false end return true end, vim.api.nvim_list_bufs()) --sort by last_used table.sort(bufnrs, function(a, b) return vim.fn.getbufinfo(a)[1].lastused > vim.fn.getbufinfo(b)[1].lastused end) -- exit early if there's nothing to show if not bufnrs or #bufnrs == 0 then return {} end table.insert(items, {type = 'padding', val = 1}) table.insert(items, hr(0, max_width, 'Buffers')) table.insert(items, {type = 'padding', val = 1}) for _, bufnr in ipairs(bufnrs) do local bufpath = require('plenary.path').new(vim.fn.getbufinfo(bufnr)[1].name):shorten(1, {-2, -1}) table.insert(items, button('b'..bufnr, bufpath, ':b'..bufnr..'')) end return items end, opts = { position = 'center', }, } end -- }}} them.config.layout = { -- {{{ {type = 'padding', val = 2}, require('alpha.themes.dashboard').section.header, {type = 'padding', val = 1}, fortune(5, MAX_WIDTH), {type = 'padding', val = 1}, hr(0, MAX_WIDTH), {type = 'padding', val = 1}, {type = 'group', val = { -- buttons {{{ button('e', '󰈔 new', [[ene startinsert]]), button('r', '󰈸 live grep', [[lua require('misc').live_grep()]]), button('f', '󰝰 find files', [[lua require('misc').find_files()]]), button('m', '󰥔 mru', [[lua require('telescope.builtin').oldfiles()]]), -- button('o', '󰃶 orgmode', [[lua require('packer').loader('orgmode.nvim'); require('orgmode').action('agenda.prompt')]]), button('T', '󰃶 todos', [[lua require('telescope._extensions.todo-comments').exports.todo {cwd=vim.env.ZK_NOTEBOOK_DIR}]]), button('u', '󰚰 update plugins', [[lua require('packer').sync()]]), button('v', '󰂓 edit config', [[lua require('telescope.builtin').find_files {search_dirs={vim.env.HOME..'/.vim/'}}]]), button('M', '󰇮 mail', [[K2]]), }}, -- }}} {type = 'padding', val = 1}, mru(MAX_WIDTH), buffers(MAX_WIDTH), } -- }}} alpha.setup(them.config) do local group = vim.api.nvim_create_augroup('AlphaIndent', { clear = true }) vim.api.nvim_create_autocmd('FileType', { pattern = 'alpha', command = [[IndentBlanklineDisable]], group = group, }) end vim.keymap.set('n', 'a', function() vim.cmd [[Alpha]] end) wk_register { ['a'] = {'alpha'} } end} -- }}} use {'ruifm/gitlinker.nvim', -- {{{ requires = {'nvim-lua/plenary.nvim'}, config = function() require('gitlinker').setup { opts = { action_callback = require('gitlinker.actions').copy_to_clipboard, }, } wk_register { ['g'] = { name = '+Git', y = {'gitlinker'} } } 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 vim.keymap.set('n', 'gm', function() vim.cmd [[GitMessenger]] end) wk_register { ['g'] = { name = '+Git', m = {'git-messenger'} } } end} -- }}} -- restore last cursor position (and handle many edge cases) use {'farmergreg/vim-lastplace'} use {'folke/todo-comments.nvim', module = {'telescope._extensions.todo-comments'}, cmd = {'TodoTelescope'}, -- {{{ config = function() require('todo-comments').setup {} -- vim.keymap.set('n', ';t', function() vim.cmd [[TodoTelescope]] end) -- wk_register { [';'] = { name = '+Telescope', t = {'todo-comments'} } } end} -- }}} -- spelling related stuff use {'lewis6991/spellsitter.nvim', disable = true, -- {{{ config = function() require('spellsitter').setup { enable = true, -- spellchecker = 'ffi' } end} -- }}} -- TODO: experimental section use {'tjdevries/sg.nvim', disable = true, -- {{{ requires = {'nvim-lua/plenary.nvim'}, config = function() end} -- }}} -- NOTE: local/personal stuff use {'~/devel/projects/k2', rtp = 'nvim', config = function() require('k2').setup() end} -- use {'https://git.sr.ht/~robertgzr/karafuru', rtp = 'vim', use {'~/devel/projects/karafuru', rtp = 'vim', disable = false, run = 'make colorscheme', config = function() vim.cmd [[colorscheme karafuru]] end} end, config = { compile_path = compilepath, git = { subcommands = { update = 'pull --ff-only --progress --rebase=true', } }, profile = { enable = false, threshold = 1, } }}) -- run sync() if compilepath doesn't exist (this usually means first start) if vim.fn.empty(vim.fn.glob(compilepath)) > 0 then require('packer').sync() end