From b71409d0f5d730e9dd74a92021cbb96900909452 Mon Sep 17 00:00:00 2001 From: Lol3rrr Date: Wed, 9 Apr 2025 17:04:45 +0200 Subject: [PATCH] Initial version --- init.lua | 93 +++++++++++++++++++++++++++++ lazy-lock.json | 21 +++++++ lua/colorschemes.lua | 2 + lua/plugins/catppuccin.lua | 1 + lua/plugins/crates.lua | 9 +++ lua/plugins/lspconfig.lua | 3 + lua/plugins/neo-tree.lua | 10 ++++ lua/plugins/nightfly.lua | 1 + lua/plugins/nvim-cmp.lua | 93 +++++++++++++++++++++++++++++ lua/plugins/rustacean.lua | 44 ++++++++++++++ lua/plugins/tokyonight.lua | 6 ++ lua/plugins/treesitter.lua | 116 +++++++++++++++++++++++++++++++++++++ 12 files changed, 399 insertions(+) create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lua/colorschemes.lua create mode 100644 lua/plugins/catppuccin.lua create mode 100644 lua/plugins/crates.lua create mode 100644 lua/plugins/lspconfig.lua create mode 100644 lua/plugins/neo-tree.lua create mode 100644 lua/plugins/nightfly.lua create mode 100644 lua/plugins/nvim-cmp.lua create mode 100644 lua/plugins/rustacean.lua create mode 100644 lua/plugins/tokyonight.lua create mode 100644 lua/plugins/treesitter.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..34e45d1 --- /dev/null +++ b/init.lua @@ -0,0 +1,93 @@ +vim.loader.enable() + +-- Bootstrap lazy.nvim +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("plugins") +--require("lazy").setup({ +-- spec = { +-- { import = "plugins" } +-- } +--}) +--require("lazy") + +local config_path = vim.fn.stdpath("config") + +local color_scheme_module, _ = string.format("colorschemes", config_path) +package.loaded[color_scheme_module] = nil +require(color_scheme_module) + +vim.o.expandtab = true +vim.o.smartindent = true +vim.o.tabstop = 2 +vim.o.shiftwidth = 2 + +vim.keymap.set('t', '', [[]]) + +-- Setup language servers. +local lspconfig = require('lspconfig') +lspconfig.pyright.setup {} +lspconfig.tsserver.setup {} +lspconfig.rust_analyzer.setup { + -- Server-specific settings. See `:help lspconfig-setup` + settings = { + ['rust-analyzer'] = {}, + }, +} + + +-- Global mappings. +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +vim.keymap.set('n', 'e', vim.diagnostic.open_float) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist) + +-- Use LspAttach autocommand to only map the following keys +-- after the language server attaches to the current buffer +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' + + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local opts = { buffer = ev.buf } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + -- vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'f', 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', 'v' }, 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format { async = true } + end, opts) + end, +}) + +vim.wo.number = true +vim.cmd('Neotree') diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..dcae2aa --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,21 @@ +{ + "catppuccin": { "branch": "main", "commit": "5b5e3aef9ad7af84f463d17b5479f06b87d5c429" }, + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" }, + "cmp-path": { "branch": "main", "commit": "c6635aae33a50d6010bf1aa756ac2398a2d54c32" }, + "crates.nvim": { "branch": "main", "commit": "fd2bbca7aa588f24ffc3517831934b4c4a9588e9" }, + "hererocks": { "branch": "master", "commit": "c9c5444dea1e07e005484014a8231aa667be30b6" }, + "image.nvim": { "branch": "master", "commit": "2e2d28b7734b5efdfc1219f4da8a46c761587bc2" }, + "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, + "neo-tree.nvim": { "branch": "v3.x", "commit": "9b5d67119c46e3262ffe1508fe6d8540b79ad75d" }, + "nightfly": { "branch": "master", "commit": "98fcfdb8a9546ddf1b971a68d7195735a0bd305a" }, + "nui.nvim": { "branch": "main", "commit": "8d3bce9764e627b62b07424e0df77f680d47ffdb" }, + "nvim-cmp": { "branch": "main", "commit": "059e89495b3ec09395262f16b1ad441a38081d04" }, + "nvim-lspconfig": { "branch": "master", "commit": "d3ad666b7895f958d088cceb6f6c199672c404fe" }, + "nvim-treesitter": { "branch": "master", "commit": "e5c8398e4492815a7e2adce46fcb08eccf2fa392" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "9937e5e356e5b227ec56d83d0a9d0a0f6bc9cad4" }, + "nvim-web-devicons": { "branch": "master", "commit": "481bdaa3dca70c5f1863e634db6afede8980488c" }, + "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, + "rustaceanvim": { "branch": "master", "commit": "047f9c9d8cd2861745eb9de6c1570ee0875aa795" }, + "tokyonight.nvim": { "branch": "main", "commit": "057ef5d260c1931f1dffd0f052c685dcd14100a3" } +} diff --git a/lua/colorschemes.lua b/lua/colorschemes.lua new file mode 100644 index 0000000..6f7a9ea --- /dev/null +++ b/lua/colorschemes.lua @@ -0,0 +1,2 @@ +-- vim.cmd [[colorscheme tokyonight]] +vim.cmd [[colorscheme catppuccin-latte]] diff --git a/lua/plugins/catppuccin.lua b/lua/plugins/catppuccin.lua new file mode 100644 index 0000000..ea83ab9 --- /dev/null +++ b/lua/plugins/catppuccin.lua @@ -0,0 +1 @@ +return {{ "catppuccin/nvim", name = "catppuccin", priority = 1000 }} diff --git a/lua/plugins/crates.lua b/lua/plugins/crates.lua new file mode 100644 index 0000000..bcf5854 --- /dev/null +++ b/lua/plugins/crates.lua @@ -0,0 +1,9 @@ +return {{ + "Saecki/crates.nvim", + event = { "BufRead Cargo.toml" }, + opts = { + src = { + cmp = { enabled = true }, + }, + }, +}} diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua new file mode 100644 index 0000000..9d1124e --- /dev/null +++ b/lua/plugins/lspconfig.lua @@ -0,0 +1,3 @@ +return {{ + "neovim/nvim-lspconfig", +}} diff --git a/lua/plugins/neo-tree.lua b/lua/plugins/neo-tree.lua new file mode 100644 index 0000000..990f4fb --- /dev/null +++ b/lua/plugins/neo-tree.lua @@ -0,0 +1,10 @@ +return {{ + "nvim-neo-tree/neo-tree.nvim", + branch = "v3.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + "3rd/image.nvim", -- Optional image support in preview window: See `# Preview Mode` for more information + } +}} diff --git a/lua/plugins/nightfly.lua b/lua/plugins/nightfly.lua new file mode 100644 index 0000000..11d9dc0 --- /dev/null +++ b/lua/plugins/nightfly.lua @@ -0,0 +1 @@ +return {{ "bluz71/vim-nightfly-colors", name = "nightfly", lazy = false, priority = 1000 }} diff --git a/lua/plugins/nvim-cmp.lua b/lua/plugins/nvim-cmp.lua new file mode 100644 index 0000000..5796440 --- /dev/null +++ b/lua/plugins/nvim-cmp.lua @@ -0,0 +1,93 @@ +return {{ + "hrsh7th/nvim-cmp", + version = false, -- last release is way too old + event = "InsertEnter", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + + + { + "Saecki/crates.nvim", + event = { "BufRead Cargo.toml" }, + opts = { + src = { + cmp = { enabled = true }, + }, + }, + }, + + }, + -- Not all LSP servers add brackets when completing a function. + -- To better deal with this, LazyVim adds a custom option to cmp, + -- that you can configure. For example: + -- + -- ```lua + -- opts = { + -- auto_brackets = { "python" } + -- } + -- ``` + + opts = function() + vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true }) + local cmp = require("cmp") + local defaults = require("cmp.config.default")() + return { + auto_brackets = {}, -- configure any filetype to auto add brackets + completion = { + completeopt = "menu,menuone,noinsert", + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), + [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [""] = function(fallback) + cmp.abort() + fallback() + end, + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "path" }, + { name = "crates"} + }, { + { name = "buffer" }, + }), + experimental = { + ghost_text = { + hl_group = "CmpGhostText", + }, + }, + sorting = defaults.sorting, + } + end, + ---@param opts cmp.ConfigSchema | {auto_brackets?: string[]} + config = function(_, opts) + for _, source in ipairs(opts.sources) do + source.group_index = source.group_index or 1 + end + local cmp = require("cmp") + local Kind = cmp.lsp.CompletionItemKind + cmp.setup(opts) + cmp.event:on("confirm_done", function(event) + if not vim.tbl_contains(opts.auto_brackets or {}, vim.bo.filetype) then + return + end + local entry = event.entry + local item = entry:get_completion_item() + if vim.tbl_contains({ Kind.Function, Kind.Method }, item.kind) then + local keys = vim.api.nvim_replace_termcodes("()", false, false, true) + vim.api.nvim_feedkeys(keys, "i", true) + end + end) + end, +}} diff --git a/lua/plugins/rustacean.lua b/lua/plugins/rustacean.lua new file mode 100644 index 0000000..2e78530 --- /dev/null +++ b/lua/plugins/rustacean.lua @@ -0,0 +1,44 @@ +return {{ + "mrcjkb/rustaceanvim", + version = "^4", -- Recommended + ft = { "rs" }, + opts = { + server = { + on_attach = function(_, bufnr) + vim.keymap.set("n", "cR", function() + vim.cmd.RustLsp("codeAction") + end, { desc = "Code Action", buffer = bufnr }) + vim.keymap.set("n", "dr", function() + vim.cmd.RustLsp("debuggables") + end, { desc = "Rust Debuggables", buffer = bufnr }) + end, + default_settings = { + -- rust-analyzer language server configuration + ["rust-analyzer"] = { + cargo = { + allFeatures = true, + loadOutDirsFromCheck = true, + runBuildScripts = true, + }, + -- Add clippy lints for Rust. + checkOnSave = { + allFeatures = true, + command = "clippy", + extraArgs = { "--no-deps" }, + }, + procMacro = { + enable = true, + ignored = { + ["async-trait"] = { "async_trait" }, + ["napi-derive"] = { "napi" }, + ["async-recursion"] = { "async_recursion" }, + }, + }, + }, + }, + }, + }, + config = function(_, opts) + vim.g.rustaceanvim = vim.tbl_deep_extend("keep", vim.g.rustaceanvim or {}, opts or {}) + end, +}} diff --git a/lua/plugins/tokyonight.lua b/lua/plugins/tokyonight.lua new file mode 100644 index 0000000..9a90635 --- /dev/null +++ b/lua/plugins/tokyonight.lua @@ -0,0 +1,6 @@ +return {{ + "folke/tokyonight.nvim", + lazy = false, + priority = 1000, + opts = {} +}} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..859ab47 --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,116 @@ +return {{ + "nvim-treesitter/nvim-treesitter", + version = false, -- last release is way too old and doesn't work on Windows + build = ":TSUpdate", + event = { "VeryLazy" }, + init = function(plugin) + -- PERF: add nvim-treesitter queries to the rtp and it's custom query predicates early + -- This is needed because a bunch of plugins no longer `require("nvim-treesitter")`, which + -- no longer trigger the **nvim-treesitter** module to be loaded in time. + -- Luckily, the only things that those plugins need are the custom queries, which we make available + -- during startup. + require("lazy.core.loader").add_to_rtp(plugin) + require("nvim-treesitter.query_predicates") + end, + dependencies = { + { + "nvim-treesitter/nvim-treesitter-textobjects", + config = function() + -- When in diff mode, we want to use the default + -- vim text objects c & C instead of the treesitter ones. + local move = require("nvim-treesitter.textobjects.move") ---@type table + local configs = require("nvim-treesitter.configs") + for name, fn in pairs(move) do + if name:find("goto") == 1 then + move[name] = function(q, ...) + if vim.wo.diff then + local config = configs.get_module("textobjects.move")[name] ---@type table + for key, query in pairs(config or {}) do + if q == query and key:find("[%]%[][cC]") then + vim.cmd("normal! " .. key) + return + end + end + end + return fn(q, ...) + end + end + end + end, + }, + }, + cmd = { "TSUpdateSync", "TSUpdate", "TSInstall" }, + keys = { + { "", desc = "Increment Selection" }, + { "", desc = "Decrement Selection", mode = "x" }, + }, + ---@type TSConfig + ---@diagnostic disable-next-line: missing-fields + opts = { + highlight = { enable = true }, + indent = { enable = true }, + ensure_installed = { + "bash", + "c", + "diff", + "html", + "javascript", + "jsdoc", + "json", + "jsonc", + "lua", + "luadoc", + "luap", + "markdown", + "markdown_inline", + "python", + "query", + "regex", + "toml", + "tsx", + "typescript", + "vim", + "vimdoc", + "xml", + "yaml", + "rust", + "toml", + "ron", + "hcl", + "terraform" + }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "", + node_incremental = "", + scope_incremental = false, + node_decremental = "", + }, + }, + textobjects = { + move = { + enable = true, + goto_next_start = { ["]f"] = "@function.outer", ["]c"] = "@class.outer" }, + goto_next_end = { ["]F"] = "@function.outer", ["]C"] = "@class.outer" }, + goto_previous_start = { ["[f"] = "@function.outer", ["[c"] = "@class.outer" }, + goto_previous_end = { ["[F"] = "@function.outer", ["[C"] = "@class.outer" }, + }, + }, + }, + ---@param opts TSConfig + config = function(_, opts) + if type(opts.ensure_installed) == "table" then + ---@type table + local added = {} + opts.ensure_installed = vim.tbl_filter(function(lang) + if added[lang] then + return false + end + added[lang] = true + return true + end, opts.ensure_installed) + end + require("nvim-treesitter.configs").setup(opts) + end, +}}