diff options
Diffstat (limited to 'neovim/.config/nvim/init.lua')
| -rw-r--r-- | neovim/.config/nvim/init.lua | 407 |
1 files changed, 407 insertions, 0 deletions
diff --git a/neovim/.config/nvim/init.lua b/neovim/.config/nvim/init.lua new file mode 100644 index 0000000..c92916e --- /dev/null +++ b/neovim/.config/nvim/init.lua @@ -0,0 +1,407 @@ +-------------------------------------------------------------------------------- +-- Neovim Configuration +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- Options +-------------------------------------------------------------------------------- + +-- UI +vim.opt.cursorline = true +vim.opt.number = true +vim.opt.scrolloff = 8 +vim.opt.signcolumn = "yes" +vim.opt.termguicolors = true + +-- Tabs & Indentation +vim.opt.expandtab = true +vim.opt.shiftwidth = 4 +vim.opt.tabstop = 4 + +-- Search +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- Splits +vim.opt.splitbelow = true +vim.opt.splitright = true + +-- Folding (treesitter-based) +vim.opt.foldmethod = "expr" +vim.opt.foldexpr = "nvim_treesitter#foldexpr()" +vim.opt.foldenable = true +vim.opt.foldlevelstart = 0 + +-- Misc +vim.opt.clipboard = "unnamedplus" +vim.opt.undofile = true +vim.opt.updatetime = 250 + +-------------------------------------------------------------------------------- +-- Bootstrap lazy.nvim +-------------------------------------------------------------------------------- +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or 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 +-------------------------------------------------------------------------------- +require("lazy").setup({ + + -- Colorscheme --------------------------------------------------------------- + { + "Shadorain/shadotheme", + lazy = false, + priority = 1000, + config = function() + vim.cmd.colorscheme("shado") + vim.api.nvim_set_hl(0, "Normal", { bg = "#000000" }) + vim.api.nvim_set_hl(0, "NormalFloat", { bg = "#000000" }) + vim.api.nvim_set_hl(0, "SignColumn", { bg = "#000000" }) + vim.api.nvim_set_hl(0, "LineNr", { bg = "#000000" }) + vim.api.nvim_set_hl(0, "CursorLineNr", { bg = "#000000" }) + end, + }, + + -- Treesitter ---------------------------------------------------------------- + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + dependencies = { "nvim-treesitter/nvim-treesitter-textobjects" }, + config = function() + require("nvim-treesitter.configs").setup({ + ensure_installed = { "bash", "lua", "python", "ruby" }, + auto_install = true, + highlight = { enable = true }, + indent = { enable = true }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "<C-space>", + node_incremental = "<C-space>", + node_decremental = "<bs>", + }, + }, + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + ["af"] = "@function.outer", ["if"] = "@function.inner", + ["ac"] = "@class.outer", ["ic"] = "@class.inner", + ["aa"] = "@parameter.outer", ["ia"] = "@parameter.inner", + }, + }, + move = { + enable = true, + set_jumps = true, + goto_next_start = { ["]m"] = "@function.outer", ["]]"] = "@class.outer" }, + goto_prev_start = { ["[m"] = "@function.outer", ["[["] = "@class.outer" }, + }, + }, + }) + end, + }, + + -- Completion ---------------------------------------------------------------- + { + "saghen/blink.cmp", + version = "1.*", + opts = { + keymap = { + preset = "default", + ["<CR>"] = { "accept", "fallback" }, + ["<Tab>"] = { "select_next", "fallback" }, + ["<S-Tab>"] = { "select_prev", "fallback" }, + }, + sources = { + default = { "lsp", "path", "buffer" }, + providers = { lsp = { timeout_ms = 2000 } }, + }, + completion = { + trigger = { show_in_snippet = false }, + menu = { auto_show = true }, + documentation = { auto_show = true, auto_show_delay_ms = 200 }, + }, + }, + }, + + -- Auto-pairs & Tags --------------------------------------------------------- + { "windwp/nvim-autopairs", event = "InsertEnter", opts = {} }, + { "windwp/nvim-ts-autotag", opts = {} }, + { "tpope/vim-endwise" }, + + -- UI ------------------------------------------------------------------------ + { "nvim-lualine/lualine.nvim", dependencies = { "nvim-tree/nvim-web-devicons" }, opts = {} }, + { "lewis6991/gitsigns.nvim", opts = {} }, + { "folke/which-key.nvim", event = "VeryLazy", opts = {} }, + { "lukas-reineke/indent-blankline.nvim", main = "ibl", opts = {} }, + + -- Navigation ---------------------------------------------------------------- + { + "nvim-tree/nvim-tree.lua", + dependencies = { "nvim-tree/nvim-web-devicons" }, + opts = {}, + keys = { { "<leader>e", "<cmd>NvimTreeToggle<cr>", desc = "File tree" } }, + }, + { + "hedyhli/outline.nvim", + opts = {}, + keys = { { "<leader>o", "<cmd>Outline<cr>", desc = "Code outline" } }, + }, + { + "nvim-telescope/telescope.nvim", + branch = "0.1.x", + dependencies = { "nvim-lua/plenary.nvim" }, + keys = { + { "<leader>ff", "<cmd>Telescope find_files<cr>", desc = "Find files" }, + { "<leader>fg", "<cmd>Telescope live_grep<cr>", desc = "Live grep" }, + { "<leader>fb", "<cmd>Telescope buffers<cr>", desc = "Buffers" }, + { "<leader>fh", "<cmd>Telescope help_tags<cr>", desc = "Help tags" }, + { "<leader>fr", "<cmd>Telescope oldfiles<cr>", desc = "Recent files" }, + { "<leader>fc", "<cmd>Telescope git_commits<cr>", desc = "Git commits" }, + { "<leader>fs", "<cmd>Telescope lsp_document_symbols<cr>", desc = "Document symbols" }, + }, + }, + { + "folke/flash.nvim", + event = "VeryLazy", + opts = {}, + keys = { + { "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" }, + { "S", mode = { "n", "x", "o" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, + }, + }, + + -- Editing ------------------------------------------------------------------- + { + "numToStr/Comment.nvim", + opts = {}, + keys = { + { "gcc", mode = "n", desc = "Comment line" }, + { "gc", mode = "v", desc = "Comment selection" }, + }, + }, + { + "kylechui/nvim-surround", + version = "^3", + event = "VeryLazy", + opts = {}, + }, + { "echasnovski/mini.ai", version = "*", opts = {} }, + + -- Diagnostics & Formatting -------------------------------------------------- + { + "folke/trouble.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, + opts = {}, + keys = { + { "<leader>xx", "<cmd>Trouble diagnostics toggle<cr>", desc = "Diagnostics" }, + { "<leader>xX", "<cmd>Trouble diagnostics toggle filter.buf=0<cr>", desc = "Buffer diagnostics" }, + { "<leader>xq", "<cmd>Trouble quickfix toggle<cr>", desc = "Quickfix list" }, + }, + }, + { + "folke/todo-comments.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + opts = {}, + keys = { + { "<leader>xt", "<cmd>Trouble todo toggle<cr>", desc = "Todo comments" }, + { "]t", function() require("todo-comments").jump_next() end, desc = "Next todo" }, + { "[t", function() require("todo-comments").jump_prev() end, desc = "Prev todo" }, + }, + }, + { + "stevearc/conform.nvim", + event = "BufWritePre", + keys = { + { "<leader>cf", function() require("conform").format({ async = true }) end, desc = "Format buffer" }, + }, + opts = { + formatters_by_ft = { + lua = { "stylua" }, + python = { "ruff_format", "ruff_fix" }, + javascript = { "prettier" }, + typescript = { "prettier" }, + javascriptreact = { "prettier" }, + typescriptreact = { "prettier" }, + json = { "prettier" }, + yaml = { "prettier" }, + html = { "prettier" }, + css = { "prettier" }, + markdown = { "prettier" }, + ruby = { "rubocop" }, + sh = { "shfmt" }, + bash = { "shfmt" }, + zsh = { "shfmt" }, + }, + }, + }, + + -- Notes --------------------------------------------------------------------- + { "vimwiki/vimwiki" }, + +}) + +-------------------------------------------------------------------------------- +-- LSP Configuration +-------------------------------------------------------------------------------- +vim.lsp.config.pyright = { + cmd = { "pyright-langserver", "--stdio" }, + filetypes = { "python" }, + root_markers = { "pyproject.toml", "setup.py", "setup.cfg", "requirements.txt", ".git" }, + single_file_support = true, + settings = { + python = { + analysis = { + typeCheckingMode = "basic", + autoSearchPaths = false, + diagnosticMode = "openFilesOnly", + useLibraryCodeForTypes = false, + }, + }, + }, +} + +vim.lsp.config.solargraph = { + cmd = { "solargraph", "stdio" }, + filetypes = { "ruby" }, + root_markers = { "Gemfile", ".git" }, + single_file_support = true, +} + +vim.lsp.config.yamlls = { + cmd = { "yaml-language-server", "--stdio" }, + filetypes = { "yaml", "yaml.docker-compose", "yaml.gitlab" }, + root_markers = { ".git" }, + single_file_support = true, + settings = { + yaml = { + validate = true, + schemaStore = { enable = true, url = "https://www.schemastore.org/api/json/catalog.json" }, + }, + }, +} + +vim.lsp.config.taplo = { + cmd = { "taplo", "lsp", "stdio" }, + filetypes = { "toml" }, + root_markers = { ".git" }, + single_file_support = true, +} + +vim.lsp.config.lua_ls = { + cmd = { "lua-language-server" }, + filetypes = { "lua" }, + root_markers = { ".luarc.json", ".luarc.jsonc", ".git" }, + single_file_support = true, + settings = { + Lua = { + runtime = { version = "LuaJIT" }, + workspace = { library = { vim.env.VIMRUNTIME } }, + telemetry = { enable = false }, + }, + }, +} + +vim.lsp.config.bashls = { + cmd = { "bash-language-server", "start" }, + filetypes = { "sh", "bash", "zsh" }, + root_markers = { ".git" }, + single_file_support = true, +} + +vim.lsp.config.jsonls = { + cmd = { "vscode-json-language-server", "--stdio" }, + filetypes = { "json", "jsonc" }, + root_markers = { ".git" }, + single_file_support = true, + settings = { + json = { + validate = { enable = true }, + schemaStore = { enable = true, url = "https://www.schemastore.org/api/json/catalog.json" }, + }, + }, +} + +vim.lsp.config.html = { + cmd = { "vscode-html-language-server", "--stdio" }, + filetypes = { "html", "templ" }, + root_markers = { ".git" }, + single_file_support = true, +} + +vim.lsp.config.cssls = { + cmd = { "vscode-css-language-server", "--stdio" }, + filetypes = { "css", "scss", "less" }, + root_markers = { ".git" }, + single_file_support = true, +} + +vim.lsp.config.ts_ls = { + cmd = { "typescript-language-server", "--stdio" }, + filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact" }, + root_markers = { "tsconfig.json", "jsconfig.json", "package.json", ".git" }, + single_file_support = true, +} + +vim.lsp.config.dockerls = { + cmd = { "docker-langserver", "--stdio" }, + filetypes = { "dockerfile" }, + root_markers = { "Dockerfile", ".git" }, + single_file_support = true, +} + +vim.lsp.config.clangd = { + cmd = { "clangd" }, + filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto" }, + root_markers = { "compile_commands.json", "compile_flags.txt", ".clangd", ".git" }, + single_file_support = true, +} + +vim.lsp.enable("pyright") +vim.lsp.enable("solargraph") +vim.lsp.enable("yamlls") +vim.lsp.enable("taplo") +vim.lsp.enable("lua_ls") +vim.lsp.enable("bashls") +vim.lsp.enable("jsonls") +vim.lsp.enable("html") +vim.lsp.enable("cssls") +vim.lsp.enable("ts_ls") +vim.lsp.enable("dockerls") +vim.lsp.enable("clangd") + +-------------------------------------------------------------------------------- +-- Tabline styling +-------------------------------------------------------------------------------- +vim.api.nvim_set_hl(0, "TabLineSel", { fg = "#ffffff", bg = "#5a5a5a", bold = true }) +vim.api.nvim_set_hl(0, "TabLine", { fg = "#888888", bg = "#000000" }) +vim.api.nvim_set_hl(0, "TabLineFill", { bg = "#000000" }) + +-------------------------------------------------------------------------------- +-- Keymaps +-------------------------------------------------------------------------------- +vim.keymap.set("n", "<S-h>", "<cmd>tabprev<cr>", { desc = "Prev tab" }) +vim.keymap.set("n", "<S-l>", "<cmd>tabnext<cr>", { desc = "Next tab" }) + +vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local map = function(key, fn, desc) + vim.keymap.set("n", key, fn, { buffer = args.buf, desc = desc }) + end + map("gd", vim.lsp.buf.definition, "Go to definition") + map("gr", vim.lsp.buf.references, "References") + map("K", vim.lsp.buf.hover, "Hover docs") + map("<leader>rn", vim.lsp.buf.rename, "Rename symbol") + map("<leader>ca", vim.lsp.buf.code_action, "Code action") + map("<leader>ds", vim.lsp.buf.document_symbol, "Document symbols") + end, +}) |
