From 851bdaa61113d25739c44fececa11c86beb35848 Mon Sep 17 00:00:00 2001 From: Triston Date: Wed, 26 Jun 2024 20:49:17 -0400 Subject: [PATCH] init config base --- init.lua | 4 + lazy-lock.json | 22 +++++ lua/config/keymaps.lua | 28 ++++++ lua/config/lazy.lua | 31 +++++++ lua/config/util.lua | 22 +++++ lua/plugins/bufferline.lua | 10 +++ lua/plugins/gitsigns.lua | 20 +++++ lua/plugins/lazygit.lua | 20 +++++ lua/plugins/lsp.lua | 175 +++++++++++++++++++++++++++++++++++++ lua/plugins/mason.lua | 8 ++ lua/plugins/oil.lua | 6 ++ lua/plugins/supermaven.lua | 12 +++ lua/plugins/telescope.lua | 3 + lua/plugins/theme.lua | 3 + lua/plugins/whichkey.lua | 25 ++++++ 15 files changed, 389 insertions(+) create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lua/config/keymaps.lua create mode 100644 lua/config/lazy.lua create mode 100644 lua/config/util.lua create mode 100644 lua/plugins/bufferline.lua create mode 100644 lua/plugins/gitsigns.lua create mode 100644 lua/plugins/lazygit.lua create mode 100644 lua/plugins/lsp.lua create mode 100644 lua/plugins/mason.lua create mode 100644 lua/plugins/oil.lua create mode 100644 lua/plugins/supermaven.lua create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/plugins/theme.lua create mode 100644 lua/plugins/whichkey.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..bf1f53a --- /dev/null +++ b/init.lua @@ -0,0 +1,4 @@ +require("config.keymaps") +require("config.lazy") + +vim.cmd.colorscheme "catppuccin-mocha" diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..77e8eec --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,22 @@ +{ + "LuaSnip": { "branch": "master", "commit": "ba3ea5bcfd969679f38fefb1bc801cd45524045b" }, + "bufferline.nvim": { "branch": "main", "commit": "99337f63f0a3c3ab9519f3d1da7618ca4f91cffe" }, + "catppuccin": { "branch": "main", "commit": "894efb557728e532aa98b98029d16907a214ec05" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "gitsigns.nvim": { "branch": "main", "commit": "fa42613096ebfa5fee1ea87d70f8625ab9685d01" }, + "lazy.nvim": { "branch": "main", "commit": "aa1c9572aa1916e582f9b9c3d43e272b4f23b326" }, + "lazygit.nvim": { "branch": "main", "commit": "ad3e1ea592f9d13e86e0d4e850224d9d78069508" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "37a336b653f8594df75c827ed589f1c91d91ff6c" }, + "mason.nvim": { "branch": "main", "commit": "0950b15060067f752fde13a779a994f59516ce3d" }, + "nvim-cmp": { "branch": "main", "commit": "a110e12d0b58eefcf5b771f533fc2cf3050680ac" }, + "nvim-lspconfig": { "branch": "master", "commit": "9c9eb07fecc578e25e28db8dc9002b43fff2ed79" }, + "nvim-web-devicons": { "branch": "master", "commit": "c0cfc1738361b5da1cd0a962dd6f774cc444f856" }, + "oil.nvim": { "branch": "master", "commit": "65c53dbe4f2140236590a7568a5f22a77d16be39" }, + "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, + "supermaven-nvim": { "branch": "main", "commit": "ec7ae4c8190c96002aa466b1eb4a23aa51e24812" }, + "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, + "which-key.nvim": { "branch": "main", "commit": "0099511294f16b81c696004fa6a403b0ae61f7a0" } +} \ No newline at end of file diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua new file mode 100644 index 0000000..0525b2b --- /dev/null +++ b/lua/config/keymaps.lua @@ -0,0 +1,28 @@ +local map = vim.keymap.set +vim.g.mapleader = " " + +map({ "n", "v" }, "", "", { silent = true }) +map("n", "Q", "") +map("n", "q:", "") +map("n", "", "") +map("n", "", "w") +map("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) +map("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) +map("n", "", '{->v:hlsearch ? ":nohl\\" : "\\"}()', { expr = true }) +map("v", "J", ":m '>+1gv=gv") +map("v", "K", ":m '<-2gv=gv") + +-- Buffers +map("n", "", "bn") +map("n", "", "bp") +map("n", "bd", "bd") + +-- Visual +map("x", "<", "", ">gv") +map("x", "K", ":move '<-2gv-gv") +map("x", "J", ":move '>+1gv-gv") + +-- Oil keymaps +map("n", "e", "Oil") + diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua new file mode 100644 index 0000000..e9733fe --- /dev/null +++ b/lua/config/lazy.lua @@ -0,0 +1,31 @@ +-- 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" + vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) +end +vim.opt.rtp:prepend(lazypath) + +-- Make sure to setup `mapleader` and `maplocalleader` before +-- loading lazy.nvim so that mappings are correct. +-- This is also a good place to setup other settings (vim.opt) +vim.g.mapleader = " " +vim.g.maplocalleader = "\\" +vim.opt.ignorecase = true +vim.opt.smartcase = true +vim.opt.inccommand = "split" +vim.opt.termguicolors = true +vim.opt.number = true + +-- Setup lazy.nvim +require("lazy").setup({ + spec = { + -- import your plugins + { import = "plugins" }, + }, + -- Configure any other settings here. See the documentation for more details. + -- colorscheme that will be used when installing plugins. + install = { colorscheme = { "catpuccin-mocha" } }, + -- automatically check for plugin updates + checker = { enabled = true, notify = false }, +}) diff --git a/lua/config/util.lua b/lua/config/util.lua new file mode 100644 index 0000000..6244d36 --- /dev/null +++ b/lua/config/util.lua @@ -0,0 +1,22 @@ +local Util = require("lazy.core.util") + +local M = {} + +M.format_on_save = true +function M.toggle_format_on_save() + if vim.b.autoformat == false then + vim.b.autoformat = nil + M.format_on_save = true + else + M.format_on_save = not M.format_on_save + end + + if M.format_on_save then + Util.info("Enabled format on save", { title = "Format" }) + else + Util.warn("Disabled format on save", { title = "Format" }) + end +end + + +return M diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua new file mode 100644 index 0000000..77aa0e5 --- /dev/null +++ b/lua/plugins/bufferline.lua @@ -0,0 +1,10 @@ +return { + { + 'akinsho/bufferline.nvim', + version = "*", + dependencies = 'nvim-tree/nvim-web-devicons', + config = function() + require('bufferline').setup() + end, + }, +} diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..179267c --- /dev/null +++ b/lua/plugins/gitsigns.lua @@ -0,0 +1,20 @@ +return { + "lewis6991/gitsigns.nvim", + event = { "BufReadPre", "BufNewFile" }, + opts = { + signs = { + add = { text = "▎" }, + change = { text = "▎" }, + delete = { text = "" }, + topdelete = { text = "" }, + changedelete = { text = "▎" }, + untracked = { text = "▎" }, + }, + current_line_blame_formatter = ", - ", + current_line_blame = true, -- Toggle with `:Gitsigns toggle_current_line_blame` + }, + keys = { + { "]g", "Gitsigns next_hunk", desc = "Next Git Hunk" }, + { "[g", "Gitsigns prev_hunk", desc = "Previous Git Hunk" }, + }, +} diff --git a/lua/plugins/lazygit.lua b/lua/plugins/lazygit.lua new file mode 100644 index 0000000..0080dd8 --- /dev/null +++ b/lua/plugins/lazygit.lua @@ -0,0 +1,20 @@ +-- nvim v0.8.0 +return { + "kdheepak/lazygit.nvim", + cmd = { + "LazyGit", + "LazyGitConfig", + "LazyGitCurrentFile", + "LazyGitFilter", + "LazyGitFilterCurrentFile", + }, + -- optional for floating window border decoration + dependencies = { + "nvim-lua/plenary.nvim", + }, + -- setting the keybinding for LazyGit with 'keys' is recommended in + -- order to load the plugin when the command is run for the first time + keys = { + { "gg", "LazyGit", desc = "LazyGit" } + } +} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..ea55a46 --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,175 @@ +return { + { + "neovim/nvim-lspconfig", + event = { "BufReadPre", "BufNewFile" }, + dependencies = { + -- LSP Support + { "williamboman/mason.nvim", cmd = "Mason", build = ":MasonUpdate" }, + { + "williamboman/mason-lspconfig.nvim", + config = function(_, opts) end, + }, + }, + + ---@class PluginLspOpts + opts = { + ---@type lspconfig.options + servers = { + tsserver = { + settings = {}, + }, + lua_ls = { + settings = { Lua = { diagnostics = { globals = { "vim" } } } }, + }, + }, + }, + config = function(_, opts) + require("mason").setup() + local mason_lspconfig = require("mason-lspconfig") + local lsp_config = require("lspconfig") + + local lsp_capabilities = vim.tbl_deep_extend( + "force", + {}, + vim.lsp.protocol.make_client_capabilities(), + require("cmp_nvim_lsp").default_capabilities() + ) + + local lsp_attach = function(client, bufnr) + local key_opts = { buffer = bufnr, remap = false } + + -- Keymaps + vim.keymap.set("n", "K", vim.lsp.buf.hover, key_opts) + vim.keymap.set("n", "gd", vim.lsp.buf.definition, key_opts) + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, key_opts) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, key_opts) + vim.keymap.set("n", "gr", vim.lsp.buf.references, key_opts) + vim.keymap.set("n", "[d", vim.diagnostic.goto_next, key_opts) + vim.keymap.set("n", "]d", vim.diagnostic.goto_prev, key_opts) + vim.keymap.set("n", "df", vim.diagnostic.open_float, key_opts) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action, key_opts) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, key_opts) + vim.keymap.set("i", "", vim.lsp.buf.signature_help, key_opts) + end + + mason_lspconfig.setup({ + ensure_installed = { + "cssls", + "emmet_ls", + "eslint", + "jsonls", + "lua_ls", + --"tailwindcss", + "tsserver", + -- linter + -- "eslint_d", + -- formatter + -- "stylua", + -- "prettierd", + }, + }) + mason_lspconfig.setup_handlers({ + function(server_name) + lsp_config[server_name].setup({ + on_attach = lsp_attach, + capabilities = lsp_capabilities, + settings = opts.servers[server_name] and opts.servers[server_name].settings or {}, + }) + end, + }) + + vim.diagnostic.config({ + underline = true, + update_in_insert = false, + virtual_text = { + spacing = 4, + source = "if_many", + }, + severity_sort = true, + float = { + focusable = true, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, + }) + end, + }, + { + "L3MON4D3/LuaSnip", + build = (not jit.os:find("Windows")) + and "echo -e 'NOTE: jsregexp is optional, so not a big deal if it fails to build\n'; make install_jsregexp" + or nil, + -- dependencies = { + -- "rafamadriz/friendly-snippets", + -- config = function() + -- require("luasnip.loaders.from_vscode").lazy_load() + -- end, + -- }, + }, + { + "hrsh7th/nvim-cmp", + version = false, -- last release is way too old + event = "InsertEnter", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "saadparwaiz1/cmp_luasnip", + }, + config = function() + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + local luasnip = require("luasnip") + local cmp = require("cmp") + local compare = require("cmp.config.compare") + + cmp.setup({ + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + sources = cmp.config.sources({ + { name = "nvim_lsp", priority = 1 }, + { name = "luasnip", priority = 5, keyword_length = 2 }, + -- { name = "buffer", priority = 10, keyword_length = 3 }, + { name = "path", priority = 2 }, + }), + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() + -- they way you will only jump inside the snippet region + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + 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" }), + }), + }) + end, + } +} diff --git a/lua/plugins/mason.lua b/lua/plugins/mason.lua new file mode 100644 index 0000000..79f57ad --- /dev/null +++ b/lua/plugins/mason.lua @@ -0,0 +1,8 @@ +return { + { + "williamboman/mason.nvim", + config = function() + require("mason").setup() + end +} +} diff --git a/lua/plugins/oil.lua b/lua/plugins/oil.lua new file mode 100644 index 0000000..93b3a77 --- /dev/null +++ b/lua/plugins/oil.lua @@ -0,0 +1,6 @@ +return { + 'stevearc/oil.nvim', + opts = {}, + -- Optional dependencies + dependencies = { "nvim-tree/nvim-web-devicons" }, +} diff --git a/lua/plugins/supermaven.lua b/lua/plugins/supermaven.lua new file mode 100644 index 0000000..f446e4b --- /dev/null +++ b/lua/plugins/supermaven.lua @@ -0,0 +1,12 @@ +return { + "supermaven-inc/supermaven-nvim", + config = function() + require("supermaven-nvim").setup({ + keymap = { + accept_suggestion = "", + clear_suggestion = "", + accept_word = "", + } + }) + end, +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..adfbbac --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,3 @@ +return { + 'nvim-telescope/telescope.nvim', tag = '0.1.8', + } diff --git a/lua/plugins/theme.lua b/lua/plugins/theme.lua new file mode 100644 index 0000000..8261c54 --- /dev/null +++ b/lua/plugins/theme.lua @@ -0,0 +1,3 @@ +return { +{ "catppuccin/nvim", name = "catppuccin", priority = 1000 } +} diff --git a/lua/plugins/whichkey.lua b/lua/plugins/whichkey.lua new file mode 100644 index 0000000..c03e0bc --- /dev/null +++ b/lua/plugins/whichkey.lua @@ -0,0 +1,25 @@ +return { + "folke/which-key.nvim", + event = "VeryLazy", + init = function() + vim.o.timeout = true + vim.o.timeoutlen = 300 + end, + config = function() + local wk = require("which-key") + -- f key register + wk.register({ + f = { + name = "Buffers", + f = { "Telescope buffers", "Find Buffer" } + } + }, { prefix = "" }) + + + -- q key register + wk.register({ + q = {"bdelete", "Close Buffer"} + }, { prefix = "" }) + + end +}