From 4c8fadee5527d0da7a25abaab8d692d4858a1ec3 Mon Sep 17 00:00:00 2001 From: Bryan Ramos Date: Tue, 20 Aug 2024 16:53:12 -0400 Subject: [PATCH] new nvim config WIP --- nvim/.luarc.json | 5 ++ nvim/init.lua | 11 +++ nvim/lazy-lock.json | 20 +++++ nvim/lua/config/keymaps.lua | 21 +++++ nvim/lua/config/lazy.lua | 35 +++++++++ nvim/lua/config/options.lua | 31 ++++++++ nvim/lua/plugins/colorscheme.lua | 35 +++++++++ nvim/lua/plugins/gitsigns.lua | 59 ++++++++++++++ nvim/lua/plugins/indent-blankline.lua | 5 ++ nvim/lua/plugins/lsp.lua | 106 ++++++++++++++++++++++++++ nvim/lua/plugins/lualine.lua | 48 ++++++++++++ nvim/lua/plugins/neotree.lua | 24 ++++++ nvim/lua/plugins/telescope.lua | 34 +++++++++ nvim/lua/plugins/which-key.lua | 29 +++++++ 14 files changed, 463 insertions(+) create mode 100644 nvim/.luarc.json create mode 100644 nvim/init.lua create mode 100644 nvim/lazy-lock.json create mode 100644 nvim/lua/config/keymaps.lua create mode 100644 nvim/lua/config/lazy.lua create mode 100644 nvim/lua/config/options.lua create mode 100644 nvim/lua/plugins/colorscheme.lua create mode 100644 nvim/lua/plugins/gitsigns.lua create mode 100644 nvim/lua/plugins/indent-blankline.lua create mode 100644 nvim/lua/plugins/lsp.lua create mode 100644 nvim/lua/plugins/lualine.lua create mode 100644 nvim/lua/plugins/neotree.lua create mode 100644 nvim/lua/plugins/telescope.lua create mode 100644 nvim/lua/plugins/which-key.lua diff --git a/nvim/.luarc.json b/nvim/.luarc.json new file mode 100644 index 0000000..6779f74 --- /dev/null +++ b/nvim/.luarc.json @@ -0,0 +1,5 @@ +{ + "diagnostics.disable": [ + "missing-fields" + ] +} \ No newline at end of file diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..dd3b61d --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,11 @@ +local function load_config_directory(directory) + local config_path = vim.fn.stdpath("config") .. "/lua/" .. directory + local files = vim.fn.glob(config_path .. "/*.lua", false, true) + + for _, file in ipairs(files) do + local file_name = vim.fn.fnamemodify(file, ":t:r") -- Extract filename without extension + require(directory .. "." .. file_name) + end +end + +load_config_directory("config") diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json new file mode 100644 index 0000000..5a1b478 --- /dev/null +++ b/nvim/lazy-lock.json @@ -0,0 +1,20 @@ +{ + "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" }, + "base16-vim": { "branch": "master", "commit": "3be3cd82cd31acfcab9a41bad853d9c68d30478d" }, + "gitsigns.nvim": { "branch": "main", "commit": "562dc47189ad3c8696dbf460d38603a74d544849" }, + "indent-blankline.nvim": { "branch": "master", "commit": "db926997af951da38e5004ec7b9fbdc480b48f5d" }, + "lazy.nvim": { "branch": "main", "commit": "077102c5bfc578693f12377846d427f49bc50076" }, + "lualine.nvim": { "branch": "master", "commit": "b431d228b7bbcdaea818bdc3e25b8cdbe861f056" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "1c55991321d1a861537e32446affc5de5d9a6eaf" }, + "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, + "neo-tree.nvim": { "branch": "main", "commit": "206241e451c12f78969ff5ae53af45616ffc9b72" }, + "nui.nvim": { "branch": "main", "commit": "61574ce6e60c815b0a0c4b5655b8486ba58089a1" }, + "nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" }, + "nvim-lspconfig": { "branch": "master", "commit": "dddd0945c0f31a0abd843425927a1712d2db2e10" }, + "nvim-treesitter": { "branch": "master", "commit": "6699eae8ba4551fe927da0f0f3f61ae085f836aa" }, + "nvim-treesitter-context": { "branch": "master", "commit": "0f3332788e0bd37716fbd25f39120dcfd557c90f" }, + "nvim-web-devicons": { "branch": "master", "commit": "3722e3d1fb5fe1896a104eb489e8f8651260b520" }, + "plenary.nvim": { "branch": "master", "commit": "ec289423a1693aeae6cd0d503bac2856af74edaa" }, + "telescope.nvim": { "branch": "master", "commit": "5972437de807c3bc101565175da66a1aa4f8707a" }, + "which-key.nvim": { "branch": "main", "commit": "6c1584eb76b55629702716995cca4ae2798a9cca" } +} diff --git a/nvim/lua/config/keymaps.lua b/nvim/lua/config/keymaps.lua new file mode 100644 index 0000000..50d7406 --- /dev/null +++ b/nvim/lua/config/keymaps.lua @@ -0,0 +1,21 @@ +-- Keep cursor centered while navigating document +vim.keymap.set("n", "", "zz", { silent = true }) +vim.keymap.set("n", "", "zz", { silent = true }) + +-- Remap Ctrl + J/K/H/L to navigate between windows +vim.keymap.set('n', '', 'j', { noremap = true, silent = true }) +vim.keymap.set('n', '', 'k', { noremap = true, silent = true }) +vim.keymap.set('n', '', 'h', { noremap = true, silent = true }) +vim.keymap.set('n', '', 'l', { noremap = true, silent = true }) + +vim.keymap.set('n', '', ':vertical resize +10', { noremap = true, silent = true }) +vim.keymap.set('n', '', ':vertical resize -10', { noremap = true, silent = true }) +vim.keymap.set('n', '', ':horizontal resize +10', { noremap = true, silent = true }) +vim.keymap.set('n', '', ':horizontal resize -10', { noremap = true, silent = true }) + +-- Remap Shift + H/L to switch between buffers +vim.keymap.set('n', '', ':bprevious', { noremap = true, silent = true }) +vim.keymap.set('n', '', ':bnext', { noremap = true, silent = true }) + +vim.keymap.set("v", "<", "", ">gv") diff --git a/nvim/lua/config/lazy.lua b/nvim/lua/config/lazy.lua new file mode 100644 index 0000000..0b93d4e --- /dev/null +++ b/nvim/lua/config/lazy.lua @@ -0,0 +1,35 @@ +-- 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) + +-- 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 = "\\" + +-- 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 = { "habamax" } }, + -- automatically check for plugin updates + checker = { enabled = false }, +}) diff --git a/nvim/lua/config/options.lua b/nvim/lua/config/options.lua new file mode 100644 index 0000000..807f25c --- /dev/null +++ b/nvim/lua/config/options.lua @@ -0,0 +1,31 @@ +vim.o.clipboard = "unnamedplus" +vim.g.autoformat = false + +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.cursorline = true + +vim.opt.tabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.softtabstop = 2 +vim.opt.expandtab = true +vim.opt.smartindent = true +vim.opt.ignorecase = true +vim.opt.smartcase = false +vim.opt.incsearch = false + +vim.opt.swapfile = false +vim.opt.backup = false +vim.opt.undofile = true + +vim.o.termguicolors = false +vim.opt.guicursor = "n-v-c:block,i:block,r:block" +vim.opt.fillchars = { eob = " " } + +vim.cmd([[ + autocmd FileType python,haskell,c,cpp setlocal tabstop=4 shiftwidth=4 softtabstop=4 +]]) + +vim.cmd([[ + au BufRead,BufNewFile *.purs set filetype=purescript +]]) diff --git a/nvim/lua/plugins/colorscheme.lua b/nvim/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..6a74597 --- /dev/null +++ b/nvim/lua/plugins/colorscheme.lua @@ -0,0 +1,35 @@ +return { + { + "chriskempson/base16-vim", + config = function() + vim.cmd("colorscheme base16-onedark") + vim.cmd([[ + hi Normal guibg=NONE ctermbg=NONE + hi NonText guibg=NONE ctermbg=NONE + hi LineNr guibg=NONE ctermbg=NONE + hi CursorLine guibg=NONE ctermbg=NONE + hi CursorLineNr guibg=NONE ctermbg=NONE guifg=#E5C07B ctermfg=Yellow cterm=bold + hi Search ctermfg=Black guifg=#000000 ctermbg=Gray guibg=#FFCC66 + hi Pmenu ctermbg=Gray ctermfg=Black cterm=NONE guibg=Gray guifg=Black gui=NONE + hi PmenuSel ctermbg=Black ctermfg=Green cterm=NONE guibg=Black guifg=Green gui=NONE + hi PmenuThumb ctermbg=Green guibg=Green + hi PmenuSbar ctermbg=Black guibg=Black + hi WinSeparator guibg=NONE ctermbg=NONE + + hi GitGutterChange guibg=NONE ctermbg=NONE + hi GitGutterAdd guibg=NONE ctermbg=NONE + hi GitGutterDelete guibg=NONE ctermbg=NONE + hi SignColumn ctermbg=NONE guibg=NONE + + hi TelescopeSelection guibg=Gray guifg=Green gui=bold ctermbg=Black ctermfg=Green cterm=bold + hi TelescopePreviewMatch ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black + ]]) + + vim.api.nvim_create_autocmd("TextYankPost", { + callback = function() + vim.highlight.on_yank({ higroup = "IncSearch", timeout = 150 }) + end, + }) + end, + } +} diff --git a/nvim/lua/plugins/gitsigns.lua b/nvim/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..b34952f --- /dev/null +++ b/nvim/lua/plugins/gitsigns.lua @@ -0,0 +1,59 @@ +return { + { + "lewis6991/gitsigns.nvim", + config = function() + require('gitsigns').setup { + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '-' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + untracked = { text = '┆' }, + }, + signs_staged = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '-' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + untracked = { text = '┆' }, + }, + signs_staged_enable = true, + signcolumn = false, -- Toggle with `:Gitsigns toggle_signs` + numhl = true, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + watch_gitdir = { + follow_files = true + }, + auto_attach = true, + attach_to_untracked = false, + current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` + current_line_blame_opts = { + virt_text = true, + virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align' + delay = 0, + ignore_whitespace = false, + virt_text_priority = 100, + }, + current_line_blame_formatter = ', - ', + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, -- Use default + max_file_length = 40000, -- Disable if file is longer than this (in lines) + preview_config = { + -- Options passed to nvim_open_win + border = 'single', + style = 'minimal', + relative = 'cursor', + row = 0, + col = 1 + }, + } + require("which-key").add({ + { "Gb", ":Gitsigns toggle_current_line_blame", desc = "Git blame" } + }) + end + } +} diff --git a/nvim/lua/plugins/indent-blankline.lua b/nvim/lua/plugins/indent-blankline.lua new file mode 100644 index 0000000..2af5796 --- /dev/null +++ b/nvim/lua/plugins/indent-blankline.lua @@ -0,0 +1,5 @@ +return { + { + "lukas-reineke/indent-blankline.nvim", + } +} diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..ad5d79e --- /dev/null +++ b/nvim/lua/plugins/lsp.lua @@ -0,0 +1,106 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + require('nvim-treesitter.configs').setup { + ensure_installed = { + "lua", + "c", + "cpp", + "python", + "nix", + "rust", + "bash", + "markdown", + "html", + "javascript", + "css", + + "vim", + + "git_config", + "git_rebase", + "gitattributes", + "gitcommit", + "gitignore" + }, + auto_install = true, + sync_install = true, + ignore_install = {}, + } + end + }, + + { + "nvim-treesitter/nvim-treesitter-context", + config = function() + require("treesitter-context").setup({ + enable = true, -- Enable this plugin (Can be enabled/disabled later via commands) + max_lines = 3, -- How many lines the window should span. Values <= 0 mean no limit. + min_window_height = 0, -- Minimum editor window height to enable context. Values <= 0 mean no limit. + line_numbers = false, + multiline_threshold = 20, -- Maximum number of lines to collapse for a single context line + trim_scope = "outer", -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer' + mode = "cursor", -- Line used to calculate context. Choices: 'cursor', 'topline' + -- Separator between context and content. Should be a single character string, like '-'. + -- When separator is set, the context will only show up when there are at least 2 lines above cursorline. + separator = "=", + zindex = 20, -- The Z-index of the context window + on_attach = nil, -- (fun(buf: integer): boolean) rurn false to disable attaching + }) + vim.cmd([[ + hi TreesitterContext guibg=NONE ctermbg=NONE + ]]) + end, + }, + + { + "neovim/nvim-lspconfig", + config = function() + require("which-key").add({ + { "cl", ":LspInfo", desc = "LSP Info" }, + }) + end + }, + + { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + }, + + { + "hrsh7th/nvim-cmp", + dependencies = { + { + "L3MON4D3/LuaSnip", + version = "v2.*", + build = "make install_jsregexp", + } + }, + config = function() + local cmp = require("cmp") + cmp.setup({ + enabled = function() + local context = require("cmp.config.context") + if vim.api.nvim_get_mode().mode == "c" then + return true + else + return not context.in_treesitter_capture("comment") and not context.in_syntax_group("comment") + end + end, + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm(), + [""] = cmp.mapping(function(fallback) + fallback() + end, { "i", "s" }), + } + }) + end + }, +} diff --git a/nvim/lua/plugins/lualine.lua b/nvim/lua/plugins/lualine.lua new file mode 100644 index 0000000..46fcf8b --- /dev/null +++ b/nvim/lua/plugins/lualine.lua @@ -0,0 +1,48 @@ +return { + { + "nvim-lualine/lualine.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + require("lualine").setup ({ + options = { + icons_enabled = true, + theme = 'iceberg_dark', + component_separators = { left = '>', right = '|'}, + section_separators = { left = '', right = ''}, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = true, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = {'mode'}, + lualine_b = {'branch', 'diff', 'diagnostics'}, + lualine_c = {'filename'}, + lualine_x = {'encoding', 'fileformat', 'filetype'}, + lualine_y = {'progress'}, + lualine_z = {'location'} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {'filename'}, + lualine_x = {'location'}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} + }) + end + } +} diff --git a/nvim/lua/plugins/neotree.lua b/nvim/lua/plugins/neotree.lua new file mode 100644 index 0000000..d6e32ef --- /dev/null +++ b/nvim/lua/plugins/neotree.lua @@ -0,0 +1,24 @@ +return { + { + "nvim-neo-tree/neo-tree.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + }, + config = function() + require("neo-tree").setup({ + window = { + position = "left", + width = 20, + }, + --filesystem = { + -- hijack_netrw_behavior = "disabled", + --}, + }) + require("which-key").add({ + { "e", ":Neotree", desc = "Neotree" } + }) + end, + }, +} diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..58021ce --- /dev/null +++ b/nvim/lua/plugins/telescope.lua @@ -0,0 +1,34 @@ +return { + { + "nvim-telescope/telescope.nvim", + brach = '0.1.x', + dependencies = { + { + 'nvim-lua/plenary.nvim' + }, + { + 'nvim-tree/nvim-web-devicons' + } + }, + config = function() + require("which-key").add({ + { "/", ":Telescope live_grep", desc = "grep" }, + { "ff", ":Telescope fd", desc = "Search for Files" }, + { "fp", ":Telescope oldfiles", desc = "Oldfiles" }, + { "?", ":Telescope command_history", desc = "Command History" }, + { "cm", ":Telescope man_pages", desc = "Manpages" }, + + -- Code + { "gd", ":Telescope lsp_definitions", desc = "Go to Definition" }, + { "gi", ":Telescope lsp_implementations", desc = "Go to Implementations" }, + { "gt", ":Telescope lsp_type_definitions", desc = "Go to Type Definition" }, + { "cv", ":Telescope treesitter", desc = "List function names & variables" }, + { "ca", ":Telescope diagnostics", desc = "Code diagnostics" }, + + -- Git + { "Gt", ":Telescope git_branches", desc = "Git Branches" }, + { "Gc", ":Telescope git_commits", desc = "Git Commits" }, + }) + end + } +} diff --git a/nvim/lua/plugins/which-key.lua b/nvim/lua/plugins/which-key.lua new file mode 100644 index 0000000..f515201 --- /dev/null +++ b/nvim/lua/plugins/which-key.lua @@ -0,0 +1,29 @@ +return { + { + "folke/which-key.nvim", + event = "VeryLazy", + opts = { + spec = { + { "l", ":Lazy", desc = "Lazy" }, + { "t", ":botright new | setlocal nonumber norelativenumber | resize 10 | terminal", mode = "n", desc = "Open Terminal" }, + + --{ "wd", "execute 'bd' | execute 'close'", desc = "Delete window & buffer" }, + -- Window & Buffer Management + { "w", group = "Windows"}, + { "wc", ":close", desc = "Close Window" }, + { "ws", ":split", desc = "Horizontal Window Split" }, + { "wv", ":vsplit", desc = "Vertial Window Split" }, + { "wm", "_", desc = "Maximize Window" }, + + { "b", group = "Buffers"}, + { "bd", ":bd", desc = "Delete Buffer" }, + { "bD", "execute 'close' | execute 'bd!'", desc = "Delete Window & Buffer" }, + + { "G", group = "Git"}, + { "f", group = "Files"}, + { "c", group = "Code"}, + { "g", group = "Goto"}, + }, + }, + } +}