Files
nvim/init.lua
T

288 lines
11 KiB
Lua

-- VIM OPTIONS START --
local vim = vim
vim.o.number = true
vim.o.relativenumber = true
vim.o.tabstop = 4
vim.o.shiftwidth = 4
vim.o.expandtab = true
vim.o.signcolumn = "yes"
vim.o.swapfile = false
vim.g.mapleader = " "
vim.o.winborder = "single"
-- Make 'j' and 'k' navigate visual lines (not logical lines)
vim.keymap.set("n", "j", "gj", { noremap = true, silent = true })
vim.keymap.set("n", "k", "gk", { noremap = true, silent = true })
vim.keymap.set("v", "j", "gj", { noremap = true, silent = true })
vim.keymap.set("v", "k", "gk", { noremap = true, silent = true })
-- VIM OPTIONS END --
-- PLUGINS START --
vim.pack.add({
{ src = "https://github.com/ellisonleao/gruvbox.nvim" },
{ src = "https://github.com/stevearc/oil.nvim" },
{ src = "https://github.com/echasnovski/mini.pick" },
{ src = "https://github.com/neovim/nvim-lspconfig" },
{ src = "https://github.com/nvim-treesitter/nvim-treesitter" },
{ src = "https://github.com/nvim-treesitter/nvim-treesitter-textobjects" },
{ src = "https://github.com/Saghen/blink.cmp", version = "v1.6.0", },
{ src = "https://github.com/mason-org/mason.nvim" },
{ src = "https://github.com/dimitry-ishenko-neovim/lualine-nvim" },
{ src = "https://github.com/chomosuke/typst-preview.nvim" },
{ src = "https://github.com/kosayoda/nvim-lightbulb" },
{ src = "https://codeberg.org/mfussenegger/nvim-jdtls.git", dependencies = { "https://codeberg.org/mfussenegger/nvim-dap.git" } },
{ src = "https://github.com/m4xshen/autoclose.nvim", },
{ src = "https://codeberg.org/mfussenegger/nvim-dap.git" },
{ src = "https://github.com/romgrk/barbar.nvim" },
{ src = "https://github.com/nvim-tree/nvim-web-devicons" },
{ src = "https://github.com/lewis6991/gitsigns.nvim" },
{ src = "https://github.com/folke/trouble.nvim" },
{ src = "https://github.com/rcarriga/nvim-dap-ui", dependencies = { "https://github.com/mfussenegger/nvim-dap", "https://github.com/nvim-neotest/nvim-nio" } },
{ src = "https://github.com/nvim-neotest/nvim-nio" },
})
vim.cmd("colorscheme gruvbox")
require("oil").setup()
require("mini.pick").setup()
require("blink.cmp").setup({
keymap = { preset = "super-tab" },
})
require("nvim-treesitter.configs").setup({
auto_install = true,
highlight = { enable = true },
indent = { enable = true },
textobjects = {
select = {
enable = true,
-- Automatically jump forward to textobj, similar to targets.vim
lookahead = true,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
["ic"] = "@class.inner",
},
},
},
})
require("mason").setup()
require("lualine").setup {
options = {
theme = "gruvbox_dark",
}
}
require("typst-preview").setup()
require("nvim-lightbulb").setup({ autocmd = { enabled = true } })
require("autoclose").setup()
require("trouble").setup()
-- PLUGINS END --
-- DAP START --
require("dapui").setup()
local dap, dapui = require("dap"), require("dapui")
dap.listeners.before.attach.dapui_config = function()
dapui.open()
end
dap.listeners.before.launch.dapui_config = function()
dapui.open()
end
dap.listeners.before.event_terminated.dapui_config = function()
dapui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
dapui.close()
end
-- DAP END --
-- LSP START --
vim.lsp.enable({ "lua_ls", "ts_ls", "svelte", "tailwindcss", "cssls", "bashls", "rust_analyzer", "clangd", "clang-format",
"taplo",
"sourcekit", "lemminx", "tinymist", "jsonls" })
vim.lsp.config["tinymist"] = {
cmd = { "tinymist" },
filetypes = { "typst" },
settings = {
formatterMode = "typstyle",
},
}
vim.api.nvim_create_autocmd('FileType', {
pattern = 'java',
callback = function(args)
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t")
local workspace_dir = vim.fn.stdpath("data") ..
package.config:sub(1, 1) .. "jdtls-workspace" .. package.config:sub(1, 1) .. project_name
local os_name = vim.loop.os_uname().sysname
local config = {
-- The command that starts the language server
-- See: https://github.com/eclipse/eclipse.jdt.ls#running-from-the-command-line
cmd = {
-- 💀
"java", -- or '/path/to/java17_or_newer/bin/java'
-- depends on if `java` is in your $PATH env variable and if it points to the right version.
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
"-Dosgi.bundles.defaultStartLevel=4",
"-Declipse.product=org.eclipse.jdt.ls.core.product",
"-Dlog.protocol=true",
"-Dlog.level=ALL",
"-Xmx1g",
"--add-modules=ALL-SYSTEM",
"--add-opens",
"java.base/java.util=ALL-UNNAMED",
"--add-opens",
"java.base/java.lang=ALL-UNNAMED",
-- 💀
"-jar",
vim.fn.stdpath("data") ..
package.config:sub(1, 1) ..
"mason" ..
package.config:sub(1, 1) ..
"packages" ..
package.config:sub(1, 1) ..
"jdtls" ..
package.config:sub(1, 1) ..
"plugins" .. package.config:sub(1, 1) .. "org.eclipse.equinox.launcher_1.7.100.v20251014-1222.jar",
-- Must point to the Change this to
-- eclipse.jdt.ls installation the actual version
-- 💀
"-configuration",
vim.fn.stdpath("data") ..
package.config:sub(1, 1) ..
"mason" ..
package.config:sub(1, 1) ..
"packages" ..
package.config:sub(1, 1) ..
"jdtls" ..
package.config:sub(1, 1) ..
"config_" .. (os_name == "Windows_NT" and "win" or os_name == "Linux" and "linux" or "mac"),
-- eclipse.jdt.ls installation Depending on your system.
-- 💀
-- See `data directory configuration` section in the README
"-data",
workspace_dir,
},
-- 💀
-- This is the default if not provided, you can remove it. Or adjust as needed.
-- One dedicated LSP server & client will be started per unique root_dir
root_dir = require("jdtls.setup").find_root({ ".git", "mvnw", "gradlew" }),
-- Here you can configure eclipse.jdt.ls specific settings
-- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
-- for a list of options
settings = {
java = {},
},
-- Language server `initializationOptions`
-- You need to extend the `bundles` with paths to jar files
-- if you want to use additional eclipse.jdt.ls plugins.
--
-- See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation
--
-- If you don't plan on using the debugger or other eclipse.jdt.ls plugins you can remove this
init_options = {
bundles = { vim.fn.glob("/home/jannikdonker/.local/share/nvim/mason/share/java-debug-adapter/com.microsoft.java.debug.plugin.jar", 1) },
},
}
-- This starts a new client & server,
-- or attaches to an existing client & server depending on the `root_dir`.
require("jdtls").start_or_attach(config)
end
})
-- LSP END --
-- KEYMAP START --
local map = vim.keymap
local opts = { noremap = true, silent = true }
map.set("n", "<leader>gf", vim.lsp.buf.format)
map.set("n", "<leader>gd", vim.lsp.buf.definition)
map.set("n", "<leader>gD", vim.lsp.buf.declaration)
map.set("n", "<leader>ca", vim.lsp.buf.code_action, { desc = "Code Action" })
map.set("n", "<leader>rn", vim.lsp.buf.rename, { desc = "Rename symbol" })
map.set("n", "<leader>xx", "<cmd>Trouble diagnostics toggle focus=true<cr>", { desc = "Diagnostics (Trouble)" })
map.set("n", "<leader>xX", "<cmd>Trouble diagnostics toggle filter.buf=0 focus=true<cr>",
{ desc = "Buffer Diagnostics (Trouble)" })
map.set("n", "<C-f>", ":Pick files<CR>")
map.set("n", "<C-g>", ":Pick grep_live<CR>")
map.set("n", "<C-h>", ":Pick help<CR>")
map.set("n", "<C-e>", ":Oil<CR>")
map.set("n", "<leader>duo", dapui.open)
map.set("n", "<leader>duc", dapui.close)
map.set("n", "<leader>dbp", dap.toggle_breakpoint)
map.set("n", "<leader>drc", dap.run_to_cursor)
-- Move to previous/next
map.set('n', '<A-,>', '<Cmd>BufferPrevious<CR>', opts)
map.set('n', '<A-.>', '<Cmd>BufferNext<CR>', opts)
-- Re-order to previous/next
map.set('n', '<A-<>', '<Cmd>BufferMovePrevious<CR>', opts)
map.set('n', '<A->>', '<Cmd>BufferMoveNext<CR>', opts)
-- Goto buffer in position...
map.set('n', '<A-1>', '<Cmd>BufferGoto 1<CR>', opts)
map.set('n', '<A-2>', '<Cmd>BufferGoto 2<CR>', opts)
map.set('n', '<A-3>', '<Cmd>BufferGoto 3<CR>', opts)
map.set('n', '<A-4>', '<Cmd>BufferGoto 4<CR>', opts)
map.set('n', '<A-5>', '<Cmd>BufferGoto 5<CR>', opts)
map.set('n', '<A-6>', '<Cmd>BufferGoto 6<CR>', opts)
map.set('n', '<A-7>', '<Cmd>BufferGoto 7<CR>', opts)
map.set('n', '<A-8>', '<Cmd>BufferGoto 8<CR>', opts)
map.set('n', '<A-9>', '<Cmd>BufferGoto 9<CR>', opts)
map.set('n', '<A-0>', '<Cmd>BufferLast<CR>', opts)
-- Pin/unpin buffer
map.set('n', '<A-p>', '<Cmd>BufferPin<CR>', opts)
-- Close buffer
map.set('n', '<A-w>', '<Cmd>BufferClose<CR>', opts)
-- Magic buffer-picking mode
map.set('n', '<C-p>', '<Cmd>BufferPick<CR>', opts)
map.set('n', '<C-s-p>', '<Cmd>BufferPickDelete<CR>', opts)
-- KEYMAP END --
vim.diagnostic.config({
virtual_text = {
prefix = "●",
spacing = 2,
source = "if_many",
},
severity_sort = true,
})
-- Toggle spell check with <leader>sc
vim.keymap.set("n", "<leader>sc", function()
vim.wo.spell = not vim.wo.spell
print("Spell checking: " .. (vim.wo.spell and "ON" or "OFF"))
end, { desc = "Toggle spell checking" })
-- Switch between English and German with <leader>sl
vim.keymap.set("n", "<leader>sl", function()
local current = vim.opt.spelllang:get()[1] or ""
local new_lang = current == "en" and "de" or "en"
vim.opt.spelllang = new_lang
print("Spell language: " .. new_lang)
end, { desc = "Switch spell language" })