From 824ff4437041b1a350113a08fdb8be68b7b098e5 Mon Sep 17 00:00:00 2001 From: rene Date: Tue, 16 Dec 2025 17:38:54 +0100 Subject: [PATCH] feat: Neovim config mit LSP, Treesitter und PlatformIO --- nvim/init.lua | 26 ++++++++ nvim/install-nvim-dotfiles.sh | 78 ++++++++++++++++++++++ nvim/lazy-lock.json | 22 +++++++ nvim/lua/plugins/editor.lua | 50 ++++++++++++++ nvim/lua/plugins/init.lua | 1 + nvim/lua/plugins/lsp.lua | 106 ++++++++++++++++++++++++++++++ nvim/lua/plugins/platformio.lua | 31 +++++++++ nvim/lua/plugins/plugins-init.lua | 1 + nvim/nvim-init.lua | 30 +++++++++ 9 files changed, 345 insertions(+) create mode 100644 nvim/init.lua create mode 100644 nvim/install-nvim-dotfiles.sh create mode 100644 nvim/lazy-lock.json create mode 100644 nvim/lua/plugins/editor.lua create mode 100644 nvim/lua/plugins/init.lua create mode 100644 nvim/lua/plugins/lsp.lua create mode 100644 nvim/lua/plugins/platformio.lua create mode 100644 nvim/lua/plugins/plugins-init.lua create mode 100644 nvim/nvim-init.lua diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..b12c24d --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,26 @@ +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.tabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.expandtab = true +vim.opt.termguicolors = true +vim.opt.signcolumn = 'yes' +vim.opt.updatetime = 250 +vim.opt.clipboard = 'unnamedplus' + +vim.g.python3_host_prog = '/Users/rene/miniconda3/bin/python3' + +local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + 'git', 'clone', '--filter=blob:none', + 'https://github.com/folke/lazy.nvim.git', + '--branch=stable', lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +require('lazy').setup('plugins') diff --git a/nvim/install-nvim-dotfiles.sh b/nvim/install-nvim-dotfiles.sh new file mode 100644 index 0000000..2779c1a --- /dev/null +++ b/nvim/install-nvim-dotfiles.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +# Neovim Dotfiles Installer +# Erstellt Symlink und installiert Abhängigkeiten + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +NVIM_CONFIG="$HOME/.config/nvim" + +echo "=== Neovim Dotfiles Installer ===" + +# Prüfe ob Neovim installiert ist +if ! command -v nvim &> /dev/null; then + echo "Neovim nicht gefunden!" + echo "Installation:" + echo " macOS: brew install neovim" + echo " Debian: sudo apt install neovim" + exit 1 +fi + +# Backup falls Config existiert +if [ -e "$NVIM_CONFIG" ] && [ ! -L "$NVIM_CONFIG" ]; then + echo "Bestehende Config gefunden, erstelle Backup..." + mv "$NVIM_CONFIG" "$NVIM_CONFIG.bak.$(date +%Y%m%d%H%M%S)" +fi + +# Entferne alten Symlink falls vorhanden +if [ -L "$NVIM_CONFIG" ]; then + echo "Entferne alten Symlink..." + rm "$NVIM_CONFIG" +fi + +# Erstelle .config falls nicht vorhanden +mkdir -p "$HOME/.config" + +# Symlink erstellen +echo "Erstelle Symlink: $NVIM_CONFIG -> $SCRIPT_DIR" +ln -s "$SCRIPT_DIR" "$NVIM_CONFIG" + +# Abhängigkeiten prüfen/installieren +echo "" +echo "=== Empfohlene Abhängigkeiten ===" + +if command -v brew &> /dev/null; then + # macOS + echo "macOS erkannt, prüfe Homebrew-Pakete..." + + PACKAGES="ripgrep fd node" + for pkg in $PACKAGES; do + if ! brew list $pkg &> /dev/null; then + echo "Installiere $pkg..." + brew install $pkg + else + echo "✓ $pkg bereits installiert" + fi + done +elif command -v apt &> /dev/null; then + # Debian/Ubuntu + echo "Debian/Ubuntu erkannt" + echo "Empfohlene Pakete: ripgrep fd-find nodejs npm" + echo " sudo apt install ripgrep fd-find nodejs npm" +fi + +echo "" +echo "=== Installation abgeschlossen ===" +echo "Starte nvim – Plugins werden automatisch installiert." +echo "" +echo "Shortcuts:" +echo " Space + e Dateibaum" +echo " Space + ff Dateien suchen" +echo " Space + fg Text suchen" +echo " Space + pb PlatformIO Build" +echo " Space + pu PlatformIO Upload" +echo " Space + pm Serial Monitor" +echo " Ctrl + t Terminal toggle" +echo " gd Gehe zur Definition" +echo " K Hover/Dokumentation" diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json new file mode 100644 index 0000000..02d93b1 --- /dev/null +++ b/nvim/lazy-lock.json @@ -0,0 +1,22 @@ +{ + "LuaSnip": { "branch": "master", "commit": "3732756842a2f7e0e76a7b0487e9692072857277" }, + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" }, + "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "gitsigns.nvim": { "branch": "main", "commit": "5813e4878748805f1518cee7abb50fd7205a3a48" }, + "lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" }, + "lualine.nvim": { "branch": "master", "commit": "47f91c416daef12db467145e16bed5bbfe00add8" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "3b3571b4dadbcb464804466e9872e7246c316af7" }, + "mason.nvim": { "branch": "main", "commit": "57e5a8addb8c71fb063ee4acda466c7cf6ad2800" }, + "nvim-cmp": { "branch": "main", "commit": "d97d85e01339f01b842e6ec1502f639b080cb0fc" }, + "nvim-lspconfig": { "branch": "master", "commit": "ad95655ec5d13ff7c728d731eb9fd39f34395a03" }, + "nvim-tree.lua": { "branch": "master", "commit": "eb33612bff2fb31f54946fb5dcadc89e905e81ec" }, + "nvim-treesitter": { "branch": "main", "commit": "d3218d988f72ed34414959c9ccd802d393432d6e" }, + "nvim-web-devicons": { "branch": "master", "commit": "8dcb311b0c92d460fac00eac706abd43d94d68af" }, + "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "telescope.nvim": { "branch": "master", "commit": "3d757e586ff0bfc85bdb7b46c9d3d932147a0cde" }, + "toggleterm.nvim": { "branch": "main", "commit": "50ea089fc548917cc3cc16b46a8211833b9e3c7c" }, + "tokyonight.nvim": { "branch": "main", "commit": "5da1b76e64daf4c5d410f06bcb6b9cb640da7dfd" }, + "which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" } +} diff --git a/nvim/lua/plugins/editor.lua b/nvim/lua/plugins/editor.lua new file mode 100644 index 0000000..163d8bf --- /dev/null +++ b/nvim/lua/plugins/editor.lua @@ -0,0 +1,50 @@ +return { + -- Farbschema + { + 'folke/tokyonight.nvim', + priority = 1000, + config = function() + vim.cmd.colorscheme('tokyonight-night') + end, + }, + + -- Statusleiste + { + 'nvim-lualine/lualine.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function() + require('lualine').setup() + end, + }, + + -- Dateibaum + { + 'nvim-tree/nvim-tree.lua', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + keys = { + { 'e', 'NvimTreeToggle', desc = 'Dateibaum' }, + }, + config = function() + require('nvim-tree').setup() + end, + }, + + -- Fuzzy Finder + { + 'nvim-telescope/telescope.nvim', + dependencies = { 'nvim-lua/plenary.nvim' }, + keys = { + { 'ff', 'Telescope find_files', desc = 'Dateien suchen' }, + { 'fg', 'Telescope live_grep', desc = 'Text suchen' }, + { 'fb', 'Telescope buffers', desc = 'Buffers' }, + }, + }, + + -- Git Integration + { + 'lewis6991/gitsigns.nvim', + config = function() + require('gitsigns').setup() + end, + }, +} diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/nvim/lua/plugins/init.lua @@ -0,0 +1 @@ +return {} diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..d1360dc --- /dev/null +++ b/nvim/lua/plugins/lsp.lua @@ -0,0 +1,106 @@ +return { + -- Syntax Highlighting + { + 'nvim-treesitter/nvim-treesitter', + build = ':TSUpdate', + config = function() + vim.treesitter.language.register('markdown', 'mdx') + -- Parser installieren + local parsers = { 'lua', 'python', 'c', 'cpp', 'json', 'yaml', 'markdown', 'bash' } + for _, parser in ipairs(parsers) do + pcall(function() + vim.treesitter.start(0, parser) + end) + end + -- Highlight aktivieren + vim.api.nvim_create_autocmd('FileType', { + pattern = '*', + callback = function() + pcall(vim.treesitter.start) + end, + }) + end, + }, + + -- Mason für LSP Installation + { + 'williamboman/mason.nvim', + config = function() + require('mason').setup() + end, + }, + + { + 'williamboman/mason-lspconfig.nvim', + dependencies = { 'williamboman/mason.nvim' }, + config = function() + require('mason-lspconfig').setup({ + ensure_installed = { 'pyright', 'lua_ls', 'clangd' }, + }) + end, + }, + + -- LSP Config (mit neuer API für nvim 0.11) + { + 'neovim/nvim-lspconfig', + dependencies = { 'williamboman/mason-lspconfig.nvim' }, + config = function() + -- Keymaps wenn LSP attached + vim.api.nvim_create_autocmd('LspAttach', { + callback = function(args) + local opts = { buffer = args.buf } + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, opts) + end, + }) + + -- LSP Server aktivieren + vim.lsp.enable('pyright') + vim.lsp.enable('lua_ls') + vim.lsp.enable('clangd') + end, + }, + + -- Autovervollständigung + { + 'hrsh7th/nvim-cmp', + dependencies = { + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'L3MON4D3/LuaSnip', + 'saadparwaiz1/cmp_luasnip', + }, + config = function() + local cmp = require('cmp') + local luasnip = require('luasnip') + + cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, { 'i', 's' }), + }), + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'buffer' }, + { name = 'path' }, + }, + }) + end, + }, +} diff --git a/nvim/lua/plugins/platformio.lua b/nvim/lua/plugins/platformio.lua new file mode 100644 index 0000000..41e2852 --- /dev/null +++ b/nvim/lua/plugins/platformio.lua @@ -0,0 +1,31 @@ +return { + -- Terminal Toggle + { + 'akinsho/toggleterm.nvim', + version = '*', + opts = { + size = 15, + open_mapping = [[]], + direction = 'float', + }, + }, + + -- PlatformIO Keymaps (custom) + { + 'folke/which-key.nvim', + config = function() + local wk = require('which-key') + wk.setup() + + -- PlatformIO Befehle + wk.add({ + { 'p', group = 'PlatformIO' }, + { 'pb', '!pio run', desc = 'Build' }, + { 'pu', '!pio run -t upload', desc = 'Upload' }, + { 'pc', '!pio run -t clean', desc = 'Clean' }, + { 'pm', 'TermExec cmd="pio device monitor"', desc = 'Serial Monitor' }, + { 'pi', '!pio init', desc = 'Init Project' }, + }) + end, + }, +} diff --git a/nvim/lua/plugins/plugins-init.lua b/nvim/lua/plugins/plugins-init.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/nvim/lua/plugins/plugins-init.lua @@ -0,0 +1 @@ +return {} diff --git a/nvim/nvim-init.lua b/nvim/nvim-init.lua new file mode 100644 index 0000000..827518c --- /dev/null +++ b/nvim/nvim-init.lua @@ -0,0 +1,30 @@ +-- Grundeinstellungen +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.tabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.expandtab = true +vim.opt.termguicolors = true +vim.opt.signcolumn = 'yes' +vim.opt.updatetime = 250 +vim.opt.clipboard = 'unnamedplus' + +-- Python für Neovim +vim.g.python3_host_prog = '/Users/rene/miniconda3/bin/python3' + +-- lazy.nvim Bootstrap +local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + 'git', 'clone', '--filter=blob:none', + 'https://github.com/folke/lazy.nvim.git', + '--branch=stable', lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +-- Plugins laden +require('lazy').setup('plugins')