diff options
| author | Robert Günzler <r@gnzler.io> | 2025-04-30 13:14:22 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2025-04-30 13:14:22 +0200 |
| commit | 6a1810f4dfe4ac22dfbaf2b98fb7618fd76eb761 (patch) | |
| tree | d9cc1046e3305476e2eea284fbdafde049cf3e10 /.vim/plugin | |
| parent | 59bdb9bc3f7b06b886a24def842f62f350f1411b (diff) | |
vim: misc updates
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '')
| -rw-r--r-- | .vim/plugin/auto.lua | 10 | ||||
| -rw-r--r-- | .vim/plugin/diagnostics.lua | 34 | ||||
| -rw-r--r-- | .vim/plugin/keymaps.lua | 23 | ||||
| -rw-r--r-- | .vim/plugin/options.lua | 14 | ||||
| -rw-r--r-- | .vim/plugin/syncbg.lua | 90 | ||||
| -rw-r--r-- | .vim/plugin/termopen.lua | 21 |
6 files changed, 129 insertions, 63 deletions
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('<abuf>') | endif ]], - group = group, - }) + -- autocmd('TermClose', { + -- pattern = { 'term://*' }, + -- command = [[ if !v:event.status | exe 'bdelete! '..expand('<abuf>') | 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', '<leader>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', '<leader>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', '<cmd>bnext<cr>', { desc = 'Next buffer' }) set('n', 'gB', '<cmd>bprevious<cr>', { desc = 'Prev buffer' }) +set( + 'n', + 'g<bs>', + '<cmd>lua vim.notify("Use <lt>C-o> and <lt>C-i>!", vim.log.levels.WARN)<cr>', + { 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 = 'indent' }) set('v', '>', '>gv', { desc = 'outdent' }) set('n', '<s-esc>', '<cmd>nohlsearch<cr>', { desc = 'Clear search highlights' }) -set('n', '<tab>', '<cmd>normal! za<cr>', { desc = 'Toggle fold under cursor' }) +-- set('n', '<tab>', '<cmd>normal! za<cr>', { desc = 'Toggle fold under cursor' }) set('n', '<s-tab>', '<cmd>normal! zA<cr>', { desc = 'Toggle fold under cursor (recursive)' }) -set('n', '<A-j>', '<cmd>cnext<cr>', { desc = 'Next in quickfix' }) -set('n', '<A-k>', '<cmd>cprev<cr>', { desc = 'Prev in quickfix' }) +set('n', '<a-j>', '<cmd>cnext<cr>', { desc = 'Next in quickfix' }) +set('n', '<a-k>', '<cmd>cprev<cr>', { desc = 'Prev in quickfix' }) + +set('n', '<leader><bs>', '@:', { desc = 'Rerun last command' }) + +set( + 'n', + 'gx', + '<cmd>lua vim.ui.open(vim.fn.expand("<cfile>"))<cr>', + { 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', '<leader><leader>m', '<cmd>Make<cr>', { desc = 'Run :Make' }) +vim.keymap.set('n', '<leader><leader>t', '<cmd>Termopen<cr>', { desc = 'Run :Termopen' }) |