From 6a1810f4dfe4ac22dfbaf2b98fb7618fd76eb761 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Wed, 30 Apr 2025 13:14:22 +0200 Subject: vim: misc updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- .vim/lua/internal/plugins/aerial.lua | 3 +- .vim/lua/internal/plugins/gentoo.lua | 6 +- .vim/lua/internal/plugins/git.lua | 7 ++ .vim/lua/internal/plugins/icons.lua | 1 + .vim/lua/internal/plugins/lsp.lua | 30 ++++--- .vim/lua/internal/plugins/markdown.lua | 1 + .vim/lua/internal/plugins/mini.lua | 37 ++++----- .vim/lua/internal/plugins/todo.lua | 6 +- .vim/lua/internal/plugins/whichkey.lua | 1 + .vim/lua/internal/plugins/writing.lua | 142 ++++++++++++++++----------------- .vim/lua/internal/plugins/zk.lua | 27 ++----- .vim/lua/internal/zk.lua | 73 +++++++++++++++++ .vim/plugin/auto.lua | 10 +-- .vim/plugin/diagnostics.lua | 34 ++++---- .vim/plugin/keymaps.lua | 23 +++++- .vim/plugin/options.lua | 14 +++- .vim/plugin/syncbg.lua | 90 +++++++++++++-------- .vim/plugin/termopen.lua | 21 ++++- 18 files changed, 331 insertions(+), 195 deletions(-) create mode 120000 .vim/lua/internal/plugins/markdown.lua create mode 100644 .vim/lua/internal/zk.lua (limited to '.vim') diff --git a/.vim/lua/internal/plugins/aerial.lua b/.vim/lua/internal/plugins/aerial.lua index a5fb4b3..0094e17 100644 --- a/.vim/lua/internal/plugins/aerial.lua +++ b/.vim/lua/internal/plugins/aerial.lua @@ -1,13 +1,14 @@ return { { 'stevearc/aerial.nvim', - opts = {}, dependencies = { 'nvim-treesitter/nvim-treesitter', 'echasnovski/mini.icons', }, + opts = {}, keys = { { 'b', 'AerialToggle' }, + { '', 'AerialToggle' }, }, }, } diff --git a/.vim/lua/internal/plugins/gentoo.lua b/.vim/lua/internal/plugins/gentoo.lua index 142374c..2fc8684 100644 --- a/.vim/lua/internal/plugins/gentoo.lua +++ b/.vim/lua/internal/plugins/gentoo.lua @@ -1,11 +1,11 @@ return { { 'gentoo/gentoo-syntax', - lazy = false, - config = function() + ft = { 'ebuild' }, + init = function() vim.api.nvim_create_autocmd('LspAttach', { callback = function(args) - if vim.bo.filetype == 'ebuild' then + if vim.opt.filetype == 'ebuild' then vim.lsp.stop_client(vim.lsp.get_clients({ bufnr = args.bufnr })) end end, diff --git a/.vim/lua/internal/plugins/git.lua b/.vim/lua/internal/plugins/git.lua index e436660..056cc14 100644 --- a/.vim/lua/internal/plugins/git.lua +++ b/.vim/lua/internal/plugins/git.lua @@ -94,6 +94,13 @@ return { vim.api.nvim_set_hl(0, 'GitGraphBranchName', { fg = 'NvimLightYellow' }) vim.api.nvim_set_hl(0, 'GitGraphBranchTag', { fg = 'NvimLightYellow' }) vim.api.nvim_set_hl(0, 'GitGraphBranchMsg', { link = 'Normal' }) + -- vim.api.nvim_create_autocmd('FileType', { + -- pattern = { 'gitgraph' }, + -- callback = function() + -- vim.keymap.set('n', 'q', 'bdel!', { silent = true, buffer = 0 }) + -- end, + -- group = vim.api.nvim_create_augroup('GitGraph'), + -- }) end), keys = { { diff --git a/.vim/lua/internal/plugins/icons.lua b/.vim/lua/internal/plugins/icons.lua index 3d503dc..9a597ab 100644 --- a/.vim/lua/internal/plugins/icons.lua +++ b/.vim/lua/internal/plugins/icons.lua @@ -3,6 +3,7 @@ return { 'echasnovski/mini.icons', version = false, events = { 'VeryLazy' }, + -- opts = {}, config = function(_, opts) require('mini.icons').setup(opts) ---@diagnostic disable-next-line: undefined-global diff --git a/.vim/lua/internal/plugins/lsp.lua b/.vim/lua/internal/plugins/lsp.lua index e2a5866..7175a89 100644 --- a/.vim/lua/internal/plugins/lsp.lua +++ b/.vim/lua/internal/plugins/lsp.lua @@ -112,6 +112,9 @@ return { rust_analyzer = { settings = { ['rust-analyzer'] = { + diagnostics = { + enable = true, + }, checkOnSave = { command = { 'cargo', 'clippy' }, }, @@ -129,8 +132,8 @@ return { zls = { cmd = { 'zls', - '--enable-debug-log', - '--enable-message-tracing', + '--log-level', + 'warn', }, }, bashls = {}, @@ -221,7 +224,7 @@ return { { 'nvimtools/none-ls.nvim', dependencies = { 'nvim-lua/plenary.nvim' }, - event = { 'VeryLazy' }, + event = 'VeryLazy', config = function() local nls = require('null-ls') nls.setup({ @@ -237,7 +240,7 @@ return { -- nls.builtins.diagnostics.cppcheck, -- nls.builtins.diagnostics.gccdiag, nls.builtins.diagnostics.golangci_lint, - nls.builtins.diagnostics.hadolint, + -- nls.builtins.diagnostics.hadolint, -- nls.builtins.diagnostics.pylint, -- nls.builtins.diagnostics.selene, -- nls.builtins.diagnostics.semgrep, @@ -252,11 +255,13 @@ return { -- diagnostics { + enabled = true, 'rachartier/tiny-inline-diagnostic.nvim', - event = 'VeryLazy', + lazy = false, opts = { + preset = 'nonerdfont', signs = { - left = ' ', + left = '', right = '', diag = '', arrow = '◂ ', @@ -264,13 +269,20 @@ return { }, options = { throttle = 0, - show_source = true, + show_source = { + enabled = true, + }, + multilines = { + enabled = false, + always_show = false, + }, + -- break_line = { enabled = true }, + show_all_diags_on_cursorline = true, }, }, config = function(_, opts) - vim.diagnostic.config({ virtual_text = false }) require('tiny-inline-diagnostic').setup(opts) - if vim.opt.background:get() == 'light' then + if vim.o.background == 'light' then require('tiny-inline-diagnostic').change({}, { mixing_color = '#aaaaaa' }) end end, diff --git a/.vim/lua/internal/plugins/markdown.lua b/.vim/lua/internal/plugins/markdown.lua new file mode 120000 index 0000000..5b578d5 --- /dev/null +++ b/.vim/lua/internal/plugins/markdown.lua @@ -0,0 +1 @@ +writing.lua \ No newline at end of file diff --git a/.vim/lua/internal/plugins/mini.lua b/.vim/lua/internal/plugins/mini.lua index 1886766..fb4c9a6 100644 --- a/.vim/lua/internal/plugins/mini.lua +++ b/.vim/lua/internal/plugins/mini.lua @@ -2,34 +2,25 @@ return { { 'echasnovski/mini.align', version = false, + lazy = false, + opts = {}, + }, + { + 'echasnovski/mini.ai', + version = false, + lazy = false, opts = {}, - keys = { - { mode = 'n', 'ga' }, - { mode = 'n', 'gA' }, - { mode = 'v', 'ga' }, - { mode = 'v', 'gA' }, - { - mode = 'v', - '', - function() - vim.cmd([[silent! echohl ErrorMsg | echo "use ga/gA" | echohl None]]) - end, - }, - }, }, { 'echasnovski/mini.surround', + version = false, lazy = false, + opts = {}, + }, + { + 'echasnovski/mini.operators', version = false, - opts = { - mappings = { - delete = 'ds', - replace = 'cs', - }, - }, - keys = { - { mode = 'n', 'cs' }, - { mode = 'n', 'ds' }, - }, + lazy = false, + opts = {}, }, } diff --git a/.vim/lua/internal/plugins/todo.lua b/.vim/lua/internal/plugins/todo.lua index 0c0ce0f..d99458e 100644 --- a/.vim/lua/internal/plugins/todo.lua +++ b/.vim/lua/internal/plugins/todo.lua @@ -17,10 +17,12 @@ return { }, highlight = { keyword = 'bg', - pattern = [[<(KEYWORDS)(|\(.+\))(:|)]], + -- pattern = [[<(KEYWORDS)(|\(.+\))(:|)]], + pattern = [[<(KEYWORDS)(|\(.+\)):]], }, search = { - pattern = [[\b(KEYWORDS)(|\(.+\))(:|)]], + -- pattern = [[\b(KEYWORDS)(|\(.+\))(:|)]], + pattern = [[\b(KEYWORDS)(|\(.+\)):]], }, }, keys = { diff --git a/.vim/lua/internal/plugins/whichkey.lua b/.vim/lua/internal/plugins/whichkey.lua index 3c9e802..dc21eda 100644 --- a/.vim/lua/internal/plugins/whichkey.lua +++ b/.vim/lua/internal/plugins/whichkey.lua @@ -3,6 +3,7 @@ return { 'folke/which-key.nvim', event = 'VeryLazy', opts = { + sort = { 'alphanum' }, icons = { separator = '→ ', group = '🞱 ' }, }, }, diff --git a/.vim/lua/internal/plugins/writing.lua b/.vim/lua/internal/plugins/writing.lua index 4792697..8f207b7 100644 --- a/.vim/lua/internal/plugins/writing.lua +++ b/.vim/lua/internal/plugins/writing.lua @@ -1,76 +1,21 @@ return { { - 'folke/zen-mode.nvim', - cmd = { 'ZenMode' }, - opts = { - window = { - -- width = 0.9, - -- height = 0.9, - options = { - cursorline = true, - }, - }, - plugins = { - options = { - number = false, - ruler = false, - showcmd = false, - }, - gitsigns = { enabled = false }, - twilight = { enabled = true }, - }, - on_open = function() - vim.diagnostic.enable(false) - end, - on_close = function() - vim.diagnostic.enable(true) - end, - }, - -- init = function() - -- vim.api.nvim_create_autocmd({ 'BufWinEnter', 'BufWinLeave' }, { - -- pattern = { '*.md' }, - -- command = [[ZenMode]], - -- }) - -- end, - dependencies = { - { - 'folke/twilight.nvim', - opts = { - context = 24, - dimming = { - alpha = 0.5, - color = { 'Normal', '#ffffff' }, - }, - }, - }, - }, - }, - { + -- DESC: handy markdown commands 'tadmccorkle/markdown.nvim', ft = { 'markdown' }, opts = { mappings = false, + on_attach = function(buf) + vim.keymap.set('n', 'nl', 'MDListItemBelow', { buffer = buf }) + vim.keymap.set('n', 'nl', 'MDListItemAbove', { buffer = buf }) + vim.keymap.set('n', '', 'MDTaskToggle', { buffer = buf }) + vim.keymap.set('x', '', 'MDTaskToggle', { buffer = buf }) + vim.keymap.set('x', '', 'gv(markdown_add_link_visual)', { buffer = buf }) + end, }, - config = function(_, opts) - require('markdown').setup(opts) - - local set = vim.keymap.set - set('n', '[[', [[(markdown_go_prev_heading)]], { desc = 'md: previous heading' }) - set('n', ']]', [[(markdown_go_next_heading)]], { desc = 'md: next heading' }) - set('n', '', [[:MDTaskToggle]], { desc = 'md: toggle task' }) - set('x', '', [[gv(markdown_add_link_visual)]], { desc = 'md: make link' }) - local toggle_emph = function(key) - return [[gvlua require('markdown.inline').toggle_emphasis_visual(']] - .. key - .. [[')]] - end - set('x', '', toggle_emph('b'), { desc = 'md: make bold' }) - set('x', '', toggle_emph('i'), { desc = 'md: make italic' }) - set('x', '', toggle_emph('s'), { desc = 'md: make strikethrough' }) - set('x', '', toggle_emph('c'), { desc = 'md: make code' }) - end, }, { + -- DESC: pretty print markdown 'MeanderingProgrammer/markdown.nvim', name = 'render-markdown', -- needed if used together with markdown.nvim above main = 'render-markdown', @@ -80,15 +25,18 @@ return { }, ft = { 'markdown' }, opts = { + completions = { blink = { enabled = true } }, + sign = { enabled = false }, heading = { + width = 'block', -- icons = { '❶ ', '❷ ', '❸ ', '❹ ', '❺ ', '❻ ' }, icons = { - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', + '▒ ', + '▒▒ ', + '▒▒▒ ', + '▒▒▒▒ ', + '▒▒▒▒▒ ', + '▒▒▒▒▒▒ ', }, signs = { 'ⅰ', 'ⅱ', 'ⅲ', 'ⅳ', 'ⅴ', 'ⅵ' }, }, @@ -104,8 +52,8 @@ return { }, }, init = vim.schedule_wrap(function() - vim.api.nvim_set_hl(0, 'RenderMarkdownH1Bg', { bg = 'NvimDarkBlue' }) - vim.api.nvim_set_hl(0, 'RenderMarkdownH1Fg', { fg = 'NvimLightBlue' }) + vim.api.nvim_set_hl(0, 'RenderMarkdownH1Bg', { bg = 'NvimDarkCyan' }) + vim.api.nvim_set_hl(0, 'RenderMarkdownH1Fg', { fg = 'NvimLightCyan' }) vim.api.nvim_set_hl(0, 'RenderMarkdownH2Bg', { bg = 'NvimDarkMagenta' }) vim.api.nvim_set_hl(0, 'RenderMarkdownH2Fg', { fg = 'NvimLightMagenta' }) @@ -113,11 +61,57 @@ return { vim.api.nvim_set_hl(0, 'RenderMarkdownH3Bg', { bg = 'NvimDarkYellow' }) vim.api.nvim_set_hl(0, 'RenderMarkdownH3Fg', { fg = 'NvimLightYellow' }) - vim.api.nvim_set_hl(0, 'RenderMarkdownH4Bg', { bg = 'NvimDarkCyan' }) - vim.api.nvim_set_hl(0, 'RenderMarkdownH4Fg', { fg = 'NvimLightCyan' }) + vim.api.nvim_set_hl(0, 'RenderMarkdownH4Bg', { bg = 'NvimDarkBlue' }) + vim.api.nvim_set_hl(0, 'RenderMarkdownH4Fg', { fg = 'NvimLightBlue' }) vim.api.nvim_set_hl(0, 'RenderMarkdownH6Bg', { bg = 'NvimDarkRed' }) vim.api.nvim_set_hl(0, 'RenderMarkdownH6Fg', { fg = 'NvimLightRed' }) + + vim.api.nvim_set_hl(0, '@markup.bold', { link = 'markdownBold' }) + vim.api.nvim_set_hl(0, '@markup.italic', { link = 'markdownItalic' }) end), }, + { + 'folke/zen-mode.nvim', + cmd = { 'ZenMode' }, + opts = { + window = { + height = 1, + options = { + number = false, + cursorline = false, + }, + }, + plugins = { + options = { + ruler = false, + showcmd = false, + laststatus = 0, + }, + gitsigns = { enabled = false }, + twilight = { enabled = true }, + }, + on_open = function() + vim.diagnostic.enable(false) + require('render-markdown').buf_disable() + end, + on_close = function() + vim.diagnostic.enable(true) + require('render-markdown').buf_enable() + end, + }, + dependencies = { + { + 'folke/twilight.nvim', + cmd = { 'Twilight' }, + opts = { + context = 24, + dimming = { + alpha = 0.3, + color = { 'Normal', '#ffffff' }, + }, + }, + }, + }, + }, } diff --git a/.vim/lua/internal/plugins/zk.lua b/.vim/lua/internal/plugins/zk.lua index 76cbcb3..da108b0 100644 --- a/.vim/lua/internal/plugins/zk.lua +++ b/.vim/lua/internal/plugins/zk.lua @@ -4,32 +4,19 @@ return { 'zk-org/zk-nvim', main = 'zk', opts = { - picker = 'telescope', + picker = 'select', }, keys = { -- these will work everywhere - { ';zc', ':ZkNew ' }, - { ';zz', 'ZkNotes {sort={"modified"}}' }, - { ';zl', 'ZkLinks' }, - { ';zb', 'ZkBacklinks' }, - { ';zt', 'ZkTags' }, + { ';zc', ':ZkNew ', desc = 'zk: new note' }, + { ';zz', 'ZkNotes {sort={"modified"}}', desc = 'zk: list notes' }, + { ';zl', 'ZkLinks', desc = 'zk: list links' }, + { ';zb', 'ZkBacklinks', desc = 'zk: list backlinks' }, + { ';zt', 'ZkTags', desc = 'zk: list tags' }, -- { ';zj', 'ZkNotes { dir = "500_journals" }' }, }, init = function() - if not vim.env.ZK_NOTEBOOK_DIR then - return - end - vim.api.nvim_create_autocmd({ 'BufEnter' }, { - pattern = vim.env.ZK_NOTEBOOK_DIR .. '/*', - callback = function() - local o = { remap = true, silent = false, buffer = true } - -- these will only work in a zettel - vim.keymap.set('n', '-', ':call feedkeys(";zz")', o) - vim.keymap.set('n', '', 'lua vim.lsp.buf.definition()', o) - end, - group = vim.api.nvim_create_augroup('zk-binds', { clear = true }), - once = true, - }) + require('internal.zk') end, }, } diff --git a/.vim/lua/internal/zk.lua b/.vim/lua/internal/zk.lua new file mode 100644 index 0000000..4631e13 --- /dev/null +++ b/.vim/lua/internal/zk.lua @@ -0,0 +1,73 @@ +if not vim.env.ZK_NOTEBOOK_DIR then + vim.notify('Missing ZK_NOTEBOOK_DIR!', vim.log.levels.WARN) + return +end + +local api = require('zk.api') +local util = require('zk.util') + +local function insert_new_note() + -- TODO: catch error an delete note + api.new(nil, nil, function(err1, res1) + if not res1 then + error(err1) + end + + -- update index to include the new note + api.index(nil, nil, nil) + + local path = res1.path + local filename = vim.fs.basename(path) + local location = util.get_lsp_location_from_caret() + + api.link(filename, location, nil, {}, function(err2, res2) + if not res2 then + error(err2) + end + + -- open split + local buf = vim.api.nvim_create_buf(true, false) + vim.api.nvim_buf_set_name(buf, filename) + vim.api.nvim_buf_call(buf, function() + vim.cmd.edit(path) + end) + local win = vim.api.nvim_open_win(buf, false, { + split = 'below', + win = 0, + }) + -- move to split + vim.api.nvim_set_current_win(win) + vim.api.nvim_win_set_cursor(win, { -1, 0 }) + end) + end) +end + +local function on_attach() + if not vim.env.ZK_NOTEBOOK_DIR then + vim.notify('Missing ZK_NOTEBOOK_DIR!', vim.log.levels.WARN) + return + end + + -- enable virtual_text diagnostics to show link titles + vim.diagnostic.config({ virtual_text = true }) + + local opts = { remap = true, silent = false, buffer = true } + + -- -- list zettelkasten + -- vim.keymap.set('n', '-', ':call feedkeys(";zz")', opts) + + -- follow links + -- TODO: should this also work on outgoing links? + vim.keymap.set('n', '', 'lua vim.lsp.buf.definition()', opts) + + -- insert ref to new note and open note in split + vim.keymap.set({ 'n', 'i' }, ';zi', insert_new_note, opts) +end + +-- setup binds to run when entering zettel buffers +vim.api.nvim_create_autocmd({ 'BufEnter' }, { + pattern = vim.env.ZK_NOTEBOOK_DIR .. '/*.md', + callback = on_attach, + group = vim.api.nvim_create_augroup('zk-on-attach', { clear = true }), + once = true, +}) diff --git a/.vim/plugin/auto.lua b/.vim/plugin/auto.lua index ab4e159..98f0ef1 100644 --- a/.vim/plugin/auto.lua +++ b/.vim/plugin/auto.lua @@ -30,9 +30,9 @@ do end, group = group, }) - autocmd('TermClose', { - pattern = { 'term://*' }, - command = [[ if !v:event.status | exe 'bdelete! '..expand('') | endif ]], - group = group, - }) + -- autocmd('TermClose', { + -- pattern = { 'term://*' }, + -- command = [[ if !v:event.status | exe 'bdelete! '..expand('') | endif ]], + -- group = group, + -- }) end diff --git a/.vim/plugin/diagnostics.lua b/.vim/plugin/diagnostics.lua index 70deec3..93ee621 100644 --- a/.vim/plugin/diagnostics.lua +++ b/.vim/plugin/diagnostics.lua @@ -7,7 +7,7 @@ vim.diagnostic.config({ [vim.diagnostic.severity.HINT] = '🞶', }, linehl = { - [vim.diagnostic.severity.ERROR] = 'Search', + -- [vim.diagnostic.severity.ERROR] = 'Search', -- [vim.diagnostic.severity.WARN] = '', -- [vim.diagnostic.severity.INFO] = '', -- [vim.diagnostic.severity.HINT] = '', @@ -19,16 +19,13 @@ vim.diagnostic.config({ [vim.diagnostic.severity.HINT] = 'DiagnosticSignHint', }, }, + severity_sort = true, underline = { - severity = { min = vim.diagnostic.severity.HINT }, - }, - float = { - severity = { min = vim.diagnostic.severity.HINT }, - }, - virtual_text = { - severity = { min = vim.diagnostic.severity.HINT }, + severity = { min = vim.diagnostic.severity.WARN }, }, - severity_sort = true, + float = false, + virtual_text = false, + virtual_lines = false, }) local commonhl = { undercurl = true, force = true } @@ -38,22 +35,29 @@ vim.api.nvim_set_hl(0, 'DiagnosticUnderlineInfo', commonhl) vim.api.nvim_set_hl(0, 'DiagnosticUnderlineHint', commonhl) vim.keymap.set('n', '[d', function() - vim.diagnostic.goto_next() + vim.diagnostic.jump({ count = 1, float = true }) end, { desc = 'diagnostic: next' }) + vim.keymap.set('n', ']d', function() - vim.diagnostic.goto_prev() + vim.diagnostic.jump({ count = -1, float = true }) end, { desc = 'diagnostic: prev' }) + vim.keymap.set('n', 'DD', vim.diagnostic.open_float, { desc = 'diagnostic: current line' }) + vim.keymap.set('n', 'td', function() - if not _G.diagnostic_hidden then + -- NOTE: this can be used to switch between multiple sets of diagnostics display + -- currently it only toggles virtual_text + local visible = vim.diagnostic.config().virtual_text + + if visible then -- vim.diagnostic.hide(nil, 0) vim.diagnostic.config({ virtual_text = false }) else -- vim.diagnostic.show(nil, 0) vim.diagnostic.config({ virtual_text = true }) end - _G.diagnostic_hidden = not _G.diagnostic_hidden -end, { desc = 'diagnostic: toggle' }) +end, { desc = 'diagnostic: toggle visibility' }) + vim.keymap.set('n', 'tD', function() vim.diagnostic.enable(not vim.diagnostic.is_enabled()) -end, { desc = 'diagnostic: toggle' }) +end, { desc = 'diagnostic: toggle all' }) diff --git a/.vim/plugin/keymaps.lua b/.vim/plugin/keymaps.lua index ff9fd57..f7cdf20 100644 --- a/.vim/plugin/keymaps.lua +++ b/.vim/plugin/keymaps.lua @@ -2,17 +2,25 @@ local set = vim.keymap.set set('n', 'gb', 'bnext', { desc = 'Next buffer' }) set('n', 'gB', 'bprevious', { desc = 'Prev buffer' }) +set( + 'n', + 'g', + 'lua vim.notify("Use C-o> and C-i>!", vim.log.levels.WARN)', + { desc = 'Last buffer' } +) set('n', ';yp', function() local payload = (vim.fn.expand('%:p') .. ':' .. vim.fn.line('.')) vim.fn.setreg('+', payload) vim.notify(payload) end, { desc = 'Yank current buffer path and line number' }) + set('n', ';yP', function() local payload = vim.fn.expand('%:p') vim.fn.setreg('+', payload) vim.notify(payload) end, { desc = 'Yank current buffer path' }) + set('n', ';yn', function() local payload = vim.fs.basename(vim.fn.expand('%:p')) vim.fn.setreg('+', payload) @@ -25,8 +33,17 @@ set('v', '<', '', '>gv', { desc = 'outdent' }) set('n', '', 'nohlsearch', { desc = 'Clear search highlights' }) -set('n', '', 'normal! za', { desc = 'Toggle fold under cursor' }) +-- set('n', '', 'normal! za', { desc = 'Toggle fold under cursor' }) set('n', '', 'normal! zA', { desc = 'Toggle fold under cursor (recursive)' }) -set('n', '', 'cnext', { desc = 'Next in quickfix' }) -set('n', '', 'cprev', { desc = 'Prev in quickfix' }) +set('n', '', 'cnext', { desc = 'Next in quickfix' }) +set('n', '', 'cprev', { desc = 'Prev in quickfix' }) + +set('n', '', '@:', { desc = 'Rerun last command' }) + +set( + 'n', + 'gx', + 'lua vim.ui.open(vim.fn.expand(""))', + { desc = 'Open file under cursor' } +) diff --git a/.vim/plugin/options.lua b/.vim/plugin/options.lua index a25a646..dba726a 100644 --- a/.vim/plugin/options.lua +++ b/.vim/plugin/options.lua @@ -10,7 +10,13 @@ opt.clipboard:prepend({ 'unnamedplus' }) opt.inccommand = 'split' -- show whitespace indicators -opt.listchars:append({ trail = '¬', tab = '> ' }) +opt.list = true +opt.listchars:append({ + trail = '¬', + tab = '> ', + -- space = '·', + lead = '·', +}) opt.showbreak = '↪ ' -- show indicator and wrap text at 80 chars @@ -25,3 +31,9 @@ opt.concealcursor = nil opt.foldmethod = 'expr' opt.foldexpr = 'v:lua.vim.treesitter.foldexpr()' opt.foldlevel = 99 + +-- https://fosstodon.org/@rockorager/114183888444195197 +opt.mousescroll = 'ver:1,hor:6' + +-- load local vim config (will as to allow it) +opt.exrc = true diff --git a/.vim/plugin/syncbg.lua b/.vim/plugin/syncbg.lua index d9243f0..c11bef6 100644 --- a/.vim/plugin/syncbg.lua +++ b/.vim/plugin/syncbg.lua @@ -1,53 +1,73 @@ --- this plugin registers two autocmds that trigger when openeing and closing vim, setting the +-- this plugin registers two autocmds that trigger when openeing and closing the editor, setting the -- background of the terminal to the color used by our colorscheme using CSI control codes. -local state = {} +local state = { enabled = false } --- get tty -local tty_handle = io.popen('tty') -if tty_handle == nil then +if not state.enabled then return end -local tty = tty_handle:read('*a') -tty_handle:close() -if tty:find('not a tty') then - error('not a tty') + +local set_bg = function(clear) + if not (state.tty and state.normal) then + return + end + if clear then + -- emit CSI to unset custom background + os.execute('printf "\\033]111\\007" > ' .. state.tty) + else + -- emit CSI to change terminal background to Normal.bg + os.execute( + 'printf "\\033]11;' .. string.format('#%06x', state.normal.bg) .. '\\007" > ' .. state.tty + ) + -- set colorscheme Normal.bg to NONE, making it transparent + vim.cmd([[hi Normal ctermbg=NONE guibg=NONE]]) + end end -state.tty = tty --- register update hook -vim.api.nvim_create_autocmd({ 'ColorScheme', 'UIEnter', 'VimResume' }, { - callback = function() - if state.tty == nil then +local discover = function() + if not state.tty then + -- get tty handle + local ok, tty_handle = pcall(io.popen, 'tty') + if (not ok) or tty_handle == nil then return end + local tty = tty_handle:read('*l') + tty_handle:close() + if tty:find('not a tty') then + return + end + state.tty = tty + end - if not state.normal then - -- get colorscheme Normal highlight - local normal = vim.api.nvim_get_hl(0, { name = 'Normal', create = false }) - if normal.bg == nil then - return - end - -- cache old value for use with VimResume - state.normal = normal + if not state.normal then + -- get colorscheme Normal highlight + local normal = vim.api.nvim_get_hl(0, { name = 'Normal', create = false }) + if normal.bg == nil then + return end + -- cache old value for use with VimResume + state.normal = normal + end - -- emit CSI to change terminal background to Normal.bg - os.execute( - 'printf "\\033]11;' .. string.format('#%06x', state.normal.bg) .. '\\007" > ' .. state.tty - ) + -- vim.notify('syncbg: ' .. vim.inspect(state), vim.log.levels.DEBUG) +end - -- set colorscheme Normal.bg to NONE, making it transparent - vim.cmd([[hi Normal ctermbg=NONE guibg=NONE]]) - end, +-- setup autogroup +local aug = vim.api.nvim_create_augroup('syncbg', { clear = true }) + +-- register update hook +vim.api.nvim_create_autocmd({ 'ColorScheme', 'UIEnter', 'VimResume' }, { + group = aug, + callback = vim.schedule_wrap(function() + discover() + set_bg(false) + end), }) -- register reset hook vim.api.nvim_create_autocmd({ 'UILeave' }, { - callback = function() - if state.tty == nil then - return - end - os.execute('printf "\\033]111\\007" > ' .. state.tty) - end, + group = aug, + callback = vim.schedule_wrap(function() + set_bg(true) + end), }) diff --git a/.vim/plugin/termopen.lua b/.vim/plugin/termopen.lua index 68b9d8d..951857f 100644 --- a/.vim/plugin/termopen.lua +++ b/.vim/plugin/termopen.lua @@ -25,11 +25,14 @@ local function termopen(opts) vim.api.nvim_set_current_win(win) -- spawn the command + if #opts.cmd == 0 then + opts.cmd = { vim.env.SHELL } + end vim.fn.termopen(opts.cmd, { on_exit = function() - if vim.api.nvim_win_is_valid(win) then - vim.api.nvim_win_close(win, true) - end + -- if vim.api.nvim_win_is_valid(win) then + -- vim.api.nvim_win_close(win, true) + -- end end, }) @@ -49,7 +52,13 @@ end, { nargs = '*' }) -- helper to spawn &makeprg vim.api.nvim_create_user_command('Make', function(a) - local cmd = vim.split(vim.o.makeprg, ' ') + if vim.opt_local.makeprg == nil then + vim.ui.input({ prompt = 'Enter makeprg: ' }, function(input) + vim.opt_local.makeprg = input + end) + end + + local cmd = vim.split(vim.opt_local.makeprg:get(), ' ') cmd = vim.tbl_map(function(p) p, _ = string.gsub(p, [[%$%*]], a.args) p, _ = vim.fn.expand(p) @@ -57,3 +66,7 @@ vim.api.nvim_create_user_command('Make', function(a) end, cmd) termopen({ cmd = cmd }) end, { nargs = '*' }) + +-- setup keymappings +vim.keymap.set('n', 'm', 'Make', { desc = 'Run :Make' }) +vim.keymap.set('n', 't', 'Termopen', { desc = 'Run :Termopen' }) -- cgit 1.4.1