diff options
| author | Robert Günzler <r@gnzler.io> | 2026-09-27 17:38:39 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2026-09-27 17:38:39 +0200 |
| commit | 0860db73ae6fd9a6f6347219d820bf026a6b8b91 (patch) | |
| tree | 11318c3670d1c32c5aa0bf404c22fba3bf63fc53 /.config/nvim/lua/config | |
| parent | 4e34cbf9673aeaba252e01df554a0d204e83c5e2 (diff) | |
| download | dotfiles-master.tar.gz | |
Automated-commit-by: dots Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.config/nvim/lua/config')
| -rw-r--r-- | .config/nvim/lua/config/autoall.lua | 35 | ||||
| -rw-r--r-- | .config/nvim/lua/config/keymaps.lua | 16 | ||||
| -rw-r--r-- | .config/nvim/lua/config/lsp.lua | 5 | ||||
| -rw-r--r-- | .config/nvim/lua/config/options.lua | 7 | ||||
| -rw-r--r-- | .config/nvim/lua/config/snippets.lua | 84 | ||||
| -rw-r--r-- | .config/nvim/lua/config/templates.lua | 53 |
6 files changed, 140 insertions, 60 deletions
diff --git a/.config/nvim/lua/config/autoall.lua b/.config/nvim/lua/config/autoall.lua new file mode 100644 index 0000000..6f36182 --- /dev/null +++ b/.config/nvim/lua/config/autoall.lua @@ -0,0 +1,35 @@ +-- Autocommands for all files opened in nvim +local autocmd = vim.api.nvim_create_autocmd +local autogrp = vim.api.nvim_create_augroup + +-- check if the current buffer is empty +local bufempty = function(bufnr) + bufnr = bufnr or 0 + if vim.api.nvim_buf_get_offset(bufnr, 0) <= 0 then + local handle = io.open(vim.api.nvim_buf_get_name(bufnr)) + if handle == nil then + return true + end + local eof = handle:read(0) + handle:close() + if eof == nil then + return true + end + end + return false +end + +local expand_template = function(name) + require('luasnip').snip_expand(require('config.templates')[name]) + require('luasnip').unlink_current() +end + +autocmd({ 'BufEnter', 'BufNewFile' }, { + pattern = 'deb/DEBIAN/changelog_blobs/*.txt', + group = autogrp('DebianChangelogTemplate', { clear = true }), + callback = function(opt) + if bufempty() then + return expand_template('debian-changelog') + end + end, +}) diff --git a/.config/nvim/lua/config/keymaps.lua b/.config/nvim/lua/config/keymaps.lua index a93b8fd..3c51041 100644 --- a/.config/nvim/lua/config/keymaps.lua +++ b/.config/nvim/lua/config/keymaps.lua @@ -1,7 +1,12 @@ 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', 'gb', '<cmd>bnext<cr>', { desc = 'Buf next' }) +map('n', 'gB', '<cmd>bprevious<cr>', { desc = 'Buf prev' }) + +map('n', '<c-h>', '<cmd>tabprev<cr>', { desc = 'Tab prev' }) +map('n', '<c-j>', '<cmd>bprev<cr>', { desc = 'Buf prev' }) +map('n', '<c-k>', '<cmd>bnext<cr>', { desc = 'Buf next' }) +map('n', '<c-l>', '<cmd>tabnext<cr>', { desc = 'Tab next' }) map('n', '<a-j>', '<cmd>cnext<cr>', { desc = 'Quickfix next' }) map('n', '<a-k>', '<cmd>cprev<cr>', { desc = 'Quickfix prev' }) @@ -21,8 +26,11 @@ map( 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 }) + if + (vim.fn.maparg('q', 'n') == '') + and vim.list_contains({ 'help', 'nofile', 'nowrite', 'quickfix' }, vim.bo.buftype) + then + map('n', 'q', '<cmd>close<cr>', { desc = 'Close buffer', buffer = 0 }) end end, }) diff --git a/.config/nvim/lua/config/lsp.lua b/.config/nvim/lua/config/lsp.lua index b168014..5a2bf79 100644 --- a/.config/nvim/lua/config/lsp.lua +++ b/.config/nvim/lua/config/lsp.lua @@ -6,6 +6,8 @@ local lsp = vim.lsp lsp.enable({ 'bashls', + 'blueprint_ls', + 'buf_ls', 'ccls', 'clangd', 'gopls', @@ -14,6 +16,7 @@ lsp.enable({ 'rust_analyzer', 'superhtml', 'tinymist', + 'vala_ls', 'zk', 'zls', }) @@ -35,7 +38,7 @@ lsp.config('*', { 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)) + local client = vim.lsp.get_client_by_id(args.data.client_id) -- TODO: what does this do? vim.opt_local.omnifunc = 'v:lua.vim.lsp.omnifunc' diff --git a/.config/nvim/lua/config/options.lua b/.config/nvim/lua/config/options.lua index 073835f..07a41a3 100644 --- a/.config/nvim/lua/config/options.lua +++ b/.config/nvim/lua/config/options.lua @@ -37,3 +37,10 @@ opt.mousescroll = 'ver:1,hor:6' -- load local vim config (will as to allow it) opt.exrc = true + +-- increase the auto-scroll window +opt.scrolloff = 10 + +-- use osc2 to set terminal title +opt.title = true +opt.titlestring = [[nvim: %t%( %M%)%( (%{expand("%:~:h")})%)%a]] diff --git a/.config/nvim/lua/config/snippets.lua b/.config/nvim/lua/config/snippets.lua index e0c260e..9cd0632 100644 --- a/.config/nvim/lua/config/snippets.lua +++ b/.config/nvim/lua/config/snippets.lua @@ -6,16 +6,24 @@ ls.config.set_config({ enable_autosnippets = true, history = true, updateevents = 'TextChanged,TextChangedI', - override_builtin = true, + exit_roots = false, -- dont exit when reaching last node ext_opts = { [types.choiceNode] = { - active = { - virt_text = { { '◂ ', 'NonText' } }, + passive = { + virt_text = { { ' ', 'Conceal' } }, + virt_text_pos = 'inline', }, }, [types.insertNode] = { - active = { - virt_text = { { '◂ ', 'NonText' } }, + passive = { + virt_text = { { ' ', 'Conceal' } }, + virt_text_pos = 'inline', + }, + }, + [types.exitNode] = { + passive = { + virt_text = { { '$', 'Conceal' } }, + virt_text_pos = 'inline', }, }, }, @@ -53,27 +61,6 @@ ls.config.set_config({ 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' }) - -vim.keymap.set({ 'i', 's' }, '<c-k>', function() - return vim.snippet.active({ direction = -1 }) and vim.snippet.jump(-1) -end, { silent = true, desc = 'snippet: jump prev' }) - -vim.keymap.set({ 'i', 's' }, '<c-n>', function() - if ls.choice_active() then - ls.change_choice(1) - end -end, { silent = true, desc = 'snippet: next choice' }) - -vim.keymap.set({ 'i', 's' }, '<c-p>', function() - if ls.choice_active() then - ls.change_choice(-1) - end -end, { silent = true, desc = 'snippet: prev choice' }) - -- usercmds vim.api.nvim_create_user_command('EditSnippets', require('luasnip.loaders').edit_snippet_files, {}) @@ -105,36 +92,23 @@ vim.api.nvim_create_user_command('EditSnippets', require('luasnip.loaders').edit 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() + if + ((vim.v.event.old_mode == 's' or vim.v.event.old_mode == 'i') and vim.v.event.new_mode == 'n') + 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() + vim.schedule(ls.unlink_current) end - 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 +-- expand/jump keymaps handled by blink + +vim.keymap.set({ 'i', 's' }, '<c-n>', function() + return ls.choice_active() and ls.change_choice(1) +end, { silent = true, desc = 'luasnip: next choice' }) + +vim.keymap.set({ 'i', 's' }, '<c-p>', function() + return ls.choice_active() and ls.change_choice(-1) +end, { silent = true, desc = 'luasnip: prev choice' }) diff --git a/.config/nvim/lua/config/templates.lua b/.config/nvim/lua/config/templates.lua new file mode 100644 index 0000000..a01efa1 --- /dev/null +++ b/.config/nvim/lua/config/templates.lua @@ -0,0 +1,53 @@ +-- template snippets +require('luasnip').setup_snip_env() +local templates = {} + +-- check if the current buffer is empty +local bufempty = function(bufnr) + bufnr = bufnr or 0 + if vim.api.nvim_buf_get_offset(bufnr, 0) <= 0 then + local handle = io.open(vim.api.nvim_buf_get_name(bufnr)) + if handle == nil then + return true + end + local eof = handle:read(0) + handle:close() + if eof == nil then + return true + end + end + return false +end + +local register_template = function(pattern, snip) + templates[pattern] = snip + + vim.api.nvim_create_autocmd({ 'BufEnter', 'BufNewFile' }, { + pattern = pattern, + group = vim.api.nvim_create_augroup('Template' .. pattern, { clear = true }), + callback = function(opt) + if bufempty() then + require('luasnip').snip_expand(templates[pattern]) + require('luasnip').unlink_current() + end + end, + }) +end + +register_template( + 'deb/DEBIAN/changelog_blobs/*.txt', + s( + 'debian-changelog', + fmt( + [[ +ukp-agent (${VERSION}) unstable; urgency=medium + + * feat: <> +]], + { i(0) }, + { + delimiters = '<>', + } + ) + ) +) |