diff options
| author | Thomas Schmucker <ts@its1.de> | 2025-12-22 17:37:13 +0100 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2025-12-22 17:37:13 +0100 |
| commit | e8bd36899b88285c94c850f0dfce0754d94cfe24 (patch) | |
| tree | aa857a427db278888233ab03cad59b138d16eaa8 /nvim/lua/config | |
| parent | 6f6457b7397247a34e25d4d9bfca434d8306283e (diff) | |
| download | dotfiles-e8bd36899b88285c94c850f0dfce0754d94cfe24.tar.gz dotfiles-e8bd36899b88285c94c850f0dfce0754d94cfe24.tar.bz2 dotfiles-e8bd36899b88285c94c850f0dfce0754d94cfe24.zip | |
Neovim: Neue Konfiguration
Diffstat (limited to 'nvim/lua/config')
| -rw-r--r-- | nvim/lua/config/autocmds.lua | 56 | ||||
| -rw-r--r-- | nvim/lua/config/keymaps.lua | 94 | ||||
| -rw-r--r-- | nvim/lua/config/lazy.lua | 29 | ||||
| -rw-r--r-- | nvim/lua/config/options.lua | 110 |
4 files changed, 289 insertions, 0 deletions
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 @@ | |||
| 1 | -- https://github.com/nvim-treesitter/nvim-treesitter/blob/main/doc/nvim-treesitter.txt | ||
| 2 | vim.api.nvim_create_autocmd('FileType', { | ||
| 3 | pattern = { "c", "cpp", "lua", "typescript" }, | ||
| 4 | callback = function() | ||
| 5 | vim.treesitter.start() | ||
| 6 | vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()' | ||
| 7 | vim.wo.foldmethod = 'expr' | ||
| 8 | vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" | ||
| 9 | end, | ||
| 10 | }) | ||
| 11 | |||
| 12 | -- https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup | ||
| 13 | vim.api.nvim_create_autocmd("VimEnter", { | ||
| 14 | callback = function(data) | ||
| 15 | -- buffer is a real file on the disk | ||
| 16 | local real_file = vim.fn.filereadable(data.file) == 1 | ||
| 17 | |||
| 18 | -- buffer is a [No Name] | ||
| 19 | local no_name = data.file == "" and vim.bo[data.buf].buftype == "" | ||
| 20 | |||
| 21 | if not real_file and not no_name then | ||
| 22 | return | ||
| 23 | end | ||
| 24 | |||
| 25 | -- open the tree, find the file but don't focus it | ||
| 26 | require("nvim-tree.api").tree.toggle({ focus = false, find_file = true, }) | ||
| 27 | end | ||
| 28 | }) | ||
| 29 | |||
| 30 | -- https://github.com/nvim-tree/nvim-tree.lua/wiki/Auto-Close | ||
| 31 | vim.api.nvim_create_autocmd("QuitPre", { | ||
| 32 | callback = function() | ||
| 33 | local invalid_win = {} | ||
| 34 | local wins = vim.api.nvim_list_wins() | ||
| 35 | |||
| 36 | for _, w in ipairs(wins) do | ||
| 37 | local bufname = vim.api.nvim_buf_get_name(vim.api.nvim_win_get_buf(w)) | ||
| 38 | if bufname:match("NvimTree_") ~= nil then | ||
| 39 | table.insert(invalid_win, w) | ||
| 40 | end | ||
| 41 | end | ||
| 42 | |||
| 43 | if #invalid_win == #wins - 1 then | ||
| 44 | -- Should quit, so we close all invalid windows. | ||
| 45 | for _, w in ipairs(invalid_win) do vim.api.nvim_win_close(w, true) end | ||
| 46 | end | ||
| 47 | end | ||
| 48 | }) | ||
| 49 | |||
| 50 | vim.api.nvim_create_autocmd("LspAttach", { | ||
| 51 | callback = function(event) | ||
| 52 | local client = vim.lsp.get_client_by_id(event.data.client_id) | ||
| 53 | local keymaps = require("config.keymaps") | ||
| 54 | keymaps.lsp(event.buf, client) | ||
| 55 | end, | ||
| 56 | }) | ||
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 @@ | |||
| 1 | local M = {} | ||
| 2 | |||
| 3 | local map = vim.keymap.set | ||
| 4 | |||
| 5 | function M.lsp(buffer, client) | ||
| 6 | local opts = { | ||
| 7 | buffer = buffer, | ||
| 8 | noremap = true, | ||
| 9 | silent = true, | ||
| 10 | } | ||
| 11 | |||
| 12 | map("n", "gd", vim.lsp.buf.definition, opts) | ||
| 13 | map("n", "gD", vim.lsp.buf.declaration, opts) | ||
| 14 | map("n", "gr", vim.lsp.buf.references, opts) | ||
| 15 | map("n", "gi", vim.lsp.buf.implementation, opts) | ||
| 16 | map("n", "K", vim.lsp.buf.hover, opts) | ||
| 17 | map("n", "<leader>rn", vim.lsp.buf.rename, opts) | ||
| 18 | map("n", "<leader>ca", vim.lsp.buf.code_action, opts) | ||
| 19 | map("n", "<leader>cf", function() vim.lsp.buf.format({ async = true; }) end, opts) | ||
| 20 | |||
| 21 | if client and client.name == "clangd" then | ||
| 22 | map("n", "<leader>hs", "<cmd>ClangdSwitchSourceHeader<cr>", opts) | ||
| 23 | end | ||
| 24 | end | ||
| 25 | |||
| 26 | function M.telescope() | ||
| 27 | local opts = { | ||
| 28 | noremap = true, | ||
| 29 | silent = true, | ||
| 30 | } | ||
| 31 | |||
| 32 | map("n", "<leader>ff", function() | ||
| 33 | require("telescope.builtin").find_files() | ||
| 34 | end, opts) | ||
| 35 | |||
| 36 | map("n", "<leader>fg", function() | ||
| 37 | require("telescope.builtin").live_grep() | ||
| 38 | end, opts) | ||
| 39 | |||
| 40 | map("n", "<leader>fb", function() | ||
| 41 | require("telescope.builtin").buffers() | ||
| 42 | end, opts) | ||
| 43 | |||
| 44 | map("n", "<leader>fh", function() | ||
| 45 | require("telescope.builtin").help_tags() | ||
| 46 | end, opts) | ||
| 47 | |||
| 48 | map("n", "<leader>dd", function() | ||
| 49 | require("telescope.builtin").diagnostics() | ||
| 50 | end, opts) | ||
| 51 | end | ||
| 52 | |||
| 53 | function M.global() | ||
| 54 | local opts = { | ||
| 55 | noremap = true, | ||
| 56 | silent = true, | ||
| 57 | } | ||
| 58 | |||
| 59 | map("n", "ö", "}", opts) | ||
| 60 | map("n", "ä", "{", opts) | ||
| 61 | |||
| 62 | map("n", "<leader>K", function() | ||
| 63 | vim.diagnostic.open_float({ scope = "cursor", border = "rounded" }) | ||
| 64 | end, opts) | ||
| 65 | map("n", "<leader>q", vim.diagnostic.setloclist, opts) | ||
| 66 | |||
| 67 | map("n", "[d", function() | ||
| 68 | vim.diagnostic.jump_prev({ wrap = false }) | ||
| 69 | end, opts) | ||
| 70 | |||
| 71 | map("n", "]d", function() | ||
| 72 | vim.diagnostic.jump_next({ wrap = false }) | ||
| 73 | end, opts) | ||
| 74 | |||
| 75 | map("n", "[e", function() | ||
| 76 | vim.diagnostic.jump_prev({ | ||
| 77 | severity = vim.diagnostic.severity.ERROR, | ||
| 78 | wrap = false | ||
| 79 | }) | ||
| 80 | end, opts) | ||
| 81 | |||
| 82 | map("n", "]e", function() | ||
| 83 | vim.diagnostic.jump_next({ | ||
| 84 | severity = vim.diagnostic.severity.ERROR, | ||
| 85 | wrap = false | ||
| 86 | }) | ||
| 87 | end, opts) | ||
| 88 | |||
| 89 | vim.keymap.set("n", "<leader>ts", function() | ||
| 90 | vim.opt_local.spell = not vim.opt_local.spell:get() | ||
| 91 | end, { desc = "Toggle spell checking" }) | ||
| 92 | end | ||
| 93 | |||
| 94 | 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 @@ | |||
| 1 | -- https://lazy.folke.io/installation | ||
| 2 | |||
| 3 | local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" | ||
| 4 | if not (vim.uv or vim.loop).fs_stat(lazypath) then | ||
| 5 | local lazyrepo = "https://github.com/folke/lazy.nvim.git" | ||
| 6 | local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) | ||
| 7 | if vim.v.shell_error ~= 0 then | ||
| 8 | vim.api.nvim_echo({ | ||
| 9 | { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, | ||
| 10 | { out, "WarningMsg" }, | ||
| 11 | { "\nPress any key to exit..." }, | ||
| 12 | }, true, {}) | ||
| 13 | vim.fn.getchar() | ||
| 14 | os.exit(1) | ||
| 15 | end | ||
| 16 | end | ||
| 17 | vim.opt.rtp:prepend(lazypath) | ||
| 18 | |||
| 19 | require("lazy").setup({ | ||
| 20 | spec = { | ||
| 21 | { import = "plugins" }, | ||
| 22 | }, | ||
| 23 | checker = { | ||
| 24 | enabled = true | ||
| 25 | }, | ||
| 26 | rocks = { | ||
| 27 | enabled = false, | ||
| 28 | }, | ||
| 29 | }) | ||
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 @@ | |||
| 1 | local opt = vim.opt | ||
| 2 | local g = vim.g | ||
| 3 | |||
| 4 | -- Allgemeine Einstellungen | ||
| 5 | opt.number = true | ||
| 6 | opt.cursorline = true | ||
| 7 | opt.shortmess:append("I") | ||
| 8 | opt.wrap = false | ||
| 9 | opt.wildmenu = true | ||
| 10 | opt.splitright = true | ||
| 11 | opt.splitbelow = true | ||
| 12 | opt.signcolumn = "yes" | ||
| 13 | opt.termguicolors = true | ||
| 14 | |||
| 15 | -- Rechtschreibprüfung | ||
| 16 | opt.spelllang = { "de", "en" } | ||
| 17 | opt.spell = true | ||
| 18 | |||
| 19 | -- Optionen für ^n-Vervollständigung | ||
| 20 | opt.complete = { ".", "w", "b", "u", "t", "i" } | ||
| 21 | |||
| 22 | -- bessere Suche | ||
| 23 | opt.hlsearch = true | ||
| 24 | opt.incsearch = true | ||
| 25 | opt.ignorecase = true | ||
| 26 | opt.smartcase = true | ||
| 27 | |||
| 28 | -- Sonderzeichen anzeigen | ||
| 29 | opt.list = true | ||
| 30 | opt.listchars = { | ||
| 31 | tab = "> ", | ||
| 32 | trail = "-", | ||
| 33 | extends = ">", | ||
| 34 | precedes = "<", | ||
| 35 | nbsp = "+" | ||
| 36 | } | ||
| 37 | opt.matchpairs:append("<:>") | ||
| 38 | |||
| 39 | -- automatisches Einlesen geänderter Dateien | ||
| 40 | opt.autoread = true | ||
| 41 | |||
| 42 | -- Suche rekursiv | ||
| 43 | opt.path:append("**") | ||
| 44 | |||
| 45 | -- Tabs | ||
| 46 | opt.expandtab = false | ||
| 47 | opt.tabstop = 4 | ||
| 48 | opt.shiftwidth = 4 | ||
| 49 | opt.softtabstop = 0 | ||
| 50 | |||
| 51 | -- Einrückungen | ||
| 52 | opt.smartindent = true | ||
| 53 | opt.autoindent = true | ||
| 54 | opt.cindent = true | ||
| 55 | |||
| 56 | -- Faltungen | ||
| 57 | opt.foldlevel = 1000 | ||
| 58 | opt.foldcolumn = "0" | ||
| 59 | |||
| 60 | -- Autovervollständigung | ||
| 61 | opt.completeopt = { "longest", "menuone", "noselect", "popup" } | ||
| 62 | |||
| 63 | -- externe Programme | ||
| 64 | opt.makeprg = "gmake" | ||
| 65 | opt.autowrite = true | ||
| 66 | |||
| 67 | -- Guifont | ||
| 68 | opt.guifont = "JetBrains Mono Semibold:h12" | ||
| 69 | |||
| 70 | -- Provider | ||
| 71 | g.python3_host_prog = "/usr/local/bin/python" | ||
| 72 | |||
| 73 | -- Provider aeaktivieren | ||
| 74 | g.loaded_node_provider = 0 | ||
| 75 | g.loaded_ruby_provider = 0 | ||
| 76 | g.loaded_perl_provider = 0 | ||
| 77 | g.loaded_luarocks_provider = 0 | ||
| 78 | |||
| 79 | -- Swap files und Undo | ||
| 80 | opt.swapfile = false | ||
| 81 | opt.undofile = true | ||
| 82 | opt.undolevels = 10000 | ||
| 83 | opt.undoreload = 10000 | ||
| 84 | |||
| 85 | -- Clipboard | ||
| 86 | opt.clipboard = "unnamedplus" | ||
| 87 | |||
| 88 | -- netrw deaktivieren | ||
| 89 | g.loaded_netrw = 1 | ||
| 90 | g.loaded_netrwPlugin = 1 | ||
| 91 | |||
| 92 | g.mapleader = "," | ||
| 93 | g.maplocalleader = "\\" | ||
| 94 | |||
| 95 | vim.diagnostic.config({ | ||
| 96 | virtual_text = true, | ||
| 97 | signs = true, | ||
| 98 | underline = true, | ||
| 99 | update_in_insert = false, | ||
| 100 | severity_sort = true, | ||
| 101 | float = { border = "rounded" }, | ||
| 102 | }) | ||
| 103 | |||
| 104 | vim.lsp.util.open_floating_preview = (function(orig) | ||
| 105 | return function(contents, syntax, opts, ...) | ||
| 106 | opts = opts or {} | ||
| 107 | opts.border = opts.border or "rounded" | ||
| 108 | return orig(contents, syntax, opts, ...) | ||
| 109 | end | ||
| 110 | end)(vim.lsp.util.open_floating_preview) | ||
