aboutsummaryrefslogtreecommitdiff
path: root/nvim/lua/config
diff options
context:
space:
mode:
Diffstat (limited to 'nvim/lua/config')
-rw-r--r--nvim/lua/config/autocmds.lua56
-rw-r--r--nvim/lua/config/keymaps.lua94
-rw-r--r--nvim/lua/config/lazy.lua29
-rw-r--r--nvim/lua/config/options.lua110
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
2vim.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
13vim.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
31vim.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
50vim.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 @@
1local M = {}
2
3local map = vim.keymap.set
4
5function 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
24end
25
26function 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)
51end
52
53function 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" })
92end
93
94return 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
3local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
4if 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
16end
17vim.opt.rtp:prepend(lazypath)
18
19require("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 @@
1local opt = vim.opt
2local g = vim.g
3
4-- Allgemeine Einstellungen
5opt.number = true
6opt.cursorline = true
7opt.shortmess:append("I")
8opt.wrap = false
9opt.wildmenu = true
10opt.splitright = true
11opt.splitbelow = true
12opt.signcolumn = "yes"
13opt.termguicolors = true
14
15-- Rechtschreibprüfung
16opt.spelllang = { "de", "en" }
17opt.spell = true
18
19-- Optionen für ^n-Vervollständigung
20opt.complete = { ".", "w", "b", "u", "t", "i" }
21
22-- bessere Suche
23opt.hlsearch = true
24opt.incsearch = true
25opt.ignorecase = true
26opt.smartcase = true
27
28-- Sonderzeichen anzeigen
29opt.list = true
30opt.listchars = {
31 tab = "> ",
32 trail = "-",
33 extends = ">",
34 precedes = "<",
35 nbsp = "+"
36}
37opt.matchpairs:append("<:>")
38
39-- automatisches Einlesen geänderter Dateien
40opt.autoread = true
41
42-- Suche rekursiv
43opt.path:append("**")
44
45-- Tabs
46opt.expandtab = false
47opt.tabstop = 4
48opt.shiftwidth = 4
49opt.softtabstop = 0
50
51-- Einrückungen
52opt.smartindent = true
53opt.autoindent = true
54opt.cindent = true
55
56-- Faltungen
57opt.foldlevel = 1000
58opt.foldcolumn = "0"
59
60-- Autovervollständigung
61opt.completeopt = { "longest", "menuone", "noselect", "popup" }
62
63-- externe Programme
64opt.makeprg = "gmake"
65opt.autowrite = true
66
67-- Guifont
68opt.guifont = "JetBrains Mono Semibold:h12"
69
70-- Provider
71g.python3_host_prog = "/usr/local/bin/python"
72
73-- Provider aeaktivieren
74g.loaded_node_provider = 0
75g.loaded_ruby_provider = 0
76g.loaded_perl_provider = 0
77g.loaded_luarocks_provider = 0
78
79-- Swap files und Undo
80opt.swapfile = false
81opt.undofile = true
82opt.undolevels = 10000
83opt.undoreload = 10000
84
85-- Clipboard
86opt.clipboard = "unnamedplus"
87
88-- netrw deaktivieren
89g.loaded_netrw = 1
90g.loaded_netrwPlugin = 1
91
92g.mapleader = ","
93g.maplocalleader = "\\"
94
95vim.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
104vim.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
110end)(vim.lsp.util.open_floating_preview)