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/lua/config/autocmds.lua | 56 ++++++++++++++++++++++ nvim/lua/config/keymaps.lua | 94 ++++++++++++++++++++++++++++++++++++ nvim/lua/config/lazy.lua | 29 ++++++++++++ nvim/lua/config/options.lua | 110 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 289 insertions(+) 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 (limited to 'nvim/lua/config') 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) -- cgit v1.3