dotfiles/.config/nvim/init.lua

344 lines
11 KiB
Lua
Raw Normal View History

2026-01-15 14:17:10 +01:00
-- Set <space> as the leader key
-- See `:help mapleader`
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
vim.g.mapleader = " "
vim.g.maplocalleader = " "
2026-01-15 14:17:10 +01:00
2026-04-27 21:10:27 +02:00
vim.o.guifont = "Adwaita Mono:h12"
-- Disable mouse input
2026-01-15 14:17:10 +01:00
vim.o.mouse = ""
-- Minimal number of screen lines to keep above and below the cursor.
vim.o.scrolloff = 10
2026-01-15 14:17:10 +01:00
-- Highlight the line where the cursor is on
vim.o.cursorline = true
-- Column at 80 characters
vim.o.colorcolumn = "80"
-- Set default tabstop and shiftwidth
vim.o.tabstop = 4
vim.o.shiftwidth = 4
2026-04-26 12:58:33 +02:00
vim.o.expandtab = false
2026-01-15 14:17:10 +01:00
-- Show <tab> and trailing spaces
vim.o.list = true
vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "" }
-- Configure line wrap
2026-01-15 14:17:10 +01:00
vim.o.linebreak = true
vim.o.breakindent = true
vim.o.showbreak = ""
-- Case-insensitive searching UNLESS \C or one or more capital letters in the search term
vim.o.ignorecase = true
vim.o.smartcase = true
-- Use undofile to preserve actions over restarts
vim.o.undofile = true
2026-01-15 14:17:10 +01:00
-- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`),
-- instead raise a dialog asking if you wish to save the current file(s) See `:help 'confirm'`
vim.o.confirm = true
2026-03-01 17:12:31 +01:00
-- local toggle_background = function (obj)
2026-04-26 12:58:33 +02:00
-- print(string.find(obj.stdout, "prefer-light"))
-- if string.find(obj.stdout, "prefer-light") then
-- print('light')
-- else
-- print('dark')
-- end
2026-03-01 17:12:31 +01:00
-- end
--
-- vim.o.background = 'light'
-- vim.system({"dconf", "read", "/org/gnome/desktop/interface/color-scheme"}, toggle_background)
vim.cmd.colorscheme("gruvbox")
2026-01-15 14:17:10 +01:00
-- [[ Set up keymaps ]] See `:h vim.keymap.set()`, `:h mapping`, `:h keycodes`
-- Use <Esc> to exit terminal mode
2026-02-12 14:49:48 +01:00
vim.keymap.set("t", "<A-Esc>", "<C-\\><C-n>")
2026-01-15 14:17:10 +01:00
-- Map <A-j>, <A-k>, <A-h>, <A-l> to navigate between windows in any modes
vim.keymap.set({ "t", "i" }, "<A-h>", "<C-\\><C-n><C-w>h")
vim.keymap.set({ "t", "i" }, "<A-j>", "<C-\\><C-n><C-w>j")
vim.keymap.set({ "t", "i" }, "<A-k>", "<C-\\><C-n><C-w>k")
vim.keymap.set({ "t", "i" }, "<A-l>", "<C-\\><C-n><C-w>l")
vim.keymap.set({ "n" }, "<A-h>", "<C-w>h")
vim.keymap.set({ "n" }, "<A-j>", "<C-w>j")
vim.keymap.set({ "n" }, "<A-k>", "<C-w>k")
vim.keymap.set({ "n" }, "<A-l>", "<C-w>l")
-- [[ Basic Autocommands ]].
-- See `:h lua-guide-autocommands`, `:h autocmd`, `:h nvim_create_autocmd()`
-- Highlight when yanking (copying) text.
-- Try it with `yap` in normal mode. See `:h vim.hl.on_yank()`
vim.api.nvim_create_autocmd("TextYankPost", {
desc = "Highlight when yanking (copying) text",
callback = function()
vim.hl.on_yank()
end,
})
-- Sync clipboard between OS and Neovim. Schedule the setting after `UiEnter` because it can
-- increase startup-time. Remove this option if you want your OS clipboard to remain independent.
-- See `:help 'clipboard'`
vim.api.nvim_create_autocmd("UIEnter", {
callback = function()
vim.o.clipboard = "unnamedplus"
end,
})
-- Print the line number in front of each line
vim.o.number = true
2026-02-09 22:15:57 +01:00
vim.o.relativenumber = true
2026-01-15 14:17:10 +01:00
-- [[ Create user commands ]]
-- See `:h nvim_create_user_command()` and `:h user-commands`
-- Create a command `:GitBlameLine` that print the git blame for the current line
vim.api.nvim_create_user_command("GitBlameLine", function()
local line_number = vim.fn.line(".") -- Get the current line number. See `:h line()`
local filename = vim.api.nvim_buf_get_name(0)
print(vim.fn.system({ "git", "blame", "-L", line_number .. ",+1", filename }))
end, { desc = "Print the git blame for the current line" })
-- [[ Add optional packages ]]
-- Nvim comes bundled with a set of packages that are not enabled by
-- default. You can enable any of them by using the `:packadd` command.
-- For example, to add the "nohlsearch" package to automatically turn off search highlighting after
-- 'updatetime' and when going to insert mode
vim.cmd("packadd! nohlsearch")
2026-01-20 00:45:49 +01:00
-- [[ Language Setup ]]
2026-01-15 14:17:10 +01:00
-- Treat Ipe stylesheets as xml code
vim.filetype.add({
extension = {
isy = "xml",
},
})
-- Install nvim-treesitter
2026-01-19 13:44:27 +01:00
vim.pack.add({ "https://github.com/nvim-treesitter/nvim-treesitter" })
2026-04-27 21:10:27 +02:00
require("nvim-treesitter").install({ 'fish', 'java', 'latex', 'make', 'python' })
2026-02-11 14:39:57 +01:00
vim.api.nvim_create_autocmd('FileType', {
2026-03-07 21:43:24 +01:00
pattern = { '<filetype>' },
2026-02-11 14:39:57 +01:00
callback = function()
vim.treesitter.start()
2026-03-04 02:34:31 +01:00
vim.wo[0][0].foldexpr = 'v:lua.vim.treesitter.foldexpr()'
vim.wo[0][0].foldmethod = 'expr'
2026-02-11 14:39:57 +01:00
end,
2026-02-09 21:47:15 +01:00
})
2026-01-15 14:17:10 +01:00
2026-01-19 13:44:27 +01:00
vim.pack.add({ "https://github.com/mason-org/mason.nvim" })
2026-04-27 19:57:33 +02:00
require("mason").setup()
2026-01-15 14:17:10 +01:00
2026-04-27 19:57:33 +02:00
vim.lsp.enable({ 'lua_ls', 'texlab', 'clangd', 'jdtls', 'fish_lsp', 'html', 'cssls', 'lemminx', 'pyright' })
2026-02-24 16:16:27 +01:00
2026-01-20 00:45:49 +01:00
vim.keymap.set('n', '<leader>lf', vim.lsp.buf.format,
2026-01-20 16:44:06 +01:00
{ desc = 'Formats a buffer using the attached language server clients' })
2026-01-20 00:45:49 +01:00
vim.keymap.set('n', '<leader>lh', vim.lsp.buf.hover,
2026-01-20 16:44:06 +01:00
{ desc = 'Displays hover information about the symbol' })
2026-01-20 00:45:49 +01:00
vim.keymap.set('n', '<leader>lr', vim.lsp.buf.rename,
2026-01-20 16:44:06 +01:00
{ desc = 'Renames all references to the symbol' })
2026-01-20 00:45:49 +01:00
vim.keymap.set('n', '<leader>ld', vim.lsp.buf.definition,
2026-01-20 16:44:06 +01:00
{ desc = 'Jumps to the definition of the symbol' })
2026-01-15 14:17:10 +01:00
vim.diagnostic.config({
signs = {
text = {
[vim.diagnostic.severity.ERROR] = "W ",
[vim.diagnostic.severity.WARN] = "w ",
[vim.diagnostic.severity.INFO] = "I ",
[vim.diagnostic.severity.HINT] = "H ",
},
},
virtual_text = true, -- Show inline diagnostics
})
2026-01-19 13:44:27 +01:00
vim.keymap.set("n", "<leader>dn", "]d", { desc = "Jump to next diagnostic" })
vim.keymap.set("n", "<leader>dp", "[d", { desc = "Jump to previous diagnostic" })
vim.keymap.set("n", "<leader>dN", "]D", { desc = "Jump to last diagnostic" })
vim.keymap.set("n", "<leader>dP", "[D", { desc = "Jump to first diagnostic" })
vim.keymap.set("n", "<leader>ds", "<C-w>d", { desc = "Display diagnostic on current line" })
2026-01-15 14:17:10 +01:00
2026-03-01 17:12:31 +01:00
vim.api.nvim_create_autocmd('FileType', {
2026-03-07 21:43:24 +01:00
pattern = { 'c', 'cpp', 'rust' },
2026-03-01 17:12:31 +01:00
callback = function()
vim.pack.add({ "https://github.com/mfussenegger/nvim-dap", "https://github.com/theHamsta/nvim-dap-virtual-text" })
local dap = require("dap")
local dap_widgets = require("dap.ui.widgets")
local dap_sidebar_s = dap_widgets.sidebar(dap_widgets.scopes)
local dap_sidebar_f = dap_widgets.sidebar(dap_widgets.frames)
vim.keymap.set("n", "<leader>bb", dap.toggle_breakpoint, { desc = "Toggle breakpoint" })
vim.keymap.set("n", "<leader>bc", dap.continue, { desc = "Continue execution" })
dap.listeners.on_session["debug"] = function()
vim.keymap.set("n", "<leader>bs", dap_sidebar_s.toggle, { desc = "Toggle scopes" })
vim.keymap.set("n", "<leader>bf", dap_sidebar_f.toggle, { desc = "Toggle frames" })
2026-03-07 21:43:24 +01:00
vim.keymap.set("n", "<leader>br", dap.repl.toggle, { desc = "Toggle REPL" })
2026-03-01 17:12:31 +01:00
vim.keymap.set("n", "<Left>", dap.step_out, { desc = "Step out" })
vim.keymap.set("n", "<Right>", dap.step_into, { desc = "Step into" })
vim.keymap.set("n", "<Down>", dap.step_over, { desc = "Step over" })
vim.keymap.set("n", "<Up>", dap.restart_frame, { desc = "Restart frame" })
end
dap.adapters.gdb = {
type = "executable",
command = "gdb",
args = { "--interpreter=dap", "--eval-command", "set print pretty on" }
}
2026-01-20 00:45:49 +01:00
2026-03-01 17:12:31 +01:00
dap.configurations.c = {
{
name = "Launch",
type = "gdb",
request = "launch",
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
args = {}, -- provide arguments if needed
cwd = "${workspaceFolder}",
stopAtBeginningOfMainSubprogram = false,
},
{
name = "Select and attach to process",
type = "gdb",
request = "attach",
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
pid = function()
local name = vim.fn.input('Executable name (filter): ')
return require("dap.utils").pick_process({ filter = name })
end,
cwd = '${workspaceFolder}'
},
{
name = 'Attach to gdbserver :1234',
type = 'gdb',
request = 'attach',
target = 'localhost:1234',
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}'
}
2026-01-26 23:38:04 +01:00
}
2026-01-20 00:45:49 +01:00
2026-03-01 17:12:31 +01:00
dap.configurations.cpp = dap.configurations.c
dap.configurations.rust = dap.configurations.c
end,
})
2026-03-04 02:34:31 +01:00
--
2026-01-17 16:52:15 +01:00
-- [[ UI Configuration ]]
2026-02-09 22:15:57 +01:00
vim.pack.add({ "https://github.com/nvim-mini/mini.nvim" })
2026-01-15 14:17:10 +01:00
vim.o.winborder = "none"
-- Use mini.completion
2026-01-15 14:17:10 +01:00
require("mini.completion").setup()
2026-01-19 13:44:27 +01:00
local imap_expr = function(lhs, rhs)
vim.keymap.set('i', lhs, rhs, { expr = true })
end
imap_expr('<Tab>', [[pumvisible() ? "\<C-n>" : "\<Tab>"]])
imap_expr('<S-Tab>', [[pumvisible() ? "\<C-p>" : "\<S-Tab>"]])
2026-02-12 14:49:48 +01:00
-- Snippet integration for mini.completion
2026-03-07 21:43:24 +01:00
-- require("mini.snippets").setup()
-- Icons for statusline and completion
2026-01-15 14:17:10 +01:00
require("mini.icons").setup()
-- Use mini.statusline instead of native showmode
2026-01-15 14:17:10 +01:00
require("mini.statusline").setup()
vim.o.showmode = false
-- Git integration for statusline and Command mode
2026-01-15 14:17:10 +01:00
require("mini.git").setup()
-- Show git diff in linenumbers
2026-01-15 14:17:10 +01:00
require("mini.diff").setup()
2026-03-07 21:43:24 +01:00
-- Use mini.notify
2026-03-07 21:52:47 +01:00
-- require("mini.notify").setup()
2026-03-07 21:43:24 +01:00
-- Use and configure mini.clue
2026-02-09 22:19:11 +01:00
local clue = require("mini.clue")
clue.setup({
2026-01-15 14:17:10 +01:00
triggers = {
-- Leader triggers
{ mode = { "n", "x" }, keys = "<Leader>" },
-- `[` and `]` keys
2026-01-19 13:44:27 +01:00
{ mode = "n", keys = "[" },
{ mode = "n", keys = "]" },
2026-01-15 14:17:10 +01:00
-- Built-in completion
2026-01-19 13:44:27 +01:00
{ mode = "i", keys = "<C-x>" },
2026-01-15 14:17:10 +01:00
-- `g` key
{ mode = { "n", "x" }, keys = "g" },
-- Marks
{ mode = { "n", "x" }, keys = "'" },
{ mode = { "n", "x" }, keys = "`" },
-- Registers
{ mode = { "n", "x" }, keys = '"' },
{ mode = { "i", "c" }, keys = "<C-r>" },
-- Window commands
2026-01-19 13:44:27 +01:00
{ mode = "n", keys = "<C-w>" },
2026-01-15 14:17:10 +01:00
-- `z` key
{ mode = { "n", "x" }, keys = "z" },
2026-02-24 16:16:27 +01:00
-- `i/a` key
{ mode = { "n", "x" }, keys = "i" },
2026-01-15 14:17:10 +01:00
},
clues = {
-- Enhance this by adding descriptions for <Leader> mapping groups
2026-02-09 22:19:11 +01:00
clue.gen_clues.square_brackets(),
clue.gen_clues.builtin_completion(),
clue.gen_clues.g(),
clue.gen_clues.marks(),
clue.gen_clues.registers(),
clue.gen_clues.windows(),
clue.gen_clues.z(),
2026-01-15 14:17:10 +01:00
},
window = {
delay = 200,
config = {
width = 'auto',
}
2026-01-15 14:17:10 +01:00
}
})
-- Use and configure mini.hipatterns
2026-03-07 21:43:24 +01:00
-- local hipatterns = require('mini.hipatterns')
-- hipatterns.setup({
2026-04-26 12:58:33 +02:00
-- highlighters = {
-- -- Highlight standalone 'FIXME', 'HACK', 'TODO', 'NOTE'
-- fixme = { pattern = '%f[%w]()FIXME()%f[%W]', group = 'MiniHipatternsFixme' },
-- hack = { pattern = '%f[%w]()HACK()%f[%W]', group = 'MiniHipatternsHack' },
-- todo = { pattern = '%f[%w]()TODO()%f[%W]', group = 'MiniHipatternsTodo' },
-- note = { pattern = '%f[%w]()NOTE()%f[%W]', group = 'MiniHipatternsNote' },
2026-03-07 21:43:24 +01:00
--
2026-04-26 12:58:33 +02:00
-- -- Highlight hex color strings (`#rrggbb`) using that color
-- hex_color = hipatterns.gen_highlighter.hex_color(),
-- },
2026-03-07 21:43:24 +01:00
-- })