diff options
Diffstat (limited to '.vim/init.lua')
| -rw-r--r-- | .vim/init.lua | 294 |
1 files changed, 177 insertions, 117 deletions
diff --git a/.vim/init.lua b/.vim/init.lua index 3b5bf52..99c2516 100644 --- a/.vim/init.lua +++ b/.vim/init.lua @@ -7,21 +7,21 @@ g.maplocalleader = '\\' local opt = vim.opt opt.backspace = 'indent,eol,start' -opt.clipboard:prepend { 'unnamedplus' } +opt.clipboard:prepend({ 'unnamedplus' }) opt.cmdheight = 1 opt.colorcolumn = '+1' -opt.formatoptions:remove 't' +opt.formatoptions:remove('t') -- opt.complete = '.,w,b,u' -opt.completeopt = {'menu','menuone','noinsert'} +opt.completeopt = { 'menu', 'menuone', 'noinsert' } opt.concealcursor = '' opt.conceallevel = 2 opt.cursorline = true opt.expandtab = false opt.exrc = true -opt.fillchars:append { +opt.fillchars:append({ fold = '─', horiz = '─', -} +}) opt.foldenable = true opt.foldmethod = 'expr' opt.foldexpr = 'nvim_treesitter#foldexpr()' @@ -36,11 +36,11 @@ opt.incsearch = true opt.laststatus = 3 opt.lazyredraw = true opt.list = true -opt.listchars:append { +opt.listchars:append({ trail = '¬', tab = '> ', -- space/lead = '⋅', -} +}) opt.mouse = 'a' opt.number = true opt.relativenumber = false @@ -49,7 +49,7 @@ opt.redrawtime = 1500 opt.ruler = true opt.scrolloff = 3 opt.shiftround = true -opt.shortmess:append { c = true } +opt.shortmess:append({ c = true }) opt.breakindent = true opt.breakindentopt = { shift = 2 } opt.showbreak = '↪ ' @@ -59,7 +59,7 @@ opt.showmatch = true opt.signcolumn = 'auto' opt.smartcase = true opt.spell = false -opt.spelllang = {'en_gb'} +opt.spelllang = { 'en_gb' } -- opt.splitkeep = 'topline' opt.termguicolors = true opt.textwidth = 80 @@ -69,8 +69,8 @@ opt.ttimeoutlen = 10 opt.undolevels = 1000 opt.updatetime = 200 opt.wrap = true -opt.path = {'', '.', '.;$HOME', '/usr/include/**'} -opt.isfname:remove ':' +opt.path = { '', '.', '.;$HOME', '/usr/include/**' } +opt.isfname:remove(':') opt.guicursor = { -- block shape in normal/visual/command 'n-c-v:block', @@ -80,7 +80,7 @@ opt.guicursor = { 'r-cr-o:hor10', -- 'sm:block-blinkwait175-blinkoff150-blinkon175', - -- 'a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor', + -- 'a:blinkwait700-blinkoff400-blinkon250-Cgrsor/lCursor', -- 'a:blinkon0-Cursor', } @@ -99,72 +99,84 @@ g.undodir = undodir opt.undofile = true -- }}} --- swap between newpaper and karafuru -g.night_and_day = 'night' - g.do_filetype_lua = true -- g.do_legacy_filetype = false -- g.did_load_filetypes = 0 +vim.g.night_and_day = 'night' + require('_globals') require('plugins') -require('internal.align').setup { bindings = true } + +require('internal.align').setup({ bindings = true }) require('internal.hardmode') --- Configure builtin diagnositics {{{ -vim.diagnostic.config { - underline = true, - virtual_text = false, - -- virtual_text = { - -- severity = {min=vim.diagnostic.severity.WARN}, - -- source = true, - -- prefix = '', - -- }, - signs = true, - float = true, - virtual_lines = { prefix = '⬐ ' }, +-- DIAGNOSITIC {{{ +vim.diagnostic.config({ + signs = true, + underline = { + severity = { min = vim.diagnostic.severity.WARN }, + }, + float = { + severity = { min = vim.diagnostic.severity.INFO }, + focusable = false, + source = 'always', + prefix = '', + scope = 'cursor', + }, + virtual_text = { + severity = { max = vim.diagnostic.severity.HINT }, + source = true, + prefix = '', + }, + -- virtual_lines = { prefix = '⬐ ' }, update_in_insert = false, - severity_sort = true, -} + severity_sort = true, +}) vim.fn.sign_define({ - {name='DiagnosticSignError', text='✗', texthl='DiagnosticSignError'}, + { name = 'DiagnosticSignError', text = '✗', texthl = 'DiagnosticSignError' }, -- {name='DiagnosticSignWarn', text='⚡', texthl='DiagnosticSignWarn'}, - {name='DiagnosticSignWarn', text='⚐', texthl='DiagnosticSignWarn'}, - {name='DiagnosticSignInfo', text='ℹ', texthl='DiagnosticSignInfo'}, - {name='DiagnosticSignHint', text='🞶', texthl='DiagnosticSignHint'} + { name = 'DiagnosticSignWarn', text = '⚐', texthl = 'DiagnosticSignWarn' }, + { name = 'DiagnosticSignInfo', text = 'ℹ', texthl = 'DiagnosticSignInfo' }, + { name = 'DiagnosticSignHint', text = '🞶', texthl = 'DiagnosticSignHint' }, }) -vim.keymap.set('n', ']d', vim.diagnostic.goto_next, {desc='next diagnostic'}) -vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, {desc='prev diagnostic'}) -vim.keymap.set('n', '<localleader>d', vim.diagnostic.open_float, {desc='show line diagnositics'}) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'next diagnostic' }) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'prev diagnostic' }) +vim.keymap.set( + 'n', + '<localleader>d', + vim.diagnostic.open_float, + { desc = 'show line diagnositics' } +) vim.keymap.set('n', '<leader>D', function() - if not _G.diagnostic_hidden then - vim.diagnostic.hide() - else - vim.diagnostic.show() - end - _G.diagnostic_hidden = not _G.diagnostic_hidden - end, {desc='toggle diagnositics'}) + if not _G.diagnostic_hidden then + vim.diagnostic.hide() + else + vim.diagnostic.show() + end + _G.diagnostic_hidden = not _G.diagnostic_hidden +end, { desc = 'toggle diagnositics' }) -- }}} -- KEY BINDS -- {{{ -vim.keymap.set('n', 'Q', [[ :quitall<cr> ]], {silent = true}) -vim.keymap.set('n', 'gb', [[ :bnext<cr> ]], {silent = true}) -vim.keymap.set('n', 'gB', [[ :bprevious<cr> ]], {silent = true}) -vim.keymap.set('n', '<tab>', [[ :normal za<cr> ]], {silent = true}) +vim.keymap.set('n', 'Q', [[ :quitall<cr> ]], { silent = true }) +vim.keymap.set('n', 'gb', [[ :bnext<cr> ]], { silent = true }) +vim.keymap.set('n', 'gB', [[ :bprevious<cr> ]], { silent = true }) +vim.keymap.set('n', '<tab>', [[ :normal za<cr> ]], { silent = true }) -- vim.keymap.set('n', '<tab>', [[ :exe 'normal za' | IndentBlanklineRefresh<cr> ]], {silent = true}) -- swap gf and gF -- vim.keymap.set('n', 'gf', [[ :e <cfile><cr> ]]) -- vim.keymap.set('v', 'gf', [[ :e <cfile><cr> ]]) -vim.keymap.set({'n', 'v'}, 'gf', function(a) +vim.keymap.set({ 'n', 'v' }, 'gf', function(a) local Path = require('plenary.path') local cfile = Path:new(vim.fn.expand('<cfile>')) if not cfile:is_absolute() then cfile = Path:new(vim.fn.expand('%:p:h'), cfile):normalize() end vim.cmd.edit(cfile) -end, {desc='extends `:e <cfile>` with path normalization'}) +end, { desc = 'extends `:e <cfile>` with path normalization' }) vim.keymap.set('n', '{', [[ {zz ]]) vim.keymap.set('n', '}', [[ }zz ]]) @@ -172,47 +184,58 @@ vim.keymap.set('n', '}', [[ }zz ]]) -- vim.keymap.set({'n', 'v'}, 'c', '_c') -- vim.keymap.set({'n', 'v'}, 'C', '_C') -vim.keymap.set('t', '<esc>', [[ <c-\><c-n> ]]) +vim.keymap.set('t', '<esc>', [[ <c-\><c-n> ]]) vim.keymap.set('t', '<leader>qq', [[ <c-\><c-n> :bdelete!<cr> ]]) -vim.keymap.set('v', 'T', - function() - vim.cmd [[retab!]] - vim.api.nvim_input("<esc>") - end) +vim.keymap.set('v', 'T', function() + vim.cmd([[retab!]]) + vim.api.nvim_input('<esc>') +end) local misc = require('internal.misc') -vim.keymap.set('n', 'gd', function() misc.open_under_cursor(nil, true) end, {desc='open under cursor'}) -vim.keymap.set('n', 'gx', function() misc.open_under_cursor('url-launcher') end, {desc='url-launcher'}) -vim.keymap.set('n', 'gu', function() misc.open_under_cursor('url-launcher') end, {desc='url-launcher'}) +vim.keymap.set('n', 'gd', function() + misc.open_under_cursor(nil, true) +end, { desc = 'open under cursor' }) +vim.keymap.set('n', 'gx', function() + misc.open_under_cursor('url-launcher') +end, { desc = 'url-launcher' }) +vim.keymap.set('n', 'gu', function() + misc.open_under_cursor('url-launcher') +end, { desc = 'url-launcher' }) -- vim.keymap.set('n', '<localleader>gs', function() misc.word_under_cursor(function(s) vim.fn.feedkeys(':%s/' .. s .. '//g'); cmd [[ call feedkeys("\<left>\<left>") ]] end) end) -vim.keymap.set('n', '<leader>r', misc.live_grep, {desc='live grep (rg)'}) -vim.keymap.set('n', '<leader>f', misc.find_files, {desc='find files (fd)'}) +vim.keymap.set('n', '<leader>r', misc.live_grep, { desc = 'live grep (rg)' }) +vim.keymap.set('n', '<leader>f', misc.find_files, { desc = 'find files (fd)' }) -vim.keymap.set('n', '<localleader>dgl', 'diffget LOCAL', {desc='diff get local'}) -vim.keymap.set('n', '<localleader>dgr', 'diffget REMOTE', {desc='diff get remote'}) -vim.keymap.set('n', '<localleader>dpl', 'diffpush LOCAL', {desc='diff push local'}) -vim.keymap.set('n', '<localleader>dpr', 'diffpush REMOTE', {desc='diff push remote'}) +vim.keymap.set('n', '<localleader>dgl', 'diffget LOCAL', { desc = 'diff get local' }) +vim.keymap.set('n', '<localleader>dgr', 'diffget REMOTE', { desc = 'diff get remote' }) +vim.keymap.set('n', '<localleader>dpl', 'diffpush LOCAL', { desc = 'diff push local' }) +vim.keymap.set('n', '<localleader>dpr', 'diffpush REMOTE', { desc = 'diff push remote' }) -vim.keymap.set('x', '<localleader>f', +vim.keymap.set( + 'x', + '<localleader>f', [[<ESC><CMD>lua require("internal.misc").fold_block()<CR>]], - { noremap = true, silent = true, desc = 'fold block' }) + { noremap = true, silent = true, desc = 'fold block' } +) -- vim.keymap.set('v', '<c-r>', [[y:%s/<c-r>h//gc<left><left><left>]], { noremap = true, silent = true }) -vim.keymap.set('n', '<leader>C', function() - local fnln = (vim.fn.expand('%') .. ':' .. vim.fn.line('.')) +vim.keymap.set('n', 'yP', function() + local fnln = (vim.fn.expand('%:p') .. ':' .. vim.fn.line('.')) vim.fn.setreg('+', fnln) vim.notify(fnln) -end, {desc='copy file path'}) - -vim.keymap.set('n', '<leader>J', require('internal.job').list, {desc='list jobs started through internal.job'}) +end, { desc = 'yank absolute file path' }) +vim.keymap.set('n', 'yT', function() + local fnln = (vim.fn.expand('%:t') .. ':' .. vim.fn.line('.')) + vim.fn.setreg('+', fnln) + vim.notify(fnln) +end, { desc = 'yank file name' }) -- }}} -- AUTO GROUPS -- {{{ local augroup = vim.api.nvim_create_augroup local autocmd = vim.api.nvim_create_autocmd -autocmd('TextYankPost', {callback=vim.highlight.on_yank}) +autocmd('TextYankPost', { callback = vim.highlight.on_yank }) do local group = augroup('ObviousActiveWin', { clear = true }) @@ -220,70 +243,99 @@ do autocmd('WinLeave', { command = 'set nocul', group = group }) end -autocmd('QuickFixCmdPost', { - callback = function() - -- make sure there is anyting in the qflist before opening it, - -- avoids: `E42: No Errors` - local qf = vim.fn.getqflist({size = true}) - if qf and qf.size > 0 then vim.cmd [[clist]] end - end, - group = augroup('OpenQuickFix', {}), -}) +do + local group = augroup('OpenQuickFix', { clear = true }) + autocmd('QuickFixCmdPost', { + callback = function() + local qf = vim.fn.getqflist({ qfbufnr = true, size = true }) + if (not qf == vim.empty_dict()) and qf and qf.size > 0 then + -- check if the quickfix buffer is already open + for bufnr in ipairs(vim.api.nvim_list_bufs()) do + if vim.api.nvim_buf_get_option(bufnr, 'buftype') == 'quickfix' then + return + end + end + vim.cmd.copen() + end + end, + group = group, + }) + autocmd('BufEnter', { + pattern = 'qf', + command = [[silent normal! G]], + group = group, + }) +end do local group = augroup('ManualCommentString', { clear = true }) - autocmd('FileType', { pattern = 'i3config', - callback = function() vim.opt_local.commentstring = '# %s' end, + autocmd('FileType', { + pattern = 'i3config', + callback = function() + vim.opt_local.commentstring = '# %s' + end, group = group, }) - autocmd('FileType', { pattern = 'jsonc', - callback = function() vim.opt_local.commentstring = '// %s' end, + autocmd('FileType', { + pattern = 'jsonc', + callback = function() + vim.opt_local.commentstring = '// %s' + end, group = group, }) end do local group = augroup('ManualFolds', { clear = true }) - autocmd('VimEnter', { pattern = 'vim/*', - callback = function() vim.opt_local.foldenable = true end, + autocmd('VimEnter', { + pattern = 'vim/*', + callback = function() + vim.opt_local.foldenable = true + end, group = group, }) - autocmd('FileType', { pattern = 'json,jsonc,yaml,toml', - callback = function() vim.opt_local.foldenable = false end, + autocmd('FileType', { + pattern = 'json,jsonc,yaml,toml', + callback = function() + vim.opt_local.foldenable = false + end, group = group, }) end do local group = augroup('EasyQuit', { clear = true }) - autocmd('FileType', { pattern = 'help,neorg,dap-float', + autocmd('FileType', { + pattern = 'help,neorg,dap-float,qf', callback = function() - vim.keymap.set('n', 'q', '<cmd>close<cr>', - { silent = true, buffer = 0 } - ) + vim.keymap.set('n', 'q', '<cmd>close<cr>', { silent = true, buffer = 0 }) end, group = group, }) - autocmd('FileType', { pattern = 'alpha', + autocmd('FileType', { + pattern = 'alpha', callback = function() - vim.keymap.set('n', 'q', '<cmd>bdel<cr>', - { silent = true, buffer = 0 } - ) + vim.keymap.set('n', 'q', '<cmd>bdel<cr>', { silent = true, buffer = 0 }) end, group = group, }) - autocmd('TermClose', { pattern = 'term://*', + autocmd('TermClose', { + pattern = 'term://*', command = [[ if !v:event.status | exe 'bdelete! '..expand('<abuf>') | endif ]], group = group, }) end -autocmd({'BufRead', 'BufNewFile'}, { pattern = '/home/robert/bin/*', - callback = function() vim.opt_local.filetype = 'sh' end, +autocmd({ 'BufRead', 'BufNewFile' }, { + pattern = '/home/robert/bin/*', + callback = function() + vim.opt_local.filetype = 'sh' + end, group = augroup('DetectBinDir', {}), }) -autocmd({'TermOpen'}, { pattern = 'term://*', +autocmd({ 'TermOpen' }, { + pattern = 'term://*', callback = function() local bufnr = vim.api.nvim_get_current_buf() vim.opt_local.number = false @@ -298,40 +350,48 @@ autocmd({'TermOpen'}, { pattern = 'term://*', -- }}} -- USER COMMANDS -- {{{ -vim.api.nvim_create_user_command('Make', function(opts) require('internal.job').make(opts.fargs) end, - { nargs = '*', desc = 'run make target' }) -vim.api.nvim_create_user_command('Sh', function(opts) require('internal.job').sh(table.concat(opts.fargs, ' ')) end, - { nargs = '*', desc = 'run shell command' }) - -require('internal.misc').setup { +vim.api.nvim_create_user_command('Make', function(opts) + require('internal.job').make(opts.fargs) +end, { nargs = '*', desc = 'run make target' }) +vim.api.nvim_create_user_command('Sh', function(opts) + require('internal.job').sh(table.concat(opts.fargs, ' ')) +end, { nargs = '*', desc = 'run shell command' }) + +require('internal.misc').setup({ grep = true, find = true, sortline = true, -} +}) -- }}} _G.statusline_enable_notifysend = false require('internal.statusline') -require('internal.exrc').setup {} +require('internal.job').setup({}) -- TODO: remove eventually local is_gotmpl = function(bufnr) for ln = 1, vim.api.nvim_buf_line_count(bufnr), 1 do - local line = vim.api.nvim_buf_get_lines(bufnr, ln-1, ln, true) - if #line == 0 then break end + local line = vim.api.nvim_buf_get_lines(bufnr, ln - 1, ln, true) + if #line == 0 then + break + end if line[1]:match('{{.+}}') then return true end end return false end -vim.filetype.add { +vim.filetype.add({ extension = { ha = 'hare', - html = function(_, bufnr) return is_gotmpl(bufnr) and 'gotmpl.html' or 'html' end, - yaml = function(_, bufnr) return is_gotmpl(bufnr) and 'gotmpl.yaml' or 'yaml' end, + html = function(_, bufnr) + return is_gotmpl(bufnr) and 'gotmpl.html' or 'html' + end, + yaml = function(_, bufnr) + return is_gotmpl(bufnr) and 'gotmpl.yaml' or 'yaml' + end, }, filename = { ['Caddyfile'] = 'conf', - } -} + }, +}) |