Public Access
rewrite and additions
This commit is contained in:
@@ -1,292 +1,4 @@
|
||||
-- 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.7.0" },
|
||||
{ src = "https://github.com/mason-org/mason.nvim" },
|
||||
{ src = "https://github.com/nvim-lualine/lualine.nvim.git" },
|
||||
{ src = "https://github.com/chomosuke/typst-preview.nvim" },
|
||||
{ src = "https://github.com/numToStr/Comment.nvim" },
|
||||
{ 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" },
|
||||
})
|
||||
|
||||
-- Safely load colorscheme
|
||||
pcall(vim.cmd, "colorscheme gruvbox")
|
||||
|
||||
-- Helper function to safely setup plugins only if they are installed
|
||||
local function setup_plugin(module, opts)
|
||||
local ok, plugin = pcall(require, module)
|
||||
if ok and type(plugin.setup) == "function" then
|
||||
plugin.setup(opts or {})
|
||||
end
|
||||
end
|
||||
|
||||
setup_plugin("oil")
|
||||
setup_plugin("mini.pick")
|
||||
setup_plugin("blink.cmp", { keymap = { preset = "super-tab" } })
|
||||
-- nvim-treesitter main branch: no configs.setup, no auto_install,
|
||||
-- no highlight.enable. You install parsers and start TS yourself.
|
||||
local ok_ts, ts = pcall(require, "nvim-treesitter")
|
||||
if ok_ts then
|
||||
ts.install({
|
||||
"lua", "vim", "vimdoc", "bash", "c", "cpp", "rust", "python",
|
||||
"javascript", "typescript", "tsx", "svelte", "css", "html",
|
||||
"json", "toml", "yaml", "markdown", "markdown_inline",
|
||||
"java", "typst", "vala",
|
||||
})
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
pcall(vim.treesitter.start)
|
||||
pcall(function()
|
||||
vim.bo.indentexpr = "v:lua.vim.treesitter.indentexpr()"
|
||||
end)
|
||||
end,
|
||||
})
|
||||
|
||||
local ok_tot, _ = pcall(require, "nvim-treesitter-textobjects")
|
||||
if ok_tot then
|
||||
local select = require("nvim-treesitter-textobjects.select")
|
||||
vim.keymap.set({ "x", "o" }, "af", function() select.select_textobject("@function.outer", "textobjects") end)
|
||||
vim.keymap.set({ "x", "o" }, "if", function() select.select_textobject("@function.inner", "textobjects") end)
|
||||
vim.keymap.set({ "x", "o" }, "ac", function() select.select_textobject("@class.outer", "textobjects") end)
|
||||
vim.keymap.set({ "x", "o" }, "ic", function() select.select_textobject("@class.inner", "textobjects") end)
|
||||
end
|
||||
|
||||
setup_plugin("mason")
|
||||
-- Automatically install these tools via Mason
|
||||
local registry = require("mason-registry")
|
||||
local ensure_installed = {
|
||||
"bash-language-server",
|
||||
"clang-format",
|
||||
"clangd",
|
||||
"java-debug-adapter",
|
||||
"jdtls",
|
||||
"json-lsp",
|
||||
"lua-language-server",
|
||||
"rust-analyzer",
|
||||
"svelte-language-server",
|
||||
"tailwindcss-language-server",
|
||||
"taplo",
|
||||
"typescript-language-server",
|
||||
"pylsp",
|
||||
"black",
|
||||
"vala"
|
||||
}
|
||||
|
||||
-- Refresh the registry and install missing tools
|
||||
registry.refresh(function()
|
||||
for _, tool in ipairs(ensure_installed) do
|
||||
local ok, pkg = pcall(registry.get_package, tool)
|
||||
if ok and not pkg:is_installed() then
|
||||
pkg:install()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
setup_plugin("lualine", { options = { theme = "gruvbox_dark" } })
|
||||
setup_plugin("typst-preview")
|
||||
setup_plugin("autoclose")
|
||||
setup_plugin("trouble")
|
||||
setup_plugin("Comment")
|
||||
|
||||
-- PLUGINS END --
|
||||
|
||||
-- DAP START --
|
||||
|
||||
local ok_dap, dap = pcall(require, "dap")
|
||||
local ok_dapui, dapui = pcall(require, "dapui")
|
||||
|
||||
if ok_dap and ok_dapui then
|
||||
dapui.setup()
|
||||
dap.listeners.before.attach.dapui_config = function() dapui.open() end
|
||||
dap.listeners.before.launch.dapui_config = function() dapui.open() end
|
||||
end
|
||||
|
||||
-- DAP END --
|
||||
|
||||
-- LSP START --
|
||||
|
||||
-- Assuming vim.lsp.enable is native to your specific Neovim version
|
||||
vim.lsp.enable({
|
||||
"lua_ls", "ts_ls", "svelte", "tailwindcss", "cssls", "bashls",
|
||||
"rust_analyzer", "clangd", "clang-format", "taplo",
|
||||
"sourcekit", "lemminx", "tinymist", "jsonls", "hls", "ormolu", "pylsp", "black", "vala_ls"
|
||||
})
|
||||
|
||||
vim.lsp.config["sourcekit"] = {
|
||||
filetypes = { "swift", "objective-c", "objective-c++" }
|
||||
}
|
||||
|
||||
vim.lsp.config["tinymist"] = {
|
||||
cmd = { "tinymist" },
|
||||
filetypes = { "typst" },
|
||||
settings = {
|
||||
formatterMode = "typstyle",
|
||||
},
|
||||
}
|
||||
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = 'java',
|
||||
callback = function(args)
|
||||
-- Safely require jdtls so it doesn't crash if uninstalled
|
||||
local ok, jdtls = pcall(require, "jdtls")
|
||||
if not ok then return end
|
||||
|
||||
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 = {
|
||||
cmd = {
|
||||
"java",
|
||||
"-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.v20251111-0406.jar",
|
||||
"-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"),
|
||||
"-data", workspace_dir,
|
||||
},
|
||||
root_dir = require("jdtls.setup").find_root({ ".git", "mvnw", "gradlew" }),
|
||||
settings = { java = {} },
|
||||
init_options = {
|
||||
bundles = { vim.fn.glob("/home/jannikdonker/.local/share/nvim/mason/share/java-debug-adapter/com.microsoft.java.debug.plugin.jar", 1) },
|
||||
},
|
||||
}
|
||||
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>")
|
||||
|
||||
-- Wrapped DAP calls in anonymous functions so they don't evaluate before DAP installs
|
||||
map.set("n", "<leader>duo", function() require("dapui").open() end)
|
||||
map.set("n", "<leader>duc", function() require("dapui").close() end)
|
||||
map.set("n", "<leader>dbp", function() require("dap").toggle_breakpoint() end)
|
||||
map.set("n", "<leader>drc", function() require("dap").run_to_cursor() end)
|
||||
|
||||
local is_mac = vim.fn.has("macunix") == 1
|
||||
local barbarKey = is_mac and "M" or "A"
|
||||
|
||||
map.set('n', '<' .. barbarKey .. '-,>', '<Cmd>BufferPrevious<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-.>', '<Cmd>BufferNext<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-<>', '<Cmd>BufferMovePrevious<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '->>', '<Cmd>BufferMoveNext<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-1>', '<Cmd>BufferGoto 1<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-2>', '<Cmd>BufferGoto 2<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-3>', '<Cmd>BufferGoto 3<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-4>', '<Cmd>BufferGoto 4<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-5>', '<Cmd>BufferGoto 5<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-6>', '<Cmd>BufferGoto 6<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-7>', '<Cmd>BufferGoto 7<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-8>', '<Cmd>BufferGoto 8<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-9>', '<Cmd>BufferGoto 9<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-0>', '<Cmd>BufferLast<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-p>', '<Cmd>BufferPin<CR>', opts)
|
||||
map.set('n', '<' .. barbarKey .. '-w>', '<Cmd>BufferClose<CR>', opts)
|
||||
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,
|
||||
})
|
||||
|
||||
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" })
|
||||
|
||||
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" })
|
||||
require("options")
|
||||
require("plugins")
|
||||
require("lsp")
|
||||
require("keymaps")
|
||||
|
||||
Reference in New Issue
Block a user