From 4a8f0841025f2eeb05809964c64a81c0bb399685 Mon Sep 17 00:00:00 2001 From: schererleander Date: Sat, 15 Nov 2025 22:23:50 +0100 Subject: use vim.pack and simplify configuration --- nvim/init.lua | 226 +++++++++++++++++++++++++++++---- nvim/lazy-lock.json | 24 ---- nvim/lua/autocmds.lua | 8 -- nvim/lua/keymaps.lua | 0 nvim/lua/options.lua | 45 ------- nvim/lua/plugins.lua | 343 -------------------------------------------------- 6 files changed, 205 insertions(+), 441 deletions(-) delete mode 100644 nvim/lazy-lock.json delete mode 100644 nvim/lua/autocmds.lua delete mode 100644 nvim/lua/keymaps.lua delete mode 100644 nvim/lua/options.lua delete mode 100644 nvim/lua/plugins.lua diff --git a/nvim/init.lua b/nvim/init.lua index ce942cb..985c11f 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,23 +1,207 @@ -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) - +-- General settings vim.g.mapleader = " " -vim.g.maplocalleader = "\\" +vim.o.number = true +vim.o.relativenumber = true +vim.o.signcolumn = "yes" +vim.o.termguicolors = true +vim.o.wrap = false +vim.o.tabstop = 2 +vim.o.shiftwidth = 2 +vim.o.updatetime = 250 +vim.o.timeoutlen = 300 +vim.o.swapfile = false +vim.o.ignorecase = true +vim.o.smartcase = true +vim.o.winborder = "rounded" +vim.o.clipboard = "unnamedplus" + +local map = vim.keymap.set +map('n', 'o', 'updatesource %', { desc = 'Save & reload init.lua' }) +map('n', 'w', 'write') +map('n', 'q', 'quit') +map('n', 'lf', vim.lsp.buf.format) + +vim.pack.add({ + { src = "https://github.com/ellisonleao/gruvbox.nvim" }, + { src = "https://github.com/echasnovski/mini.starter" }, + { src = "https://github.com/lewis6991/gitsigns.nvim" }, + { src = "https://github.com/windwp/nvim-autopairs" }, + { src = "https://github.com/nvim-telescope/telescope.nvim" }, + { src = "https://github.com/j-hui/fidget.nvim" }, + { src = "https://github.com/nvim-lua/plenary.nvim" }, + { src = "https://github.com/nvim-treesitter/nvim-treesitter" }, + { src = "https://github.com/neovim/nvim-lspconfig" }, + { src = "https://github.com/hrsh7th/nvim-cmp" }, + { src = "https://github.com/hrsh7th/cmp-nvim-lsp" }, + { src = "https://github.com/hrsh7th/cmp-buffer" }, + { src = "https://github.com/hrsh7th/cmp-path" }, + { src = "https://github.com/hrsh7th/cmp-cmdline" }, + { src = "https://github.com/L3MON4D3/LuaSnip" }, + { src = "https://github.com/saadparwaiz1/cmp_luasnip" }, + { src = "https://github.com/onsails/lspkind-nvim" } +}) + +require("nvim-treesitter.configs").setup({ + ensure_installed = { "lua", "nix" }, + highlight = { enable = true }, +}) + +local builtin = require('telescope.builtin') +map('n', 'ff', builtin.find_files, { desc = 'Telescope find files' }) +map('n', 'fg', builtin.live_grep, { desc = 'Telescope live grep' }) +map('n', 'fb', builtin.buffers, { desc = 'Telescope buffers' }) +map('n', 'fh', builtin.help_tags, { desc = 'Telescope help tags' }) + + +local cmp = require("cmp") +cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, { 'i', 's' }), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, { + { name = 'buffer' }, + }) +}) + +-- Add parentheses after selecting function or method +local cmp_autopairs = require('nvim-autopairs.completion.cmp') +cmp.event:on( + 'confirm_done', + cmp_autopairs.on_confirm_done() +) + +local capabilities = require('cmp_nvim_lsp').default_capabilities() + +require("lspconfig").nixd.setup({ + capabilities = capabilities, + settings = { + nixd = { + formatting = { + command = { "nixfmt" }, + }, + }, + }, +}) + +require("lspconfig").lua_ls.setup({ + capabilities = capabilities, + settings = { + lua_ls = { + formatting = { + command = { "luaformatter" }, + }, + }, + Lua = { + runtime = { + version = 'LuaJIT', + }, + +diagnostics = { + globals = { + 'vim', 'require' + }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + }, + telemetry = { + enable = false, + }, + }, + }, +}) + +require("lspconfig").pyright.setup({ + capabilities = capabilities, +}) + +require("lspconfig").ts_ls.setup({ + capabilities = capabilities, +}) + +require("lspconfig").tailwindcss.setup({ + capabilities = capabilities, +}) + +require("lspconfig").gopls.setup({ + capabilities = capabilities, + settings = { + gopls = { + analyses = { + unusedparams = true, + unusedwrite = true, + }, + staticcheck = true, + }, + }, +}) + +require("lspconfig").rust_analyzer.setup({ + capabilities = capabilities, +}) + +vim.diagnostic.config({ + virtual_text = { source = "if_many" }, + underline = true, + severity_sort = true, +}) + + +require("mini.starter").setup({ + header = table.concat({ + " /l、 ", + "(゚、 。 7 ", + " l ~ ヽ ", + " じしf_,)ノ ", + }, "\n"), + footer = "", + content_hooks = { + require("mini.starter").gen_hook.adding_bullet("» "), + require("mini.starter").gen_hook.aligning("center", "center"), + }, +}) + + +require("gitsigns").setup() +require("nvim-autopairs").setup() +require("fidget").setup() + +vim.cmd("colorscheme gruvbox") -require('options') -require('keymaps') -require('plugins') -require('autocmds') +local hl = vim.api.nvim_set_hl +hl(0, 'Normal', { bg = 'none' }) +hl(0, 'NormalFloat', { bg = 'none' }) +hl(0, 'NormalNC', { bg = 'none' }) +hl(0, 'StatusLine', { bg = 'none' }) +hl(0, 'SignColumn', { bg = 'none' }) +hl(0, "DiagnosticError", { bg = "none" }) +hl(0, "DiagnosticSignError", { bg = "none" }) +hl(0, "DiagnosticSignHint", { bg = "none" }) +hl(0, "DiagnosticSignInfo", { bg = "none" }) +hl(0, "DiagnosticSignWarn", { bg = "none" }) diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json deleted file mode 100644 index 83536d5..0000000 --- a/nvim/lazy-lock.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "LuaSnip": { "branch": "master", "commit": "a7a4b4682c4b3e2ba82b82a4e6e5f5a0e79dec32" }, - "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, - "cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, - "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, - "gitsigns.nvim": { "branch": "main", "commit": "4e348641b8206c3b8d23080999e3ddbe4ca90efc" }, - "gruvbox.nvim": { "branch": "main", "commit": "68c3460a5d1d1a362318960035c9f3466d5011f5" }, - "lazy.nvim": { "branch": "main", "commit": "83493db50a434a4c5c648faf41e2ead80f96e478" }, - "lspkind-nvim": { "branch": "master", "commit": "a700f1436d4a938b1a1a93c9962dc796afbaef4d" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "55716a879568a498fa236593c8119789054a3b8e" }, - "mason.nvim": { "branch": "main", "commit": "3b5068f0fc565f337d67a2d315d935f574848ee7" }, - "mini.nvim": { "branch": "main", "commit": "e025ee74705b04dd25a132a521c9c535dc78a8d8" }, - "nvim-autopairs": { "branch": "master", "commit": "ee297f215e95a60b01fde33275cc3c820eddeebe" }, - "nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" }, - "nvim-lint": { "branch": "master", "commit": "941fa1220a61797a51f3af9ec6b7d74c8c7367ce" }, - "nvim-lspconfig": { "branch": "master", "commit": "4bdd3800b4148f670c6cf55ef65f490148eeb550" }, - "nvim-treesitter": { "branch": "master", "commit": "0603b3e3d21ebe2fa82dc5361a3d500e0d3ad3a8" }, - "nvim-web-devicons": { "branch": "master", "commit": "75df79feb02d5e0ec114e447453775d4d291ea03" }, - "plenary.nvim": { "branch": "master", "commit": "f7adfc4b3f4f91aab6caebf42b3682945fbc35be" }, - "staline.nvim": { "branch": "main", "commit": "c49f2deaba3d3c669e7243b57619e0078e7a351b" }, - "telescope.nvim": { "branch": "master", "commit": "b323abeb4baf9e4851c3af1961e770ce76c657c7" }, - "toggleterm.nvim": { "branch": "main", "commit": "193786e0371e3286d3bc9aa0079da1cd41beaa62" } -} \ No newline at end of file diff --git a/nvim/lua/autocmds.lua b/nvim/lua/autocmds.lua deleted file mode 100644 index f7e6923..0000000 --- a/nvim/lua/autocmds.lua +++ /dev/null @@ -1,8 +0,0 @@ -vim.cmd('highlight WinSeparator guibg=None ctermbg=None') -vim.cmd('highlight VertSplit guibg=NONE ctermbg=NONE') --- hide background lsp coloum -vim.cmd('highlight SignColumn guibg=NONE ctermbg=None') - --- transparent background -vim.cmd('highlight Normal guibg=NONE ctermbg=NONE') -vim.cmd('highlight NormalNC guibg=NONE ctermbg=NONE') diff --git a/nvim/lua/keymaps.lua b/nvim/lua/keymaps.lua deleted file mode 100644 index e69de29..0000000 diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua deleted file mode 100644 index 891668f..0000000 --- a/nvim/lua/options.lua +++ /dev/null @@ -1,45 +0,0 @@ -local options = { - list = false, - backup = false, -- creates a backup file - clipboard = "unnamedplus", -- allows neovim to access the system clipboard - conceallevel = 2, -- so that `` is visible in markdown files - fileencoding = "utf-8", -- the encoding written to a file - hidden = true, -- required to keep multiple buffers and open multiple buffers - hlsearch = true, -- highlight all matches on previous search pattern - ignorecase = true, -- ignore case in search patterns - mouse = "a", -- allow the mouse to be used in neovim - laststatus = 3, - showmode = false, -- we don't need to see things like -- INSERT -- anymore - smartcase = true, -- smart case - smartindent = true, -- make indenting smarter again - splitbelow = true, -- force all horizontal splits to go below current window ↕️ - splitright = true, -- force all vertical splits to go to the right of current window ↔️ - swapfile = false, -- creates a swapfile - termguicolors = true, -- set term gui colors (most terminals support this) - timeoutlen = 100, -- time to wait for a mapped sequence to complete (in milliseconds) - undofile = true, -- enable persistent undo - updatetime = 300, -- faster completion (4000ms default) ⚡ - writebackup = false, -- if a file is being edited by another program, it is not allowed to be edited - expandtab = true, -- use tabs instead of spaces ␣ - pumheight = 10, - cmdheight = 2, - shiftwidth = 2, -- the number of spaces inserted for each indentation - tabstop = 2, -- insert 2 spaces for a tab ⇥ - cursorline = false, -- highlight the current line (disabled for now) - number = false, -- set numbered lines - relativenumber = false, -- set relative numbered lines - numberwidth = 4, -- set number column width to 2 (default 4) - wrap = false, -- display lines as one long lines -} - -vim.opt.shortmess:append 'c' - -for k, v in pairs(options) do - vim.opt[k] = v -end - -vim.wo.list = false -vim.cmd 'set whichwrap+=<,>,[,],h,l' - --- lazy load -vim.loader.enable() diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua deleted file mode 100644 index ff8c9a8..0000000 --- a/nvim/lua/plugins.lua +++ /dev/null @@ -1,343 +0,0 @@ -require("lazy").setup({ - { - "ellisonleao/gruvbox.nvim", - priority = 1000, - config = function () - require("gruvbox").setup({}) - vim.cmd("colorscheme gruvbox") - end - }, - - { - "hrsh7th/nvim-cmp", - dependencies = { - "williamboman/mason.nvim", - "williamboman/mason-lspconfig.nvim", - "neovim/nvim-lspconfig", - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "hrsh7th/cmp-cmdline", - "L3MON4D3/LuaSnip", - "onsails/lspkind-nvim" - }, - config = function() - require("mason").setup() - require("mason-lspconfig").setup({ - ensure_installed = { "lua_ls", "java_language_server", "pyright", "tailwindcss", "clangd" }, - automatic_installation = true, - }) - - local signs = { - Error = " ", - Warn = " ", - Hint = " ", - Info = " ", - } - for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) - end - - local capabilities = require("cmp_nvim_lsp").default_capabilities() - - local on_attach = function(client, bufnr) - local opts = { noremap = true, silent = true, buffer = bufnr } - vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) - vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) - vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) - vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, opts) - vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, opts) - vim.keymap.set("n", "wl", function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, opts) - vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) - vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) - vim.keymap.set("n", "ca", vim.lsp.buf.code_action, opts) - vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) - vim.keymap.set("n", "e", vim.diagnostic.open_float, opts) - vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) - vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts) - vim.keymap.set("n", "q", vim.diagnostic.setloclist, opts) - end - - local lspconfig = require("lspconfig") - - lspconfig.lua_ls.setup({ - capabilities = capabilities, - on_attach = on_attach, - settings = { - Lua = { - diagnostics = { - globals = { "vim" }, - }, - workspace = { - library = vim.api.nvim_get_runtime_file("", true), - }, - telemetry = { - enable = false, - }, - }, - }, - }) - - lspconfig.jdtls.setup({ - capabilities = capabilities, - on_attach = on_attach, - }) - - lspconfig.pyright.setup({ - capabilities = capabilities, - on_attach = on_attach, - }) - - lspconfig.tailwindcss.setup({ - capabilities = capabilities, - on_attach = on_attach, - }) - - lspconfig.clangd.setup({ - capabilities = capabilities, - on_attach = on_attach, - }) - - local cmp = require("cmp") - local luasnip = require("luasnip") - local lspkind = require("lspkind") - require("luasnip.loaders.from_vscode").lazy_load() - - cmp.setup({ - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.close(), - [""] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { "i", "s" }), - }), - formatting = { - format = lspkind.cmp_format({ - mode = "symbol_text", - maxwidth = 50, - ellipsis_char = "..." - }), - }, - sources = { - { name = "nvim_lsp" }, - { name = "luasnip" }, - { name = "buffer" }, - { name = "path" }, - }, - }) - - cmp.setup.filetype('gitcommit', { - sources = cmp.config.sources({ - { name = 'buffer' }, - }) - }) - - cmp.setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = 'path' } - }, { - { name = 'cmdline' } - }) - }) - end, - }, - - { - "nvim-treesitter/nvim-treesitter", - build = ":TSUpdate", - event = "BufRead", - config = function() - require("nvim-treesitter.configs").setup({ - auto_install = true, - ensure_installed = { "c", "lua", "vim", "python", "java", "javascript", "typescript", "css", "html" }, - highlight = { enable = true, use_languagetree = true }, - indent = { enable = true }, - }) - end, - }, - - { - "nvim-tree/nvim-tree.lua", - enabled = false, - config = function() - require("nvim-tree").setup({ - view = { width = 20, side = "left" }, - disable_netrw = true, - hijack_cursor = true, - update_cwd = true, - hijack_directories = { auto_open = true }, - renderer = { - root_folder_label = false, - indent_markers = { - enable = true, - icons = { corner = "└ ", edge = "│ ", none = " " }, - }, - }, - }) - end, - }, - - { - "nvim-telescope/telescope.nvim", - dependencies = { "nvim-lua/plenary.nvim" }, - keys = { - { "", ":silent Telescope current_buffer_fuzzy_find", desc = "Open Telescope" }, - }, - config = function() - require("telescope").setup({ - defaults = { mapping = {} }, - pickers = {}, - extensions = {}, - }) - end, - }, - - { - "akinsho/toggleterm.nvim", - version = "*", - config = true, - }, - - { - "lewis6991/gitsigns.nvim", - config = function() - require("gitsigns").setup() - end, - }, - - { - "mfussenegger/nvim-lint", - event = { "BufReadPre", "BufNewFile" }, - config = function() - local lint = require("lint") - - lint.linters_by_ft = { - lua = { "luacheck" }, - python = { "pylint" }, - } - - local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true }) - - vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, { - group = lint_augroup, - callback = function() - lint.try_lint() - end, - }) - end, - }, - - { - "echasnovski/mini.nvim", - version = false, - dependencies = { "nvim-tree/nvim-web-devicons" }, - config = function() - require("mini.starter").setup({ - header = table.concat({ - " /l、 ", - "(゚、 。 7 ", - " l ~ ヽ ", - " じしf_,)ノ ", - }, "\n"), - footer = "", - content_hooks = { - require("mini.starter").gen_hook.adding_bullet("» "), - require("mini.starter").gen_hook.aligning("center", "center"), - }, - }) - end, - }, - - { - "windwp/nvim-autopairs", - event = "InsertEnter", - config = function() - require("nvim-autopairs").setup {} - end, - }, - - { - "tamton-aquib/staline.nvim", - dependencies = { "nvim-tree/nvim-web-devicons" }, - config = function() - require("staline").setup { - sections = { - left = { 'file_name', 'branch' }, - mid = { 'lsp' }, - right = { 'line_column' }, - }, - special_table = { - NvimTree = { 'NvimTree', ' ' }, - packer = { 'Packer', ' ' }, - starter = { '', '' }, - lazy = { '', '' }, - mason = { '', '' }, - }, - lsp_symbols = { - Error = " ", - Info = " ", - Warn = " ", - Hint = "", - }, - defaults = { - true_colors = true, - line_column = ' ☰ %l/%L %c', - branch_symbol = " ", - exclude_fts = { 'NvimTree' }, - }, - } - vim.cmd('highlight Statusline guibg=none') - vim.cmd('highlight StatuslineNC guibg=none') - end, - }, - - { - "epwalsh/obsidian.nvim", - enabled = false, - version = "*", - lazy = true, - ft = "markdown", - dependencies = { - "nvim-lua/plenary.nvim", - }, - opts = { - workspaces = { - { - name = "Vaut", - path = "~/Vault/", - }, - }, - }, - }, -}) -- cgit v1.3.1