From e8bd36899b88285c94c850f0dfce0754d94cfe24 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Mon, 22 Dec 2025 17:37:13 +0100 Subject: Neovim: Neue Konfiguration --- nvim/ftplugin/lua.lua | 6 +++ nvim/init.lua | 8 +++ nvim/lua/config/autocmds.lua | 56 ++++++++++++++++++++ nvim/lua/config/keymaps.lua | 94 ++++++++++++++++++++++++++++++++++ nvim/lua/config/lazy.lua | 29 +++++++++++ nvim/lua/config/options.lua | 110 ++++++++++++++++++++++++++++++++++++++++ nvim/lua/plugins/editing.lua | 20 ++++++++ nvim/lua/plugins/git.lua | 7 +++ nvim/lua/plugins/lsp.lua | 29 +++++++++++ nvim/lua/plugins/telescope.lua | 9 ++++ nvim/lua/plugins/treesitter.lua | 29 +++++++++++ nvim/lua/plugins/ui.lua | 58 +++++++++++++++++++++ 12 files changed, 455 insertions(+) create mode 100644 nvim/ftplugin/lua.lua create mode 100644 nvim/init.lua create mode 100644 nvim/lua/config/autocmds.lua create mode 100644 nvim/lua/config/keymaps.lua create mode 100644 nvim/lua/config/lazy.lua create mode 100644 nvim/lua/config/options.lua create mode 100644 nvim/lua/plugins/editing.lua create mode 100644 nvim/lua/plugins/git.lua create mode 100644 nvim/lua/plugins/lsp.lua create mode 100644 nvim/lua/plugins/telescope.lua create mode 100644 nvim/lua/plugins/treesitter.lua create mode 100644 nvim/lua/plugins/ui.lua diff --git a/nvim/ftplugin/lua.lua b/nvim/ftplugin/lua.lua new file mode 100644 index 0000000..0883a50 --- /dev/null +++ b/nvim/ftplugin/lua.lua @@ -0,0 +1,6 @@ +local opt = vim.opt_local + +opt.expandtab = true +opt.shiftwidth = 2 +opt.tabstop = 2 +opt.softtabstop = 2 diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..d148f6b --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,8 @@ +require("config.options") + +local keymaps = require("config.keymaps") +keymaps.global() +keymaps.telescope() + +require("config.autocmds") +require("config.lazy") diff --git a/nvim/lua/config/autocmds.lua b/nvim/lua/config/autocmds.lua new file mode 100644 index 0000000..e11b231 --- /dev/null +++ b/nvim/lua/config/autocmds.lua @@ -0,0 +1,56 @@ +-- https://github.com/nvim-treesitter/nvim-treesitter/blob/main/doc/nvim-treesitter.txt +vim.api.nvim_create_autocmd('FileType', { + pattern = { "c", "cpp", "lua", "typescript" }, + callback = function() + vim.treesitter.start() + vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()' + vim.wo.foldmethod = 'expr' + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end, +}) + +-- https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup +vim.api.nvim_create_autocmd("VimEnter", { + callback = function(data) + -- buffer is a real file on the disk + local real_file = vim.fn.filereadable(data.file) == 1 + + -- buffer is a [No Name] + local no_name = data.file == "" and vim.bo[data.buf].buftype == "" + + if not real_file and not no_name then + return + end + + -- open the tree, find the file but don't focus it + require("nvim-tree.api").tree.toggle({ focus = false, find_file = true, }) + end +}) + +-- https://github.com/nvim-tree/nvim-tree.lua/wiki/Auto-Close +vim.api.nvim_create_autocmd("QuitPre", { + callback = function() + local invalid_win = {} + local wins = vim.api.nvim_list_wins() + + for _, w in ipairs(wins) do + local bufname = vim.api.nvim_buf_get_name(vim.api.nvim_win_get_buf(w)) + if bufname:match("NvimTree_") ~= nil then + table.insert(invalid_win, w) + end + end + + if #invalid_win == #wins - 1 then + -- Should quit, so we close all invalid windows. + for _, w in ipairs(invalid_win) do vim.api.nvim_win_close(w, true) end + end + end +}) + +vim.api.nvim_create_autocmd("LspAttach", { + callback = function(event) + local client = vim.lsp.get_client_by_id(event.data.client_id) + local keymaps = require("config.keymaps") + keymaps.lsp(event.buf, client) + end, +}) diff --git a/nvim/lua/config/keymaps.lua b/nvim/lua/config/keymaps.lua new file mode 100644 index 0000000..c54247c --- /dev/null +++ b/nvim/lua/config/keymaps.lua @@ -0,0 +1,94 @@ +local M = {} + +local map = vim.keymap.set + +function M.lsp(buffer, client) + local opts = { + buffer = buffer, + noremap = true, + silent = true, + } + + map("n", "gd", vim.lsp.buf.definition, opts) + map("n", "gD", vim.lsp.buf.declaration, opts) + map("n", "gr", vim.lsp.buf.references, opts) + map("n", "gi", vim.lsp.buf.implementation, opts) + map("n", "K", vim.lsp.buf.hover, opts) + map("n", "rn", vim.lsp.buf.rename, opts) + map("n", "ca", vim.lsp.buf.code_action, opts) + map("n", "cf", function() vim.lsp.buf.format({ async = true; }) end, opts) + + if client and client.name == "clangd" then + map("n", "hs", "ClangdSwitchSourceHeader", opts) + end +end + +function M.telescope() + local opts = { + noremap = true, + silent = true, + } + + map("n", "ff", function() + require("telescope.builtin").find_files() + end, opts) + + map("n", "fg", function() + require("telescope.builtin").live_grep() + end, opts) + + map("n", "fb", function() + require("telescope.builtin").buffers() + end, opts) + + map("n", "fh", function() + require("telescope.builtin").help_tags() + end, opts) + + map("n", "dd", function() + require("telescope.builtin").diagnostics() + end, opts) +end + +function M.global() + local opts = { + noremap = true, + silent = true, + } + + map("n", "ö", "}", opts) + map("n", "ä", "{", opts) + + map("n", "K", function() + vim.diagnostic.open_float({ scope = "cursor", border = "rounded" }) + end, opts) + map("n", "q", vim.diagnostic.setloclist, opts) + + map("n", "[d", function() + vim.diagnostic.jump_prev({ wrap = false }) + end, opts) + + map("n", "]d", function() + vim.diagnostic.jump_next({ wrap = false }) + end, opts) + + map("n", "[e", function() + vim.diagnostic.jump_prev({ + severity = vim.diagnostic.severity.ERROR, + wrap = false + }) + end, opts) + + map("n", "]e", function() + vim.diagnostic.jump_next({ + severity = vim.diagnostic.severity.ERROR, + wrap = false + }) + end, opts) + + vim.keymap.set("n", "ts", function() + vim.opt_local.spell = not vim.opt_local.spell:get() + end, { desc = "Toggle spell checking" }) +end + +return M diff --git a/nvim/lua/config/lazy.lua b/nvim/lua/config/lazy.lua new file mode 100644 index 0000000..c798b9d --- /dev/null +++ b/nvim/lua/config/lazy.lua @@ -0,0 +1,29 @@ +-- https://lazy.folke.io/installation + +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, {}) + vim.fn.getchar() + os.exit(1) + end +end +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup({ + spec = { + { import = "plugins" }, + }, + checker = { + enabled = true + }, + rocks = { + enabled = false, + }, +}) diff --git a/nvim/lua/config/options.lua b/nvim/lua/config/options.lua new file mode 100644 index 0000000..097e5d6 --- /dev/null +++ b/nvim/lua/config/options.lua @@ -0,0 +1,110 @@ +local opt = vim.opt +local g = vim.g + +-- Allgemeine Einstellungen +opt.number = true +opt.cursorline = true +opt.shortmess:append("I") +opt.wrap = false +opt.wildmenu = true +opt.splitright = true +opt.splitbelow = true +opt.signcolumn = "yes" +opt.termguicolors = true + +-- Rechtschreibprüfung +opt.spelllang = { "de", "en" } +opt.spell = true + +-- Optionen für ^n-Vervollständigung +opt.complete = { ".", "w", "b", "u", "t", "i" } + +-- bessere Suche +opt.hlsearch = true +opt.incsearch = true +opt.ignorecase = true +opt.smartcase = true + +-- Sonderzeichen anzeigen +opt.list = true +opt.listchars = { + tab = "> ", + trail = "-", + extends = ">", + precedes = "<", + nbsp = "+" +} +opt.matchpairs:append("<:>") + +-- automatisches Einlesen geänderter Dateien +opt.autoread = true + +-- Suche rekursiv +opt.path:append("**") + +-- Tabs +opt.expandtab = false +opt.tabstop = 4 +opt.shiftwidth = 4 +opt.softtabstop = 0 + +-- Einrückungen +opt.smartindent = true +opt.autoindent = true +opt.cindent = true + +-- Faltungen +opt.foldlevel = 1000 +opt.foldcolumn = "0" + +-- Autovervollständigung +opt.completeopt = { "longest", "menuone", "noselect", "popup" } + +-- externe Programme +opt.makeprg = "gmake" +opt.autowrite = true + +-- Guifont +opt.guifont = "JetBrains Mono Semibold:h12" + +-- Provider +g.python3_host_prog = "/usr/local/bin/python" + +-- Provider aeaktivieren +g.loaded_node_provider = 0 +g.loaded_ruby_provider = 0 +g.loaded_perl_provider = 0 +g.loaded_luarocks_provider = 0 + +-- Swap files und Undo +opt.swapfile = false +opt.undofile = true +opt.undolevels = 10000 +opt.undoreload = 10000 + +-- Clipboard +opt.clipboard = "unnamedplus" + +-- netrw deaktivieren +g.loaded_netrw = 1 +g.loaded_netrwPlugin = 1 + +g.mapleader = "," +g.maplocalleader = "\\" + +vim.diagnostic.config({ + virtual_text = true, + signs = true, + underline = true, + update_in_insert = false, + severity_sort = true, + float = { border = "rounded" }, +}) + +vim.lsp.util.open_floating_preview = (function(orig) + return function(contents, syntax, opts, ...) + opts = opts or {} + opts.border = opts.border or "rounded" + return orig(contents, syntax, opts, ...) + end +end)(vim.lsp.util.open_floating_preview) diff --git a/nvim/lua/plugins/editing.lua b/nvim/lua/plugins/editing.lua new file mode 100644 index 0000000..44f74c6 --- /dev/null +++ b/nvim/lua/plugins/editing.lua @@ -0,0 +1,20 @@ +return { + { "tpope/vim-repeat" }, + { "tpope/vim-surround" }, + + { + "romainl/vim-cool", + event = "VeryLazy", + }, + + { + "windwp/nvim-autopairs", + event = "InsertEnter", + config = true, + }, + + { + "windwp/nvim-ts-autotag", + event = "InsertEnter", + }, +} diff --git a/nvim/lua/plugins/git.lua b/nvim/lua/plugins/git.lua new file mode 100644 index 0000000..1fd2418 --- /dev/null +++ b/nvim/lua/plugins/git.lua @@ -0,0 +1,7 @@ +return { + { + "lewis6991/gitsigns.nvim", + event = { "BufReadPre", "BufNewFile" }, + config = true, + }, +} diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..e888ae0 --- /dev/null +++ b/nvim/lua/plugins/lsp.lua @@ -0,0 +1,29 @@ +return { + { + "neovim/nvim-lspconfig", + lazy = false, + config = function() + vim.lsp.config.lua_ls = { + settings = { + Lua = { + diagnostics = { + globals = { "vim" }, + }, + workspace = { + checkThirdParty = false, + library = { + vim.fn.expand("$VIMRUNTIME/lua"), + vim.fn.expand("$XDG_CONFIG_HOME") .. "/nvim/lua", + }, + }, + }, + }, + } + + vim.lsp.enable({ + "clangd", -- pkg install llvm + "lua_ls", -- pkg install lua-language-server + }) + end, + }, +} diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..7633892 --- /dev/null +++ b/nvim/lua/plugins/telescope.lua @@ -0,0 +1,9 @@ +return { + { + "nvim-telescope/telescope.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + }, + lazy = true, + }, +} diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua new file mode 100644 index 0000000..edcaff2 --- /dev/null +++ b/nvim/lua/plugins/treesitter.lua @@ -0,0 +1,29 @@ +-- https://github.com/nvim-treesitter/nvim-treesitter/blob/main/README.md + +return { + { + "nvim-treesitter/nvim-treesitter", + branch = "main", + build = ":TSUpdate", + lazy = false, + config = function() + local treesitter = require("nvim-treesitter") + + treesitter.setup({}) + + -- https://github.com/nvim-treesitter/nvim-treesitter/blob/main/SUPPORTED_LANGUAGES.md + treesitter.install({ + "c", + "cpp", + "html", + "python", + "vim", + "vimdoc", + "javascript", + "lua", + "typescript", + "vim", + }) + end, + }, +} diff --git a/nvim/lua/plugins/ui.lua b/nvim/lua/plugins/ui.lua new file mode 100644 index 0000000..10c4762 --- /dev/null +++ b/nvim/lua/plugins/ui.lua @@ -0,0 +1,58 @@ +return { + + { + "Mofiqul/vscode.nvim", + priority = 1000, -- wichtig: vor anderen UI-Plugins laden + lazy = false, + config = function() + local vscode = require("vscode") + + vscode.setup({ + style = "dark", + transparent = false, + italic_comments = true, + underline_links = true, + disable_nvimtree_bg = true, + }) + + vscode.load() + end, + }, + + { + "nvim-tree/nvim-tree.lua", + dependencies = { + "nvim-tree/nvim-web-devicons", + }, + cmd = { "NvimTreeToggle", "NvimTreeOpen" }, + keys = { + { "e", "NvimTreeToggle", desc = "Explorer toggle" }, + }, + config = function() + require("nvim-tree").setup({ + view = { + width = 30, + }, + renderer = { + highlight_git = true, + icons = { + show = { + file = true, + folder = true, + git = true, + }, + }, + }, + filters = { + dotfiles = false, + }, + }) + end, + }, + + { + "RRethy/vim-illuminate", + event = "BufReadPost", + }, + +} -- cgit v1.3