diff options
| author | Robert Günzler <r@gnzler.io> | 2026-02-10 12:32:48 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2026-02-10 12:41:25 +0100 |
| commit | 63feeb9f369fc6176e85c1c2d8fcc863caad1946 (patch) | |
| tree | 41cd5d2d1ec36e74e464caab722cc9b460153f04 /.config/nvim/lua/config | |
| parent | 5bd0a4aca65ecb9818ef1285982d160b6b6ff665 (diff) | |
start new
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '')
| -rw-r--r-- | .config/nvim/lua/config/diagnostics.lua (renamed from .vim/plugin/diagnostics.lua) | 14 | ||||
| -rw-r--r-- | .config/nvim/lua/config/filetypes.lua | 5 | ||||
| -rw-r--r-- | .config/nvim/lua/config/keymaps.lua | 36 | ||||
| -rw-r--r-- | .config/nvim/lua/config/lazy.lua | 63 | ||||
| -rw-r--r-- | .config/nvim/lua/config/lsp.lua | 66 | ||||
| -rw-r--r-- | .config/nvim/lua/config/options.lua (renamed from .vim/plugin/options.lua) | 4 | ||||
| -rw-r--r-- | .config/nvim/lua/config/reset.lua | 17 | ||||
| -rw-r--r-- | .config/nvim/lua/config/snippets.lua (renamed from .vim/lua/internal/snippets.lua) | 135 | ||||
| -rw-r--r-- | .config/nvim/lua/config/statuscolumn.lua (renamed from .vim/plugin/statuscolumn.lua) | 0 | ||||
| -rw-r--r-- | .config/nvim/lua/config/statusline.lua (renamed from .vim/plugin/statusline.lua) | 0 | ||||
| -rw-r--r-- | .config/nvim/lua/config/undo.lua (renamed from .vim/plugin/undo.lua) | 0 |
11 files changed, 270 insertions, 70 deletions
diff --git a/.vim/plugin/diagnostics.lua b/.config/nvim/lua/config/diagnostics.lua index 93ee621..6314b83 100644 --- a/.vim/plugin/diagnostics.lua +++ b/.config/nvim/lua/config/diagnostics.lua @@ -1,10 +1,10 @@ vim.diagnostic.config({ signs = { text = { - [vim.diagnostic.severity.ERROR] = '✗', - [vim.diagnostic.severity.WARN] = '▷', - [vim.diagnostic.severity.INFO] = 'ℹ', - [vim.diagnostic.severity.HINT] = '🞶', + [vim.diagnostic.severity.ERROR] = '', + [vim.diagnostic.severity.WARN] = '', + [vim.diagnostic.severity.INFO] = '', + [vim.diagnostic.severity.HINT] = '', }, linehl = { -- [vim.diagnostic.severity.ERROR] = 'Search', @@ -44,7 +44,9 @@ end, { desc = 'diagnostic: prev' }) vim.keymap.set('n', 'DD', vim.diagnostic.open_float, { desc = 'diagnostic: current line' }) -vim.keymap.set('n', '<leader>td', function() +vim.keymap.set('n', '<leader>d', '<nop>', { desc = "diagnostics" }) +vim.keymap.set('n', '<leader>dd', vim.diagnostic.open_float, { desc = 'diagnostic: current line' }) +vim.keymap.set('n', '<leader>dv', function() -- 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 @@ -58,6 +60,6 @@ vim.keymap.set('n', '<leader>td', function() end end, { desc = 'diagnostic: toggle visibility' }) -vim.keymap.set('n', '<leader>tD', function() +vim.keymap.set('n', '<leader>da', function() vim.diagnostic.enable(not vim.diagnostic.is_enabled()) end, { desc = 'diagnostic: toggle all' }) diff --git a/.config/nvim/lua/config/filetypes.lua b/.config/nvim/lua/config/filetypes.lua new file mode 100644 index 0000000..f1428d2 --- /dev/null +++ b/.config/nvim/lua/config/filetypes.lua @@ -0,0 +1,5 @@ +vim.filetype.add({ + pattern = { + ['todo.txt'] = 'todotxt', + } +}) diff --git a/.config/nvim/lua/config/keymaps.lua b/.config/nvim/lua/config/keymaps.lua new file mode 100644 index 0000000..9c00f7b --- /dev/null +++ b/.config/nvim/lua/config/keymaps.lua @@ -0,0 +1,36 @@ +local map = vim.keymap.set + +map('n', 'gb', '<cmd>bnext<cr>', { desc = 'Buffer next' }) +map('n', 'gB', '<cmd>bprevious<cr>', { desc = 'Buffer prev' }) + +map('n', '<a-j>', '<cmd>cnext<cr>', { desc = 'Quickfix next' }) +map('n', '<a-k>', '<cmd>cprev<cr>', { desc = 'Quickfix prev' }) + +map('v', '<', '<gv', { desc = 'Indent' }) +map('v', '>', '>gv', { desc = 'Outdent' }) + +map('t', '<esc>', [[ <c-\><c-n> ]], { desc = 'Terminal: Exit INSERT mode' }) + +map( + 'n', + 'gx', + '<cmd>lua vim.ui.open(vim.fn.expand("<cfile>"))<cr>', + { desc = 'Open file under cursor' } +) + +vim.api.nvim_create_autocmd({'BufEnter', 'BufWinEnter'}, { + group = vim.api.nvim_create_augroup('bufclose', {}), + callback = function() + if vim.list_contains({'help', 'nofile', 'quickfix'}, vim.bo.buftype) then + map('', 'q', '<cmd>close<cr>', { desc = 'Close buffer', buffer = 0 }) + end + end, +}) + +map('n', '<leader><leader>x', function() + local file = vim.fn.expand('%') + vim.cmd.source(file) + vim.notify('** sourced ' .. file, vim.log.levels.INFO) +end, { desc = 'source current file' }) + +map('n', '<leader>a', '<cmd>edit #<cr>', { desc = 'open alternative file' }) diff --git a/.config/nvim/lua/config/lazy.lua b/.config/nvim/lua/config/lazy.lua new file mode 100644 index 0000000..5f859f0 --- /dev/null +++ b/.config/nvim/lua/config/lazy.lua @@ -0,0 +1,63 @@ +local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = 'https://github.com/folke/lazy.nvim.git' + local out = vim.fn.system({'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath}) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + {'Failed to clone lazy.nvim:\n', 'ErrorMsg'}, + {out, 'WarningMsg'}, + {'\nPress any key to exit...'}, + }, true, {}) + vi.fn.getchar() -- let user ack + os.exit(1) + end +end + +vim.opt.rtp:prepend(lazypath) + +vim.g.mapleader = " " +vim.g.maplocalleader = "\\" + +require('lazy').setup({ + -- load plugin specs from ./plugins + spec = { { import = 'plugins' } }, + -- colorscheme for installing plugins + install = { colorscheme = { 'default' } }, + -- automatically check for plugin updates + checker = { + enabled = true, + frequency = (3600 * 24 * 3), -- 3 days + }, +}) + +vim.keymap.set({'n'}, '<leader>l', '<nop>', { desc = 'lazy' }) +vim.keymap.set({'n'}, '<leader>lz', '<cmd>Lazy<cr>', { desc = 'lazy: open ui' }) +vim.keymap.set({'n'}, '<leader>ln', function() + local pname = 'TODO' + local ppath = vim.fn.stdpath('config') .. '/lua/plugins' + + vim.ui.input({ prompt = 'Plugin name: ' }, function(input) + pname = input + end) + + vim.cmd.cd(ppath) + + vim.fn.setreg('a', [[return { + { + '$name', + cmd = {'$cmd'}, + opts = {$opts}, + keys = { + { mode = {'n'}, '$lhs', '$rhs', desc = '$desc' }, + }, + } +}]]) + + local buf = vim.api.nvim_create_buf(true, false) + vim.api.nvim_buf_set_name(buf, pname .. '.lua') + vim.api.nvim_set_option_value('filetype', 'lua', { buf = buf }) + vim.api.nvim_win_set_buf(0, buf) + + require('luasnip.extras.otf').on_the_fly('a') + +end, { desc = 'lazy: new plugin' }) diff --git a/.config/nvim/lua/config/lsp.lua b/.config/nvim/lua/config/lsp.lua new file mode 100644 index 0000000..282a3dc --- /dev/null +++ b/.config/nvim/lua/config/lsp.lua @@ -0,0 +1,66 @@ +if not vim.lsp.enable then return end + +local lsp = vim.lsp + +lsp.enable({ + 'bashls', + 'ccls', + 'clangd', + 'gopls', + 'rust_analyzer', + 'superhtml', + 'tinymist', + 'zk', + 'zls', +}) + +local capabilities = nil +if pcall(require, 'blink.cmp') then + capabilities = require('blink.cmp').get_lsp_capabilities() +end + +lsp.config('*', { + root_markers = {'.git'}, + capabilities = capabilities +}) + +vim.api.nvim_create_autocmd({'LspAttach'}, { + group = vim.api.nvim_create_augroup('lspattach', {}), + callback = function(args) + local client = assert(vim.lsp.get_client_by_id(args.data.client_id)) + + -- TODO: what does this do? + vim.opt_local.omnifunc = 'v:lua.vim.lsp.omnifunc' + + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { desc = 'goto_definition' }) + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, { desc = 'goto declaration' }) + vim.keymap.set('n', 'gT', vim.lsp.buf.type_definition, { desc = 'goto type definition' }) + vim.keymap.set('n', 'gR', vim.lsp.buf.references, { desc = 'show references' }) + vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, { desc = 'show code actions' }) + vim.keymap.set('n', 'grr', vim.lsp.buf.rename, { desc = 'rename' }) + + if client:supports_method('textDocument/implementation') then + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { desc = 'goto implementation' }) + end + + if client:supports_method('textDocument/completion') then + vim.lsp.completion.enable(true, client.id, args.buf, {autotrigger = false}) + end + + if client:supports_method('textDocument/formatting') then + vim.keymap.set('n', '<leader>f', vim.lsp.buf.format, { desc = 'format' }) + end + + if not client:supports_method('textDocument/willSaveWaitUntil') + and client:supports_method('textDocument/formatting') then + vim.api.nvim_create_autocmd({'BufWritePre'}, { + group = vim.api.nvim_create_augroup('lspattach', {}), + buffer = args.buf, + callback = function() + if vim.b.nofmt then return end + vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 }) + end, + }) + end + end, +}) diff --git a/.vim/plugin/options.lua b/.config/nvim/lua/config/options.lua index dba726a..073835f 100644 --- a/.vim/plugin/options.lua +++ b/.config/nvim/lua/config/options.lua @@ -15,13 +15,13 @@ opt.listchars:append({ trail = '¬', tab = '> ', -- space = '·', - lead = '·', + -- lead = '·', }) opt.showbreak = '↪ ' -- show indicator and wrap text at 80 chars opt.colorcolumn = '+1' -opt.textwidth = 79 +opt.textwidth = 80 opt.wrap = true opt.conceallevel = 2 diff --git a/.config/nvim/lua/config/reset.lua b/.config/nvim/lua/config/reset.lua new file mode 100644 index 0000000..4908c20 --- /dev/null +++ b/.config/nvim/lua/config/reset.lua @@ -0,0 +1,17 @@ +vim.g.loaded_gzip = 1 +vim.g.loaded_tar = 1 +vim.g.loaded_tarPlugin = 1 +vim.g.loaded_zip = 1 +vim.g.loaded_zipPlugin = 1 +vim.g.loaded_getscript = 1 +vim.g.loaded_getscriptPlugin = 1 +vim.g.loaded_vimball = 1 +vim.g.loaded_vimballPlugin = 1 +vim.g.loaded_matchit = 1 +vim.g.loaded_2html_plugin = 1 +vim.g.loaded_logiPat = 1 +vim.g.loaded_rrhelper = 1 +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 +vim.g.loaded_netrwSettings = 1 +vim.g.loaded_netrwFileHandlers = 1 diff --git a/.vim/lua/internal/snippets.lua b/.config/nvim/lua/config/snippets.lua index be00884..e0c260e 100644 --- a/.vim/lua/internal/snippets.lua +++ b/.config/nvim/lua/config/snippets.lua @@ -1,72 +1,12 @@ local ls = require('luasnip') local types = require('luasnip.util.types') --- attach to builtin snippet hooks - -vim.snippet.expand = ls.lsp_expand - ----@diagnostic disable-next-line: duplicate-set-field -vim.snippet.active = function(filter) - filter = filter or {} - filter.direction = filter.direction or 1 - - if filter.direction == 1 then - return ls.expand_or_jumpable() - else - return ls.jumpable(filter.direction) - end -end - ----@diagnostic disable-next-line: duplicate-set-field -vim.snippet.jump = function(direction) - if direction == 1 then - if ls.expandable() then - return ls.expand_or_jump() - else - return ls.jumpable(1) and ls.jump(1) - end - else - return ls.jumpable(-1) and ls.jump(-1) - end -end - -vim.snippet.stop = ls.unlink_current - -local snip_env = { - -- snippet helpers - nl = function() - return ls.t({ '', '' }) - end, - exec = function(command) - return ls.f(function(_, _, ...) - local job = require('plenary.job'):new({ - command = vim.env.SHELL, - args = { '-c', ... }, - enable_recording = true, - }) - local res, exitcode = job:sync() - if not exitcode == 0 or #res == 0 then - error(string.format('exec "%s" failed', ...)) - end - return res - end, {}, { user_args = { command } }) - end, - -- condition helpers - cond = { - ts = function(capture) - return function() - return vim.tbl_contains(vim.treesitter.get_captures_at_cursor(), capture) - end - end, - }, -} - +-- configure luasnip ls.config.set_config({ enable_autosnippets = true, history = true, updateevents = 'TextChanged,TextChangedI', override_builtin = true, - snip_env = vim.tbl_deep_extend('error', ls.session.config.snip_env, snip_env), ext_opts = { [types.choiceNode] = { active = { @@ -79,10 +19,41 @@ ls.config.set_config({ }, }, }, + snip_env = vim.tbl_deep_extend('error', ls.session.config.snip_env, { + -- snippet helpers + nl = function() + return ls.t({ '', '' }) + end, + exec = function(command) + return ls.f(function(_, _, ...) + local job = require('plenary.job'):new({ + command = vim.env.SHELL, + args = { '-c', ... }, + enable_recording = true, + }) + local res, exitcode = job:sync() + if not exitcode == 0 or #res == 0 then + error(string.format('exec "%s" failed', ...)) + end + return res + end, {}, { user_args = { command } }) + end, + -- condition helpers + cond = { + ts = function(capture) + return function() + return vim.tbl_contains(vim.treesitter.get_captures_at_cursor(), capture) + end + end, + }, + }), }) -require('luasnip.loaders.from_lua').lazy_load({ paths = './snippets' }) +-- snippet loaders +require('luasnip.loaders.from_lua').lazy_load() +require('luasnip.loaders.from_vscode').lazy_load({ include = {} }) +-- keymaps vim.keymap.set({ 'i', 's' }, '<c-j>', function() return vim.snippet.active({ direction = 1 }) and vim.snippet.jump(1) end, { silent = true, desc = 'snippet: jump next' }) @@ -103,8 +74,10 @@ vim.keymap.set({ 'i', 's' }, '<c-p>', function() end end, { silent = true, desc = 'snippet: prev choice' }) +-- usercmds vim.api.nvim_create_user_command('EditSnippets', require('luasnip.loaders').edit_snippet_files, {}) +-- autocmds -- vim.api.nvim_create_autocmd('User', { -- pattern = 'LuasnipChoiceNodeEnter', -- callback = function() @@ -127,3 +100,41 @@ vim.api.nvim_create_user_command('EditSnippets', require('luasnip.loaders').edit -- end) -- end, -- }) + +-- unlink luasnip session on <esc> +vim.api.nvim_create_autocmd('ModeChanged', { + pattern = '*', + callback = function() + if ((vim.v.event.old_mode == 's' and vim.v.event.new_mode == 'n') or vim.v.event.old_mode == 'i') + and ls.session.current_nodes[vim.api.nvim_get_current_buf()] + and not ls.session.jump_active + and not require("blink.cmp").is_visible() + then + ls.unlink_current() + end + end +}) + +-- attach to builtin snippet hooks +vim.snippet.expand = ls.lsp_expand +vim.snippet.active = function(filter) + filter = filter or {} + filter.direction = filter.direction or 1 + if filter.direction == 1 then + return ls.expand_or_jumpable() + else + return ls.jumpable(filter.direction) + end +end +vim.snippet.jump = function(direction) + if direction == 1 then + if ls.expandable() then + return ls.expand_or_jump() + else + return ls.jumpable(1) and ls.jump(1) + end + else + return ls.jumpable(-1) and ls.jump(-1) + end +end +vim.snippet.stop = ls.unlink_current diff --git a/.vim/plugin/statuscolumn.lua b/.config/nvim/lua/config/statuscolumn.lua index 06e8988..06e8988 100644 --- a/.vim/plugin/statuscolumn.lua +++ b/.config/nvim/lua/config/statuscolumn.lua diff --git a/.vim/plugin/statusline.lua b/.config/nvim/lua/config/statusline.lua index fed6d33..fed6d33 100644 --- a/.vim/plugin/statusline.lua +++ b/.config/nvim/lua/config/statusline.lua diff --git a/.vim/plugin/undo.lua b/.config/nvim/lua/config/undo.lua index aed6195..aed6195 100644 --- a/.vim/plugin/undo.lua +++ b/.config/nvim/lua/config/undo.lua |