From f407f526b237280659eb42ec3e0299834d965896 Mon Sep 17 00:00:00 2001 From: A_train63 Date: Fri, 15 Sep 2023 15:24:13 -0700 Subject: [PATCH] Initial Commit --- init.lua | 8 ++ lazy-lock.json | 45 ++++++++++++ lua/.luarc.json | 44 +++++++++++ lua/core/keymaps.lua | 71 ++++++++++++++++++ lua/core/lazy.lua | 30 ++++++++ lua/core/options.lua | 18 +++++ lua/helpers/buffers.lua | 25 +++++++ lua/helpers/colorscheme.lua | 24 ++++++ lua/helpers/keys.lua | 21 ++++++ lua/plugins/bufferline.lua | 9 +++ lua/plugins/cmp.lua | 105 ++++++++++++++++++++++++++ lua/plugins/git.lua | 31 ++++++++ lua/plugins/lsp.lua | 143 ++++++++++++++++++++++++++++++++++++ lua/plugins/lualine.lua | 15 ++++ lua/plugins/misc.lua | 25 +++++++ lua/plugins/neo-tree.lua | 27 +++++++ lua/plugins/null-ls.lua | 19 +++++ lua/plugins/telescope.lua | 46 ++++++++++++ lua/plugins/themes.lua | 20 +++++ lua/plugins/toggleterm.lua | 12 +++ lua/plugins/treesitter.lua | 65 ++++++++++++++++ lua/plugins/which-key.lua | 25 +++++++ 22 files changed, 828 insertions(+) create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lua/.luarc.json create mode 100644 lua/core/keymaps.lua create mode 100644 lua/core/lazy.lua create mode 100644 lua/core/options.lua create mode 100644 lua/helpers/buffers.lua create mode 100644 lua/helpers/colorscheme.lua create mode 100644 lua/helpers/keys.lua create mode 100644 lua/plugins/bufferline.lua create mode 100644 lua/plugins/cmp.lua create mode 100644 lua/plugins/git.lua create mode 100644 lua/plugins/lsp.lua create mode 100644 lua/plugins/lualine.lua create mode 100644 lua/plugins/misc.lua create mode 100644 lua/plugins/neo-tree.lua create mode 100644 lua/plugins/null-ls.lua create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/plugins/themes.lua create mode 100644 lua/plugins/toggleterm.lua create mode 100644 lua/plugins/treesitter.lua create mode 100644 lua/plugins/which-key.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..e61cd5c --- /dev/null +++ b/init.lua @@ -0,0 +1,8 @@ +-- Handle plugins with lazy.nvim +require("core.lazy") + +-- General Neovim keymaps +require("core.keymaps") + +-- Other options +require("core.options") diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..d3ff769 --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,45 @@ +{ + "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, + "LuaSnip": { "branch": "master", "commit": "ea7d7ea510c641c4f15042becd27f35b3e5b3c2b" }, + "bg.nvim": { "branch": "main", "commit": "e7318e901f4bb9272814cf2af1eb6435bfa2e905" }, + "bufferline.nvim": { "branch": "main", "commit": "243893ba9d5d1049dd451a25cab32ec7f8f67bcf" }, + "catppuccin": { "branch": "main", "commit": "85e93601e0f0b48aa2c6bbfae4d0e9d7a1898280" }, + "close-buffers.nvim": { "branch": "master", "commit": "3acbcad1211572342632a6c0151f839e7dead27f" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, + "cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" }, + "everforest": { "branch": "master", "commit": "83b666410d7ae0eccf96dbbe3b4b6ac5b8172d38" }, + "fidget.nvim": { "branch": "main", "commit": "89b633f3bd0b7187f070236b348697de176860e2" }, + "friendly-snippets": { "branch": "main", "commit": "ebf6d6e83494cdd88a54a429340256f4dbb6a052" }, + "git-conflict.nvim": { "branch": "main", "commit": "2957f747e1a34f1854e4e0efbfbfa59a1db04af5" }, + "gitsigns.nvim": { "branch": "main", "commit": "907ae8636016aab2f283576fc60d46ca3427e579" }, + "gruvbox.nvim": { "branch": "main", "commit": "7fb36e0f67aa6f3d7f3e54f37ca7032ea1af0b59" }, + "lazy.nvim": { "branch": "main", "commit": "2a9354c7d2368d78cbd5575a51a2af5bd8a6ad01" }, + "lualine.nvim": { "branch": "master", "commit": "45e27ca739c7be6c49e5496d14fcf45a303c3a63" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "f014db32437aa61c86fc0ef1067cd2bc6a37205c" }, + "mason.nvim": { "branch": "main", "commit": "d66c60e17dd6fd8165194b1d14d21f7eb2c1697a" }, + "melange-nvim": { "branch": "master", "commit": "517518347e41301bb2d1189d257f3918551a2ea5" }, + "mini.move": { "branch": "main", "commit": "3afd39873eb9171684e554a214c055482444a47d" }, + "neo-tree.nvim": { "branch": "v2.x", "commit": "80dc74d081823649809f78370fa5b204aa9a853a" }, + "neodev.nvim": { "branch": "main", "commit": "471324e6c746284dbbdc1d357799d1911bb7e120" }, + "nui.nvim": { "branch": "main", "commit": "c8de23342caf8d50b15d6b28368d36a56a69d76f" }, + "null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" }, + "nvim-cmp": { "branch": "main", "commit": "5dce1b778b85c717f6614e3f4da45e9f19f54435" }, + "nvim-lspconfig": { "branch": "master", "commit": "cc388d3f6b9c7c943ae2b2dcd46ad470fd257f91" }, + "nvim-treesitter": { "branch": "master", "commit": "bf8b089eecef9e9e8c1765f81613a2fd5e49175c" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "bd103502252027434ec42f628d2dbf54821d4ce6" }, + "nvim-ts-rainbow": { "branch": "master", "commit": "8312b513ce930e7669a1721befbe56f2e1853301" }, + "nvim-web-devicons": { "branch": "master", "commit": "973ab742f143a796a779af4d786ec409116a0d87" }, + "plenary.nvim": { "branch": "master", "commit": "9ce85b0f7dcfe5358c0be937ad23e456907d410b" }, + "rose-pine": { "branch": "main", "commit": "e29002cbee4854a9c8c4b148d8a52fae3176070f" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, + "telescope.nvim": { "branch": "0.1.x", "commit": "54930e1abfc94409e1bb9266e752ef8379008592" }, + "toggleterm.nvim": { "branch": "main", "commit": "b90a1381e9b5b8596f49070ee86c71db267ac868" }, + "vim-fugitive": { "branch": "master", "commit": "6fcb0ad03982de646e3fecb6915e585651b9a9fb" }, + "vim-illuminate": { "branch": "master", "commit": "8c910b2f84ae6acd9b4b17330bb94dd783c0c11a" }, + "vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" }, + "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" }, + "which-key.nvim": { "branch": "main", "commit": "7ccf476ebe0445a741b64e36c78a682c1c6118b7" } +} \ No newline at end of file diff --git a/lua/.luarc.json b/lua/.luarc.json new file mode 100644 index 0000000..e9903f5 --- /dev/null +++ b/lua/.luarc.json @@ -0,0 +1,44 @@ +{ + "workspace.library": [ + "/home/robot/.local/share/nvim/lazy/neodev.nvim/types/stable", + "/squashfs-root/usr/share/nvim/runtime/lua", + "/home/robot/.local/share/nvim/lazy/close-buffers.nvim/lua", + "/home/robot/.local/share/nvim/lazy/which-key.nvim/lua", + "/home/robot/.local/share/nvim/lazy/melange-nvim/lua", + "/home/robot/.local/share/nvim/lazy/nvim-treesitter-textobjects/lua", + "/home/robot/.local/share/nvim/lazy/telescope.nvim/lua", + "/home/robot/.local/share/nvim/lazy/null-ls.nvim/lua", + "/home/robot/.local/share/nvim/lazy/telescope-fzf-native.nvim/lua", + "/home/robot/.local/share/nvim/lazy/nvim-web-devicons/lua", + "/home/robot/.local/share/nvim/lazy/nvim-cmp/lua", + "/home/robot/.local/share/nvim/lazy/lualine.nvim/lua", + "/home/robot/.local/share/nvim/lazy/cmp-nvim-lsp/lua", + "/home/robot/.local/share/nvim/lazy/cmp-nvim-lua/lua", + "/home/robot/.local/share/nvim/lazy/nvim-lspconfig/lua", + "/home/robot/.local/share/nvim/lazy/catppuccin/lua", + "/home/robot/.local/share/nvim/lazy/cmp-buffer/lua", + "/home/robot/.local/share/nvim/lazy/mason.nvim/lua", + "/home/robot/.local/share/nvim/lazy/gitsigns.nvim/lua", + "/home/robot/.local/share/nvim/lazy/mini.move/lua", + "/home/robot/.local/share/nvim/lazy/cmp-path/lua", + "/home/robot/.local/share/nvim/lazy/lazy.nvim/lua", + "/home/robot/.local/share/nvim/lazy/git-conflict.nvim/lua", + "/home/robot/.local/share/nvim/lazy/nvim-treesitter/lua", + "/home/robot/.local/share/nvim/lazy/everforest/lua", + "/home/robot/.local/share/nvim/lazy/LuaSnip/lua", + "/home/robot/.local/share/nvim/lazy/rose-pine/lua", + "/home/robot/.local/share/nvim/lazy/nui.nvim/lua", + "/home/robot/.local/share/nvim/lazy/gruvbox.nvim/lua", + "/home/robot/.local/share/nvim/lazy/plenary.nvim/lua", + "/home/robot/.local/share/nvim/lazy/cmp_luasnip/lua", + "/home/robot/.local/share/nvim/lazy/bufferline.nvim/lua", + "/home/robot/.local/share/nvim/lazy/neodev.nvim/lua", + "/home/robot/.local/share/nvim/lazy/mason-lspconfig.nvim/lua", + "/home/robot/.local/share/nvim/lazy/Comment.nvim/lua", + "/home/robot/.local/share/nvim/lazy/fidget.nvim/lua", + "/home/robot/.local/share/nvim/lazy/neo-tree.nvim/lua", + "/home/robot/.local/share/nvim/lazy/vim-illuminate/lua", + "/home/robot/.config/nvim/lua", + "${3rd}/luv/library" + ] +} \ No newline at end of file diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua new file mode 100644 index 0000000..d5fcdb8 --- /dev/null +++ b/lua/core/keymaps.lua @@ -0,0 +1,71 @@ +local map = require("helpers.keys").map + +-- Quick access to some common actions +map("n", "fw", "w", "Write") +map("n", "fa", "wa", "Write all") +map("n", "qq", "q", "Quit") +map("n", "qa", "qa!", "Quit all") +map("n", "dw", "close", "Window") + +-- Diagnostic keymaps +map('n', 'gx', vim.diagnostic.open_float, "Show diagnostics under cursor") + +-- Easier access to beginning and end of lines +map("n", "", "^", "Go to beginning of line") +map("n", "", "$", "Go to end of line") + +-- Better window navigation +map("n", "", "", "Navigate windows to the left") +map("n", "", "", "Navigate windows down") +map("n", "", "", "Navigate windows up") +map("n", "", "", "Navigate windows to the right") + +-- Move with shift-arrows +map("n", "", "", "Move window to the left") +map("n", "", "", "Move window down") +map("n", "", "", "Move window up") +map("n", "", "", "Move window to the right") + +-- Resize with arrows +map("n", "", ":resize +2") +map("n", "", ":resize -2") +map("n", "", ":vertical resize +2") +map("n", "", ":vertical resize -2") + +-- Deleting buffers +local buffers = require("helpers.buffers") +map("n", "db", buffers.delete_this, "Current buffer") +map("n", "do", buffers.delete_others, "Other buffers") +map("n", "da", buffers.delete_all, "All buffers") + +-- Navigate buffers +map("n", "", ":bnext") +map("n", "", ":bprevious") + +-- Stay in indent mode +map("v", "<", "", ">gv") + +-- Switch between light and dark modes +map("n", "ut", function() + if vim.o.background == "dark" then + vim.o.background = "light" + else + vim.o.background = "dark" + end +end, "Toggle between light and dark themes") + +-- Clear after search +map("n", "ur", "nohl", "Clear highlights") + +-- Open config +map("n", "Nc", "n ~/.config/nvim/init.lua", "Open Config") + +-- ToggleTerm config +local Terminal = require('toggleterm.terminal').Terminal +local lazygit = Terminal:new({cmd = "lazygit", hidden = true, direction='tab'}) + +function _lazygit_toggle() + lazygit:toggle() +end +map("n", "gg", "lua _lazygit_toggle()", "open lazygit") diff --git a/lua/core/lazy.lua b/lua/core/lazy.lua new file mode 100644 index 0000000..44e13c3 --- /dev/null +++ b/lua/core/lazy.lua @@ -0,0 +1,30 @@ +-- Install lazy.nvim if not already installed +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", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +-- Use a protected call so we don't error out on first use +local ok, lazy = pcall(require, "lazy") +if not ok then + return +end + +-- We have to set the leader key here for lazy.nvim to work +require("helpers.keys").set_leader(" ") + +-- Load plugins from specifications +-- (The leader key must be set before this) +lazy.setup("plugins") + +-- Might as well set up an easy-access keybinding + +require("helpers.keys").map("n", "pL", lazy.show, "Show Lazy") diff --git a/lua/core/options.lua b/lua/core/options.lua new file mode 100644 index 0000000..d9c6d45 --- /dev/null +++ b/lua/core/options.lua @@ -0,0 +1,18 @@ +local opts = { + shiftwidth = 4, + tabstop = 4, + expandtab = true, + wrap = false, + termguicolors = true, + number = true, + relativenumber = true, +} + +-- Set options from table +for opt, val in pairs(opts) do + vim.o[opt] = val +end + +-- Set other options +local colorscheme = require("helpers.colorscheme") +vim.cmd.colorscheme(colorscheme) diff --git a/lua/helpers/buffers.lua b/lua/helpers/buffers.lua new file mode 100644 index 0000000..81703be --- /dev/null +++ b/lua/helpers/buffers.lua @@ -0,0 +1,25 @@ +local M = {} +local function noop() + print("NOOP") +end + +local ok, close_buffers = pcall(require, "close_buffers") +if ok then + M.delete_this = function() + close_buffers.delete({ type = "this" }) + end + M.delete_all = function() + close_buffers.delete({ type = "all", force = true }) + end + M.delete_others = function() + close_buffers.delete({ type = "other", force = true }) + end +else + M.delete_this = function() + vim.cmd.bdelete() + end + M.delete_all = noop + M.delete_others = noop +end + +return M diff --git a/lua/helpers/colorscheme.lua b/lua/helpers/colorscheme.lua new file mode 100644 index 0000000..07c9aa1 --- /dev/null +++ b/lua/helpers/colorscheme.lua @@ -0,0 +1,24 @@ +-- Fetch and setup colorscheme if available, otherwise just return 'default' +-- This should prevent Neovim from complaining about missing colorschemes on first boot +local function get_if_available(name, opts) + local lua_ok, colorscheme = pcall(require, name) + if lua_ok then + colorscheme.setup(opts) + return name + end + + local vim_ok, _ = pcall(vim.cmd.colorscheme, name) + if vim_ok then + return name + end + + return "default" +end + +-- Uncomment the colorscheme to use +-- local colorscheme = get_if_available('gruvbox') +-- local colorscheme = get_if_available('rose-pine') +local colorscheme = get_if_available('catppuccin') +-- local colorscheme = get_if_available('melange') + +return colorscheme diff --git a/lua/helpers/keys.lua b/lua/helpers/keys.lua new file mode 100644 index 0000000..3bf4079 --- /dev/null +++ b/lua/helpers/keys.lua @@ -0,0 +1,21 @@ +local M = {} + +M.map = function(mode, lhs, rhs, desc) + vim.keymap.set(mode, lhs, rhs, { silent = true, desc = desc }) +end + +M.lsp_map = function(lhs, rhs, bufnr, desc) + vim.keymap.set("n", lhs, rhs, { silent = true, buffer = bufnr, desc = desc }) +end + +M.dap_map = function(mode, lhs, rhs, desc) + M.map(mode, lhs, rhs, desc) +end + +M.set_leader = function(key) + vim.g.mapleader = key + vim.g.maplocalleader = key + M.map({ "n", "v" }, key, "") +end + +return M diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua new file mode 100644 index 0000000..134d1b9 --- /dev/null +++ b/lua/plugins/bufferline.lua @@ -0,0 +1,9 @@ +-- See current buffers at the top of the editor +return { + { + "akinsho/bufferline.nvim", + version = "v3.*", + dependencies = "nvim-tree/nvim-web-devicons", + opts = {}, + }, +} diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua new file mode 100644 index 0000000..8b8b970 --- /dev/null +++ b/lua/plugins/cmp.lua @@ -0,0 +1,105 @@ +-- Autocompletion +return { + { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-nvim-lua", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + "rafamadriz/friendly-snippets", + }, + config = function() + local cmp = require("cmp") + local luasnip = require("luasnip") + + require("luasnip/loaders/from_vscode").lazy_load() + + local kind_icons = { + Text = "", + Method = "m", + Function = "", + Constructor = "", + Field = "", + Variable = "", + Class = "", + Interface = "", + Module = "", + Property = "", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", + } + + cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }), + [""] = 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 = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + -- Kind icons + vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + vim_item.menu = ({ + nvim_lsp = "[LSP]", + luasnip = "[Snippet]", + buffer = "[Buffer]", + path = "[Path]", + })[entry.source.name] + return vim_item + end, + }, + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }, + }) + end, + }, +} diff --git a/lua/plugins/git.lua b/lua/plugins/git.lua new file mode 100644 index 0000000..1a4c935 --- /dev/null +++ b/lua/plugins/git.lua @@ -0,0 +1,31 @@ +-- Git related plugins +return { + { + "lewis6991/gitsigns.nvim", + opts = {}, + }, + { + "akinsho/git-conflict.nvim", + commit = "2957f74", + config = function() + require("git-conflict").setup({ + default_mappings = { + ours = "co", + theirs = "ct", + none = "c0", + both = "cb", + next = "cn", + prev = "cp", + }, + }) + end, + }, + { + "tpope/vim-fugitive", + config = function () + local map = require("helpers.keys").map + map("n", "ga", "Git add %", "Stage the current file") + map("n", "gb", "Git blame", "Show the blame") + end + } +} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..8e3a539 --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,143 @@ +-- LSP Configuration & Plugins +return { + { + "neovim/nvim-lspconfig", + dependencies = { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + "j-hui/fidget.nvim", + "folke/neodev.nvim", + "RRethy/vim-illuminate", + "hrsh7th/cmp-nvim-lsp", + }, + config = function() + -- Set up Mason before anything else + require("mason").setup() + require("mason-lspconfig").setup({ + ensure_installed = { + "lua_ls", + "pylsp", + }, + automatic_installation = true, + }) + + -- Quick access via keymap + require("helpers.keys").map("n", "M", "Mason", "Show Mason") + + -- Neodev setup before LSP config + require("neodev").setup() + + -- Turn on LSP status information + require("fidget").setup() + + -- Set up cool signs for diagnostics + 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 = "" }) + end + + -- Diagnostic config + local config = { + virtual_text = false, + signs = { + active = signs, + }, + update_in_insert = true, + underline = true, + severity_sort = true, + float = { + focusable = true, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, + } + vim.diagnostic.config(config) + + -- This function gets run when an LSP connects to a particular buffer. + local on_attach = function(client, bufnr) + local lsp_map = require("helpers.keys").lsp_map + + lsp_map("lr", vim.lsp.buf.rename, bufnr, "Rename symbol") + lsp_map("la", vim.lsp.buf.code_action, bufnr, "Code action") + lsp_map("ld", vim.lsp.buf.type_definition, bufnr, "Type definition") + lsp_map("ls", require("telescope.builtin").lsp_document_symbols, bufnr, "Document symbols") + + lsp_map("gd", vim.lsp.buf.definition, bufnr, "Goto Definition") + lsp_map("gr", require("telescope.builtin").lsp_references, bufnr, "Goto References") + lsp_map("gI", vim.lsp.buf.implementation, bufnr, "Goto Implementation") + lsp_map("K", vim.lsp.buf.hover, bufnr, "Hover Documentation") + lsp_map("gD", vim.lsp.buf.declaration, bufnr, "Goto Declaration") + + -- Create a command `:Format` local to the LSP buffer + vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_) + vim.lsp.buf.format() + end, { desc = "Format current buffer with LSP" }) + + lsp_map("ff", "Format", bufnr, "Format") + + -- Attach and configure vim-illuminate + require("illuminate").on_attach(client) + end + + -- nvim-cmp supports additional completion capabilities, so broadcast that to servers + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) + + -- Lua + require("lspconfig")["lua_ls"].setup({ + on_attach = on_attach, + capabilities = capabilities, + settings = { + Lua = { + completion = { + callSnippet = "Replace", + }, + diagnostics = { + globals = { "vim" }, + }, + workspace = { + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + }, + }, + }, + }, + }) + + -- Python + require("lspconfig")["pylsp"].setup({ + on_attach = on_attach, + capabilities = capabilities, + settings = { + pylsp = { + plugins = { + flake8 = { + enabled = true, + maxLineLength = 88, -- Black's line length + }, + -- Disable plugins overlapping with flake8 + pycodestyle = { + enabled = false, + }, + mccabe = { + enabled = false, + }, + pyflakes = { + enabled = false, + }, + -- Use Black as the formatter + autopep8 = { + enabled = false, + }, + }, + }, + }, + }) + end, + }, +} diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 0000000..f0097d7 --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,15 @@ +-- Fancier statusline +return { + "nvim-lualine/lualine.nvim", + config = function() + local colorscheme = require("helpers.colorscheme") + local lualine_theme = colorscheme == "default" and "auto" or colorscheme + require("lualine").setup({ + options = { + icons_enabled = true, + theme = lualine_theme, + component_separators = "|", + section_separators = "", + }, + }) + end, } diff --git a/lua/plugins/misc.lua b/lua/plugins/misc.lua new file mode 100644 index 0000000..01635dd --- /dev/null +++ b/lua/plugins/misc.lua @@ -0,0 +1,25 @@ +-- Miscelaneous fun stuff +return { + -- Comment with haste + { + "numToStr/Comment.nvim", + opts = {}, + }, + -- Move stuff with and in both normal and visual mode + { + "echasnovski/mini.move", + config = function() + require("mini.move").setup() + end, + }, + -- Better buffer closing actions. Available via the buffers helper. + { + "kazhala/close-buffers.nvim", + opts = { + preserve_window_layout = { "this", "nameless" }, + }, + }, + "tpope/vim-sleuth", -- Detect tabstop and shiftwidth automatically + "tpope/vim-surround", -- Surround stuff with the ys-, cs-, ds- commands + "mrjones2014/nvim-ts-rainbow", +} diff --git a/lua/plugins/neo-tree.lua b/lua/plugins/neo-tree.lua new file mode 100644 index 0000000..54faf1d --- /dev/null +++ b/lua/plugins/neo-tree.lua @@ -0,0 +1,27 @@ +-- Nicer filetree than NetRW +return { + { + "nvim-neo-tree/neo-tree.nvim", + branch = "v2.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", + "MunifTanjim/nui.nvim", + }, + config = function() + require("neo-tree").setup({ + close_if_last_window=true, + filesystem = { + follow_current_file = { enable=true }, + use_libuv_file_watcher=true, + }, + }) + require("helpers.keys").map( + { "n", "v" }, + "e", + "NeoTreeRevealToggle", + "Toggle file explorer" + ) + end, + }, +} diff --git a/lua/plugins/null-ls.lua b/lua/plugins/null-ls.lua new file mode 100644 index 0000000..09d1cf7 --- /dev/null +++ b/lua/plugins/null-ls.lua @@ -0,0 +1,19 @@ +return { + { + "jose-elias-alvarez/null-ls.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + }, + config = function() + local null_ls = require("null-ls") + null_ls.setup({ + sources = { + null_ls.builtins.formatting.stylua, + null_ls.builtins.formatting.clang_format, + null_ls.builtins.formatting.black, + null_ls.builtins.formatting.isort, + }, + }) + end, + }, +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..37eab7b --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,46 @@ +-- Telescope fuzzy finding (all the things) +return { + { + "nvim-telescope/telescope.nvim", + branch = "0.1.x", + dependencies = { + "nvim-lua/plenary.nvim", + -- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available + { "nvim-telescope/telescope-fzf-native.nvim", build = "make", cond = vim.fn.executable("make") == 1 }, + }, + config = function() + require("telescope").setup({ + defaults = { + mappings = { + i = { + [""] = false, + [""] = false, + }, + }, + }, + }) + + -- Enable telescope fzf native, if installed + pcall(require("telescope").load_extension, "fzf") + + local map = require("helpers.keys").map + map("n", "fr", require("telescope.builtin").oldfiles, "Recently opened") + map("n", "", require("telescope.builtin").buffers, "Open buffers") + map("n", "/", function() + -- You can pass additional configuration to telescope to change theme, layout, etc. + require("telescope.builtin").current_buffer_fuzzy_find(require("telescope.themes").get_dropdown({ + winblend = 10, + previewer = false, + })) + end, "Search in current buffer") + + map("n", "sf", require("telescope.builtin").find_files, "Files") + map("n", "sh", require("telescope.builtin").help_tags, "Help") + map("n", "sw", require("telescope.builtin").grep_string, "Current word") + map("n", "sg", require("telescope.builtin").live_grep, "Grep") + map("n", "sd", require("telescope.builtin").diagnostics, "Diagnostics") + + map("n", "", require("telescope.builtin").keymaps, "Search keymaps") + end, + }, +} diff --git a/lua/plugins/themes.lua b/lua/plugins/themes.lua new file mode 100644 index 0000000..63654c6 --- /dev/null +++ b/lua/plugins/themes.lua @@ -0,0 +1,20 @@ +-- Themes +return { + "typicode/bg.nvim", + + "ellisonleao/gruvbox.nvim", + + { + "catppuccin/nvim", + name = "catppuccin", + }, + + { + "rose-pine/nvim", + name = "rose-pine", + }, + + "sainnhe/everforest", + + "savq/melange-nvim" +} diff --git a/lua/plugins/toggleterm.lua b/lua/plugins/toggleterm.lua new file mode 100644 index 0000000..30c841b --- /dev/null +++ b/lua/plugins/toggleterm.lua @@ -0,0 +1,12 @@ +return { + { + 'akinsho/toggleterm.nvim', + version = "*", + config = { + direction = 'float', + shell = 'fish', + float_opts = { border = 'curved' }, + open_mapping = [[]], + } + } +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..8265952 --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,65 @@ +-- Highlight, edit, and navigate code +return { + { + "nvim-treesitter/nvim-treesitter", + build = function() + pcall(require("nvim-treesitter.install").update({ with_sync = true })) + end, + dependencies = { + "nvim-treesitter/nvim-treesitter-textobjects", + }, + config = function() + require("nvim-treesitter.configs").setup({ + -- Add languages to be installed here that you want installed for treesitter + ensure_installed = { "c", "cpp", "go", "lua", "python", "rust", "vim" }, + + highlight = { enable = true }, + indent = { enable = true, disable = { "python" } }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "", + node_incremental = "", + scope_incremental = "", + node_decremental = "", + }, + }, + textobjects = { + select = { + enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ["aa"] = "@parameter.outer", + ["ia"] = "@parameter.inner", + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + ["ic"] = "@class.inner", + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + ["]m"] = "@function.outer", + ["]]"] = "@class.outer", + }, + goto_next_end = { + ["]M"] = "@function.outer", + ["]["] = "@class.outer", + }, + goto_previous_start = { + ["[m"] = "@function.outer", + ["[["] = "@class.outer", + }, + goto_previous_end = { + ["[M"] = "@function.outer", + ["[]"] = "@class.outer", + }, + }, + }, + }) + end, + }, +} diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua new file mode 100644 index 0000000..366cae5 --- /dev/null +++ b/lua/plugins/which-key.lua @@ -0,0 +1,25 @@ +return { + { + "folke/which-key.nvim", + config = function() + local wk = require("which-key") + wk.setup() + wk.register( + { + [""] = { + f = { name = "File" }, + d = { name = "Delete/Close" }, + q = { name = "Quit" }, + s = { name = "Search" }, + l = { name = "LSP" }, + u = { name = "UI" }, + b = { name = "Debugging" }, + g = { name = "Git" }, + N = { name = "Neovim" }, + p = { name = "Plugins" } + } + } + ) + end + } +}