From 4c2dcb4be160741880a9db398d85e5f6ee3b28da Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Thu, 25 May 2023 21:48:59 -0600 Subject: [PATCH] new neovim config --- common/nvim/after/plugin/barbar.lua | 54 +++++++++++++++++++++++ common/nvim/after/plugin/blankline.lua | 14 ++++++ common/nvim/after/plugin/colors.lua | 42 ++++++++++++++++++ common/nvim/after/plugin/fugitive.lua | 1 + common/nvim/after/plugin/lsp.lua | 58 +++++++++++++++++++++++++ common/nvim/after/plugin/telescope.lua | 6 +++ common/nvim/after/plugin/tree.lua | 36 +++++++++++++++ common/nvim/after/plugin/treesitter.lua | 21 +++++++++ common/nvim/after/plugin/undotree.lua | 1 + common/nvim/after/plugin/whitespace.lua | 4 ++ common/nvim/init.lua | 4 ++ common/nvim/{init.vim => init.vim.old} | 0 common/nvim/lua/cc/init.lua | 3 ++ common/nvim/lua/cc/packer.lua | 48 ++++++++++++++++++++ common/nvim/lua/cc/remap.lua | 41 +++++++++++++++++ common/nvim/lua/cc/set.lua | 30 +++++++++++++ 16 files changed, 363 insertions(+) create mode 100644 common/nvim/after/plugin/barbar.lua create mode 100644 common/nvim/after/plugin/blankline.lua create mode 100644 common/nvim/after/plugin/colors.lua create mode 100644 common/nvim/after/plugin/fugitive.lua create mode 100644 common/nvim/after/plugin/lsp.lua create mode 100644 common/nvim/after/plugin/telescope.lua create mode 100644 common/nvim/after/plugin/tree.lua create mode 100644 common/nvim/after/plugin/treesitter.lua create mode 100644 common/nvim/after/plugin/undotree.lua create mode 100644 common/nvim/after/plugin/whitespace.lua create mode 100644 common/nvim/init.lua rename common/nvim/{init.vim => init.vim.old} (100%) create mode 100644 common/nvim/lua/cc/init.lua create mode 100644 common/nvim/lua/cc/packer.lua create mode 100644 common/nvim/lua/cc/remap.lua create mode 100644 common/nvim/lua/cc/set.lua diff --git a/common/nvim/after/plugin/barbar.lua b/common/nvim/after/plugin/barbar.lua new file mode 100644 index 0000000..e471134 --- /dev/null +++ b/common/nvim/after/plugin/barbar.lua @@ -0,0 +1,54 @@ +local map = vim.api.nvim_set_keymap +local opts = { noremap = true, silent = true } + +-- Move to previous/next +map("n", "", "BufferPrevious", opts) +map("n", "", "BufferNext", opts) +-- Re-order to previous/next +map("n", "", "BufferMovePrevious", opts) +map("n", ">", "BufferMoveNext", opts) +-- Goto buffer in position... +map("n", "", "BufferGoto 1", opts) +map("n", "", "BufferGoto 2", opts) +map("n", "", "BufferGoto 3", opts) +map("n", "", "BufferGoto 4", opts) +map("n", "", "BufferGoto 5", opts) +map("n", "", "BufferGoto 6", opts) +map("n", "", "BufferGoto 7", opts) +map("n", "", "BufferGoto 8", opts) +map("n", "", "BufferGoto 9", opts) +map("n", "", "BufferLast", opts) +-- Pin/unpin buffer +map("n", "", "BufferPin", opts) +-- Close buffer +map("n", "", "BufferClose", opts) + +vim.g.barbar_auto_setup = false +local barbar = require("barbar") +barbar.setup({ + animation = false, + auto_hide = true, + tabpages = true, + clickable = true, + focus_on_close = "previous", + icons = { + gitsigns = { + added = {enabled = true, icon = '+'}, + changed = {enabled = true, icon = '~'}, + deleted = {enabled = true, icon = '-'}, + }, + filetype = { + custom_colors = false, + enabled = false, + }, + separator = {left = "▎", right = ""}, + modified = {button = "●"}, + pinned = {button = "▲", filename = true}, + inactive = {button = "x"}, + button = "x", + }, + sidebar_filetypes = { + NvimTree = true, + undotree = {text = "undotree"}, + }, +}) diff --git a/common/nvim/after/plugin/blankline.lua b/common/nvim/after/plugin/blankline.lua new file mode 100644 index 0000000..7e7c75c --- /dev/null +++ b/common/nvim/after/plugin/blankline.lua @@ -0,0 +1,14 @@ +require("indent_blankline").setup({ + char = "▎", + space_char_blankline = " ", + char_blankline = " ", + char_highlight_list = { + "IndentBlanklineIndent1", + "IndentBlanklineIndent2", + "IndentBlanklineIndent3", + "IndentBlanklineIndent4", + }, + show_current_context = true, + show_current_context_start = true, +}) + diff --git a/common/nvim/after/plugin/colors.lua b/common/nvim/after/plugin/colors.lua new file mode 100644 index 0000000..f469749 --- /dev/null +++ b/common/nvim/after/plugin/colors.lua @@ -0,0 +1,42 @@ +vim.cmd("colorscheme lena") + +vim.cmd("highlight IndentBlanklineIndent1 ctermfg=11 cterm=nocombine") +vim.cmd("highlight IndentBlanklineIndent2 ctermfg=10 cterm=nocombine") +vim.cmd("highlight IndentBlanklineIndent3 ctermfg=13 cterm=nocombine") +vim.cmd("highlight IndentBlanklineIndent4 ctermfg=12 cterm=nocombine") + +vim.cmd("hi Normal ctermbg=NONE") +vim.cmd("hi LineNr ctermfg=7") +vim.cmd("hi CursorLineNr ctermfg=1 ctermbg=0") +vim.cmd("hi CursorLine cterm=NONE ctermfg=NONE ctermbg=0") +vim.cmd("hi StatusLine ctermfg=5 ctermbg=8 cterm=NONE") +vim.cmd("hi StatusLineNC ctermfg=7 ctermbg=0 cterm=NONE") +vim.cmd("hi VertSplit ctermbg=0 ctermfg=0") +vim.cmd("hi ExtraWhitespace ctermbg=1") +vim.cmd("hi SignColumn ctermbg=8") + +vim.cmd("hi BufferCurrent ctermfg=5 ctermbg=NONE") +vim.cmd("hi BufferCurrentIndex ctermfg=5 ctermbg=NONE") +vim.cmd("hi BufferCurrentMod ctermfg=9 ctermbg=NONE") +vim.cmd("hi BufferCurrentSign ctermfg=5 ctermbg=NONE") +vim.cmd("hi BufferCurrentTarget ctermfg=5 ctermbg=NONE") +vim.cmd("hi BufferVisible ctermfg=7 ctermbg=NONE") +vim.cmd("hi BufferVisibleIndex ctermfg=7 ctermbg=NONE") +vim.cmd("hi BufferVisibleMod ctermfg=9 ctermbg=NONE") +vim.cmd("hi BufferVisibleSign ctermfg=7 ctermbg=NONE") +vim.cmd("hi BufferVisibleTarget ctermfg=7 ctermbg=NONE") +vim.cmd("hi BufferInactive ctermfg=7 ctermbg=0") +vim.cmd("hi BufferInactiveIndex ctermfg=5 ctermbg=0") +vim.cmd("hi BufferInactiveMod ctermfg=1 ctermbg=0") +vim.cmd("hi BufferInactiveSign ctermfg=10 ctermbg=0") +vim.cmd("hi BufferInactiveTarget ctermfg=11 ctermbg=0") +vim.cmd("hi BufferTabpages ctermfg=7 ctermbg=0") +vim.cmd("hi BufferTabpageFill ctermfg=7 ctermbg=0") +vim.cmd("hi BufferOffset ctermfg=0 ctermbg=0") + +vim.cmd("hi! link SignColumn LineNr") + +vim.cmd("hi LspDiagnosticsDefaultHint ctermfg=6") +vim.cmd("hi LspDiagnosticsDefaultError ctermfg=1") +vim.cmd("hi LspDiagnosticsDefaultWarning ctermfg=3") +vim.cmd("hi LspDiagnosticsDefaultInformation ctermfg=7") diff --git a/common/nvim/after/plugin/fugitive.lua b/common/nvim/after/plugin/fugitive.lua new file mode 100644 index 0000000..80c9070 --- /dev/null +++ b/common/nvim/after/plugin/fugitive.lua @@ -0,0 +1 @@ +vim.keymap.set("n", "gs", vim.cmd.Git) diff --git a/common/nvim/after/plugin/lsp.lua b/common/nvim/after/plugin/lsp.lua new file mode 100644 index 0000000..22a89e1 --- /dev/null +++ b/common/nvim/after/plugin/lsp.lua @@ -0,0 +1,58 @@ +local lsp = require("lsp-zero") +lsp.preset("recommended") + +lsp.ensure_installed({ + "eslint", + "rust_analyzer", +}) + +lsp.nvim_workspace() + +local cmp = require("cmp") +local cmp_select = {behavior = cmp.SelectBehavior.Select} +local cmp_mappings = lsp.defaults.cmp_mappings({ + [""] = cmp.mapping.select_prev_item(cmp_select), + [""] = cmp.mapping.select_next_item(cmp_select), + [""] = cmp.mapping.confirm({select = true}), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.abort(), +}) +cmp_mappings[""] = nil +cmp_mappings[""] = nil + +lsp.setup_nvim_cmp({ + mapping = cmp_mappings, +}) + +lsp.set_preferences({ + suggest_lsp_servers = false, + sign_icons = { + error = "E", + warn = "W", + hint = "H", + info = "I", + }, +}) + +lsp.on_attach(function(client, bufnr) + local opts = {buffer = bufnr, remap = false} + + vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) + vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) + vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) + vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) + vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) + vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) + vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) + vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) + vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) + vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) +end) + +lsp.setup_servers({"eslint"}) + +lsp.setup() + +vim.diagnostic.config({ + virtual_text = true +}) diff --git a/common/nvim/after/plugin/telescope.lua b/common/nvim/after/plugin/telescope.lua new file mode 100644 index 0000000..df536e4 --- /dev/null +++ b/common/nvim/after/plugin/telescope.lua @@ -0,0 +1,6 @@ +local builtin = require('telescope.builtin') +vim.keymap.set('n', 'pf', builtin.find_files, {}) +vim.keymap.set('n', '', builtin.git_files, {}) +vim.keymap.set('n', 'ps', function() + builtin.grep_string({search = vim.fn.input("Grep > ")}) +end) diff --git a/common/nvim/after/plugin/tree.lua b/common/nvim/after/plugin/tree.lua new file mode 100644 index 0000000..8a3e061 --- /dev/null +++ b/common/nvim/after/plugin/tree.lua @@ -0,0 +1,36 @@ +require("nvim-tree").setup({ + actions = { + open_file = { + quit_on_open = true, + }, + }, + renderer = { + indent_markers = { + enable = true, + }, + icons = { + symlink_arrow = " -> ", + show = { + file = false, + folder = false, + }, + glyphs = { + folder = { + arrow_closed = "+", + arrow_open = "-", + }, + git = { + unstaged = "U", + staged = "S", + unmerged = "M", + renamed = "R", + untracked = "+", + deleted = "-", + ignored = "I", + }, + }, + }, + }, +}) + +vim.keymap.set("n", "b", vim.cmd.NvimTreeToggle) diff --git a/common/nvim/after/plugin/treesitter.lua b/common/nvim/after/plugin/treesitter.lua new file mode 100644 index 0000000..1255591 --- /dev/null +++ b/common/nvim/after/plugin/treesitter.lua @@ -0,0 +1,21 @@ +require'nvim-treesitter.configs'.setup({ + -- A list of parser names, or "all" (the five listed parsers should always be installed) + ensure_installed = { "javascript", "typescript", "rust", "c", "lua", "vim", "vimdoc", "query" }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally + auto_install = true, + + highlight = { + enable = true, + + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, +}) diff --git a/common/nvim/after/plugin/undotree.lua b/common/nvim/after/plugin/undotree.lua new file mode 100644 index 0000000..b6b9276 --- /dev/null +++ b/common/nvim/after/plugin/undotree.lua @@ -0,0 +1 @@ +vim.keymap.set("n", "u", vim.cmd.UndotreeToggle) diff --git a/common/nvim/after/plugin/whitespace.lua b/common/nvim/after/plugin/whitespace.lua new file mode 100644 index 0000000..1bbdfe5 --- /dev/null +++ b/common/nvim/after/plugin/whitespace.lua @@ -0,0 +1,4 @@ +vim.g.better_whitespace_enable = true +vim.g.strip_whitespace_on_save = true + +vim.cmd("hi ExtraWhitespace ctermbg=9") diff --git a/common/nvim/init.lua b/common/nvim/init.lua new file mode 100644 index 0000000..49db9df --- /dev/null +++ b/common/nvim/init.lua @@ -0,0 +1,4 @@ +vim.g.loaded_netrw = 1 +vim.g.loaded_netwrPlugin = 1 + +require("cc") diff --git a/common/nvim/init.vim b/common/nvim/init.vim.old similarity index 100% rename from common/nvim/init.vim rename to common/nvim/init.vim.old diff --git a/common/nvim/lua/cc/init.lua b/common/nvim/lua/cc/init.lua new file mode 100644 index 0000000..b728722 --- /dev/null +++ b/common/nvim/lua/cc/init.lua @@ -0,0 +1,3 @@ +require("cc.packer") +require("cc.remap") +require("cc.set") diff --git a/common/nvim/lua/cc/packer.lua b/common/nvim/lua/cc/packer.lua new file mode 100644 index 0000000..b81d145 --- /dev/null +++ b/common/nvim/lua/cc/packer.lua @@ -0,0 +1,48 @@ +vim.cmd("packadd packer.nvim") + +local packer = require("packer") + +return packer.startup(function(use) + use("wbthomason/packer.nvim") + + use({ + "nvim-telescope/telescope.nvim", + tag = "0.1.1", + requires = { + {"nvim-lua/plenary.nvim"}, + }, + }) + use( + "nvim-treesitter/nvim-treesitter", + {run = ":TSUpdate"} + ) + use("theprimeagen/harpoon") + use("mbbill/undotree") + use("tpope/vim-fugitive") + + use({ + "VonHeikemen/lsp-zero.nvim", + branch = "v2.x", + requires = { + -- LSP Support + {"neovim/nvim-lspconfig"}, -- Required + { -- Optional + "williamboman/mason.nvim", + run = function() + pcall(vim.cmd, "MasonUpdate") + end, + }, + {"williamboman/mason-lspconfig.nvim"}, -- Optional + + -- Autocompletion + {"hrsh7th/nvim-cmp"}, -- Required + {"hrsh7th/cmp-nvim-lsp"}, -- Required + {"L3MON4D3/LuaSnip"}, -- Required + }, + }) + + use("lukas-reineke/indent-blankline.nvim") + use("romgrk/barbar.nvim") + use("ntpeters/vim-better-whitespace") + use("nvim-tree/nvim-tree.lua") +end) diff --git a/common/nvim/lua/cc/remap.lua b/common/nvim/lua/cc/remap.lua new file mode 100644 index 0000000..13e895e --- /dev/null +++ b/common/nvim/lua/cc/remap.lua @@ -0,0 +1,41 @@ +vim.g.mapleader = " " + +vim.keymap.set("t", "", "") + +vim.keymap.set("!", "", "") +vim.keymap.set("!", "", "") +vim.keymap.set("i", "", "") +vim.keymap.set("c", "", "") + +vim.keymap.set("v", "J", ":m '>+1gv=gv") +vim.keymap.set("v", "K", ":m '<-2gv=gv") +vim.keymap.set("v", "", ":m '>+1gv=gv") +vim.keymap.set("v", "", ":m '<-2gv=gv") + +vim.keymap.set("n", "J", "mzJ`z") +vim.keymap.set("n", "", "zz") +vim.keymap.set("n", "", "zz") +vim.keymap.set("n", "n", "nzzzv") +vim.keymap.set("n", "N", "Nzzzv") + +vim.keymap.set("x", "p", "\"_dP") +vim.keymap.set({"n", "v"}, "y", "\"+y") +vim.keymap.set("n", "Y", "\"+Y") +vim.keymap.set({"n", "v"}, "d", "\"_d") + +vim.keymap.set("n", "Q", "") + +vim.keymap.set("n", "f", function() + vim.lsp.buf.format() +end) + +vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) + +vim.keymap.set("n", "", function() + vim.cmd("so") +end) +vim.keymap.set("n", "vpp", function() + local dir = vim.call("stdpath", "config") + vim.cmd("e " .. dir .. "/lua/cc/packer.lua") +end) +vim.keymap.set("n", "vps", "PackerSync") diff --git a/common/nvim/lua/cc/set.lua b/common/nvim/lua/cc/set.lua new file mode 100644 index 0000000..871ec4b --- /dev/null +++ b/common/nvim/lua/cc/set.lua @@ -0,0 +1,30 @@ +vim.opt.termguicolors = false + +vim.opt.fileformat = "unix" +vim.opt.fileformats = {"unix", "dos"} + +vim.opt.nu = true +vim.opt.relativenumber = true +vim.opt.cul = true + +vim.opt.tabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.expandtab = true + +vim.opt.hlsearch = false +vim.opt.incsearch = true + +vim.opt.list = true +vim.opt.listchars:append("space:⋅") +vim.opt.listchars:append("eol:↴") +vim.opt.fillchars:append("vert:▎") + +vim.opt.scrolloff = 8 +vim.opt.signcolumn = "yes" + +vim.opt.updatetime = 50 + +vim.opt.colorcolumn = "80" + +vim.g.ackprg = "ag --vimgrep" +