From cd7a1ff6640792ca18a4528d396a79b0e2d7247f Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 19 Feb 2023 10:59:52 -0500 Subject: [PATCH] Initial nvim configuration --- init.lua | 35 ++++++ lua/latex.lua | 4 + lua/plugins.lua | 74 ++++++++++++ lua/plugins/FRC.lua | 3 + lua/plugins/angry-reviewer.lua | 2 + lua/plugins/black.lua | 8 ++ lua/plugins/catppuccin.lua | 46 ++++++++ lua/plugins/chad.lua | 1 + lua/plugins/lsp.lua | 122 +++++++++++++++++++ lua/plugins/statusline.lua | 40 +++++++ lua/plugins/treesitter.lua | 18 +++ plugin/packer_compiled.lua | 210 +++++++++++++++++++++++++++++++++ 12 files changed, 563 insertions(+) create mode 100644 init.lua create mode 100644 lua/latex.lua create mode 100644 lua/plugins.lua create mode 100644 lua/plugins/FRC.lua create mode 100644 lua/plugins/angry-reviewer.lua create mode 100644 lua/plugins/black.lua create mode 100644 lua/plugins/catppuccin.lua create mode 100644 lua/plugins/chad.lua create mode 100644 lua/plugins/lsp.lua create mode 100644 lua/plugins/statusline.lua create mode 100644 lua/plugins/treesitter.lua create mode 100644 plugin/packer_compiled.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..d9671f5 --- /dev/null +++ b/init.lua @@ -0,0 +1,35 @@ +-- display +vim.opt.showmode = true -- show editing mode +vim.opt.title = true -- custom title +vim.opt.number = true -- display line numbers +vim.opt.lazyredraw = true + +-- spellcheck +vim.opt.spelllang = en,fr,de +vim.opt.spellsuggest = best,9 + +-- case-insensitive search except when using capitals +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- miscellaneous +vim.opt.confirm = true -- ask to save before failed command +vim.opt.cmdheight = 2 -- set command window height to 2 lines + +-- indentation +vim.opt.shiftwidth = 4 +vim.opt.tabstop = 4 + +-- automatically switch buffer name when target file isn't read/write-able +vim.g.suda_smart_edit = 1 + +require("latex") +require("plugins") +require("plugins/statusline") +require("plugins/treesitter") +require("plugins/catppuccin") +require("plugins/lsp") +require("plugins/black") +require("plugins/angry-reviewer") +require("plugins/chad") +require("plugins/FRC") diff --git a/lua/latex.lua b/lua/latex.lua new file mode 100644 index 0000000..3a96378 --- /dev/null +++ b/lua/latex.lua @@ -0,0 +1,4 @@ +vim.g.tex_flavor = 'latex' +vim.g.tex_conceal = '' +vim.g.vimtex_fold_manual = 1 +vim.g.vimtex_compiler_progname = 'tectonic' diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 0000000..8d52a59 --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,74 @@ +-- automatically compile new plugins +vim.cmd([[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerCompile + augroup end +]]) + +return require('packer').startup(function(use) + -- Packer can manage itself + use 'wbthomason/packer.nvim' + + -- Catppuccin theme + use { "catppuccin/nvim", as = "catppuccin" } + + -- Statusline + use { + 'nvim-lualine/lualine.nvim', + requires = { 'kyazdani42/nvim-web-devicons', opt = true } + } + + -- Treesitter + use { + 'nvim-treesitter/nvim-treesitter', + run = ':TSUpdate' + } + + -- Fuzzy finder + use { + 'junegunn/fzf', + run = 'fzf#install()' + } + use 'junegunn/fzf.vim' + + -- Easy commenting + use 'tpope/vim-commentary' + + -- git decorations + use { + 'lewis6991/gitsigns.nvim', + config = function() + require('gitsigns').setup() + end + } + + -- File explorer + use { + 'ms-jpq/chadtree', branch = 'chad', + run = '!python3 -m chadtree deps' + } + + -- LSP + use 'neovim/nvim-lspconfig' + use 'simrat39/rust-tools.nvim' + use 'hrsh7th/nvim-cmp' + use 'hrsh7th/cmp-nvim-lsp' + use 'hrsh7th/cmp-vsnip' + use 'hrsh7th/cmp-path' + use 'hrsh7th/cmp-buffer' + use 'hrsh7th/vim-vsnip' + + use 'alaviss/nim.nvim' + + -- Angry reviewer + use 'anufrievroman/vim-angry-reviewer' + + -- Sudo + use 'lambdalisue/suda.vim' + + -- git + use 'tpope/vim-fugitive' + +end) + diff --git a/lua/plugins/FRC.lua b/lua/plugins/FRC.lua new file mode 100644 index 0000000..28ec6d2 --- /dev/null +++ b/lua/plugins/FRC.lua @@ -0,0 +1,3 @@ +vim.api.nvim_create_user_command('FRCbuild', '!gradle build', {}) +vim.api.nvim_create_user_command('FRCdeploy', '!gradle deploy', {}) +vim.api.nvim_create_user_command('FRCconfig', ':LspStop', {}) diff --git a/lua/plugins/angry-reviewer.lua b/lua/plugins/angry-reviewer.lua new file mode 100644 index 0000000..56da333 --- /dev/null +++ b/lua/plugins/angry-reviewer.lua @@ -0,0 +1,2 @@ +vim.g.AngryReviewerEnglish = 'american' +vim.keymap.set('n', 'ar', 'AngryReviewer') diff --git a/lua/plugins/black.lua b/lua/plugins/black.lua new file mode 100644 index 0000000..0a84154 --- /dev/null +++ b/lua/plugins/black.lua @@ -0,0 +1,8 @@ +-- run black formatter on save +local black_on_save = vim.api.nvim_create_augroup('black_on_save', { + clear = true }) +vim.api.nvim_create_autocmd('BufWritePost', { + pattern = '*.py', + group = 'black_on_save', + command = 'silent! !black -q ', +}) diff --git a/lua/plugins/catppuccin.lua b/lua/plugins/catppuccin.lua new file mode 100644 index 0000000..65d853d --- /dev/null +++ b/lua/plugins/catppuccin.lua @@ -0,0 +1,46 @@ +require("catppuccin").setup({ + flavour = "mocha", -- latte, frappe, macchiato, mocha + background = { -- :h background + light = "latte", + dark = "mocha", + }, + transparent_background = true, + show_end_of_buffer = false, -- show the '~' characters after the end of buffers + term_colors = true, + dim_inactive = { + enabled = false, + shade = "dark", + percentage = 0.15, + }, + no_italic = false, -- Force no italic + no_bold = false, -- Force no bold + styles = { + comments = { "italic" }, + conditionals = { "italic" }, + loops = {}, + functions = {}, + keywords = {}, + strings = {}, + variables = {}, + numbers = {}, + booleans = {}, + properties = {}, + types = {}, + operators = {}, + }, + color_overrides = {}, + custom_highlights = {}, + integrations = { + cmp = true, + treesitter = true, + gitsigns = true, + nvimtree = true, + telescope = true, + notify = false, + mini = false, + -- For more plugins integrations please scroll down (https://github.com/catppuccin/nvim#integrations) + }, +}) + +-- setup must be called before loading +vim.cmd.colorscheme "catppuccin" diff --git a/lua/plugins/chad.lua b/lua/plugins/chad.lua new file mode 100644 index 0000000..b5bcd53 --- /dev/null +++ b/lua/plugins/chad.lua @@ -0,0 +1 @@ +vim.keymap.set('n', 'f', 'CHADopen') diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..5b11a98 --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,122 @@ +vim.opt.completeopt = "menu,menuone,noinsert" + +local nvim_lsp = require'lspconfig' + +local opts = { + tools = { -- rust-tools options + autoSetHints = true, + inlay_hints = { + show_parameter_hints = false, + parameter_hints_prefix = "", + other_hints_prefix = "", + }, + }, + + -- all the opts to send to nvim-lspconfig + -- these override the defaults set by rust-tools.nvim + -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer + server = { + -- on_attach is a callback called when the language server attachs to the buffer + -- on_attach = on_attach, + settings = { + -- to enable rust-analyzer settings visit: + -- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc + ["rust-analyzer"] = { + -- enable clippy on save + checkOnSave = { + command = "clippy" + }, + } + } + }, +} + +require('rust-tools').setup(opts) +-- Use a loop to conveniently call 'setup' on multiple servers and +-- map buffer local keybindings when the language server attaches +local servers = { 'pylsp', 'gdscript'} +for _, lsp in pairs(servers) do + require('lspconfig')[lsp].setup { + on_attach = on_attach, + flags = { + -- This will be the default in neovim 0.7+ + debounce_text_changes = 150, + } + } +end + +-- Java LSP (WPILib broken :/) +require'lspconfig'.java_language_server.setup{ cmd = { "/home/erin/src/java-language-server/dist/lang_server_linux.sh" } } + +-- Setup Completion +-- See https://github.com/hrsh7th/nvim-cmp#basic-configuration +local cmp = require'cmp' +cmp.setup({ + -- Enable LSP snippets + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + -- Add tab support + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }) + }, + + -- Installed sources + sources = { + { name = 'nvim_lsp' }, + { name = 'vsnip' }, + { name = 'path' }, + { name = 'buffer' }, + }, +}) + +local api = vim.api + +-- set updatetime for CursorHold +-- 300ms of no cursor movement to trigger CursorHold +vim.opt.updatetime = 300 +-- show diagnostic popup on cursor hold +api.nvim_create_autocmd("CursorHold", { + command = "lua vim.diagnostic.open_float(nil, { focusable = false })", +}) +-- fixed column for the diagnostics to appear in +vim.opt.signcolumn = "yes" +-- auto-format *.rs (rust) files prior to saving them +api.nvim_create_autocmd("BufWritePre", { + pattern = "*.rs", + command = "lua vim.lsp.buf.formatting_sync(nil, 1000)", +}) + +-- Code navigation shortcutst +vim.keymap.set('n', 'K', function() + return vim.lsp.buf.hover() +end, { silent = true }) + +vim.keymap.set('n', 'gr', function() + return vim.lsp.buf.references() +end, { silent = true, buffer = true }) + +vim.keymap.set('n', 'gd', function() + return vim.lsp.buf.definition() +end, { silent = true, buffer = true }) + +vim.keymap.set('n', 'ga', function() + return vim.lsp.buf.code_action() +end, { silent = true, buffer = true }) + +vim.keymap.set('n', '1gD', function() + return vim.lsp.buf.type_definition() +end, { silent = true, buffer = true }) diff --git a/lua/plugins/statusline.lua b/lua/plugins/statusline.lua new file mode 100644 index 0000000..56c426a --- /dev/null +++ b/lua/plugins/statusline.lua @@ -0,0 +1,40 @@ +require('lualine').setup { + options = { + icons_enabled = true, + theme = 'auto', + component_separators = { left = '', right = ''}, + section_separators = { left = '', right = ''}, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + 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 = {} +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..3584c28 --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,18 @@ +require'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" (the four listed parsers should always be installed) + ensure_installed = { "c", "cpp", "lua", "vim", "help", "bash", "cmake", "make", "html", "css", "scss", "javascript", "latex", "markdown", "toml", "json", "yaml", "dockerfile", "gitattributes", "git_rebase", "gitcommit", "gdscript", "http", "java", "php" }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = true, + + -- 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 = { + -- 'false' will disable the whole extension + enable = true, + + additional_vim_regex_highlighting = false, + }, +} diff --git a/plugin/packer_compiled.lua b/plugin/packer_compiled.lua new file mode 100644 index 0000000..f7b2d36 --- /dev/null +++ b/plugin/packer_compiled.lua @@ -0,0 +1,210 @@ +-- Automatically generated packer.nvim plugin loader code + +if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then + vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"') + return +end + +vim.api.nvim_command('packadd packer.nvim') + +local no_errors, error_msg = pcall(function() + +_G._packer = _G._packer or {} +_G._packer.inside_compile = true + +local time +local profile_info +local should_profile = false +if should_profile then + local hrtime = vim.loop.hrtime + profile_info = {} + time = function(chunk, start) + if start then + profile_info[chunk] = hrtime() + else + profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 + end + end +else + time = function(chunk, start) end +end + +local function save_profiles(threshold) + local sorted_times = {} + for chunk_name, time_taken in pairs(profile_info) do + sorted_times[#sorted_times + 1] = {chunk_name, time_taken} + end + table.sort(sorted_times, function(a, b) return a[2] > b[2] end) + local results = {} + for i, elem in ipairs(sorted_times) do + if not threshold or threshold and elem[2] > threshold then + results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms' + end + end + if threshold then + table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)') + end + + _G._packer.profile_output = results +end + +time([[Luarocks path setup]], true) +local package_path_str = "/home/erin/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/home/erin/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/home/erin/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/home/erin/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/home/erin/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" +if not string.find(package.path, package_path_str, 1, true) then + package.path = package.path .. ';' .. package_path_str +end + +if not string.find(package.cpath, install_cpath_pattern, 1, true) then + package.cpath = package.cpath .. ';' .. install_cpath_pattern +end + +time([[Luarocks path setup]], false) +time([[try_loadstring definition]], true) +local function try_loadstring(s, component, name) + local success, result = pcall(loadstring(s), name, _G.packer_plugins[name]) + if not success then + vim.schedule(function() + vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {}) + end) + end + return result +end + +time([[try_loadstring definition]], false) +time([[Defining packer_plugins]], true) +_G.packer_plugins = { + catppuccin = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/catppuccin", + url = "https://github.com/catppuccin/nvim" + }, + chadtree = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/chadtree", + url = "https://github.com/ms-jpq/chadtree" + }, + ["cmp-buffer"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/cmp-buffer", + url = "https://github.com/hrsh7th/cmp-buffer" + }, + ["cmp-nvim-lsp"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", + url = "https://github.com/hrsh7th/cmp-nvim-lsp" + }, + ["cmp-path"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/cmp-path", + url = "https://github.com/hrsh7th/cmp-path" + }, + ["cmp-vsnip"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/cmp-vsnip", + url = "https://github.com/hrsh7th/cmp-vsnip" + }, + fzf = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/fzf", + url = "https://github.com/junegunn/fzf" + }, + ["fzf.vim"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/fzf.vim", + url = "https://github.com/junegunn/fzf.vim" + }, + ["gitsigns.nvim"] = { + config = { "\27LJ\2\0026\0\0\2\0\3\0\0066\0\0\0'\1\1\0B\0\2\0029\0\2\0B\0\1\1K\0\1\0\nsetup\rgitsigns\frequire\0" }, + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/gitsigns.nvim", + url = "https://github.com/lewis6991/gitsigns.nvim" + }, + ["lualine.nvim"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/lualine.nvim", + url = "https://github.com/nvim-lualine/lualine.nvim" + }, + ["nim.nvim"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/nim.nvim", + url = "https://github.com/alaviss/nim.nvim" + }, + ["nvim-cmp"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/nvim-cmp", + url = "https://github.com/hrsh7th/nvim-cmp" + }, + ["nvim-lspconfig"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", + url = "https://github.com/neovim/nvim-lspconfig" + }, + ["nvim-treesitter"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/nvim-treesitter", + url = "https://github.com/nvim-treesitter/nvim-treesitter" + }, + ["nvim-web-devicons"] = { + loaded = false, + needs_bufread = false, + path = "/home/erin/.local/share/nvim/site/pack/packer/opt/nvim-web-devicons", + url = "https://github.com/kyazdani42/nvim-web-devicons" + }, + ["packer.nvim"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/packer.nvim", + url = "https://github.com/wbthomason/packer.nvim" + }, + ["rust-tools.nvim"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/rust-tools.nvim", + url = "https://github.com/simrat39/rust-tools.nvim" + }, + ["suda.vim"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/suda.vim", + url = "https://github.com/lambdalisue/suda.vim" + }, + ["vim-angry-reviewer"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/vim-angry-reviewer", + url = "https://github.com/anufrievroman/vim-angry-reviewer" + }, + ["vim-commentary"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/vim-commentary", + url = "https://github.com/tpope/vim-commentary" + }, + ["vim-fugitive"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/vim-fugitive", + url = "https://github.com/tpope/vim-fugitive" + }, + ["vim-vsnip"] = { + loaded = true, + path = "/home/erin/.local/share/nvim/site/pack/packer/start/vim-vsnip", + url = "https://github.com/hrsh7th/vim-vsnip" + } +} + +time([[Defining packer_plugins]], false) +-- Config for: gitsigns.nvim +time([[Config for gitsigns.nvim]], true) +try_loadstring("\27LJ\2\0026\0\0\2\0\3\0\0066\0\0\0'\1\1\0B\0\2\0029\0\2\0B\0\1\1K\0\1\0\nsetup\rgitsigns\frequire\0", "config", "gitsigns.nvim") +time([[Config for gitsigns.nvim]], false) + +_G._packer.inside_compile = false +if _G._packer.needs_bufread == true then + vim.cmd("doautocmd BufRead") +end +_G._packer.needs_bufread = false + +if should_profile then save_profiles() end + +end) + +if not no_errors then + error_msg = error_msg:gsub('"', '\\"') + vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None') +end