From f4f89ee5edfb32b711e8b2569bb4d898b558ce8d Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Sun, 12 Dec 2021 11:59:29 -0500 Subject: [PATCH] Added neogit --- nvim/.config/nvim/init.lua | 1 - nvim/.config/nvim/lua/config/cmp.lua | 112 ++++++++++++++++ nvim/.config/nvim/lua/config/diffview.lua | 37 ++++++ nvim/.config/nvim/lua/config/neogit.lua | 32 +++++ nvim/.config/nvim/lua/plugins.lua | 32 ++++- nvim/.config/nvim/plugin/packer_compiled.lua | 127 +++++++++++++++++-- 6 files changed, 327 insertions(+), 14 deletions(-) create mode 100644 nvim/.config/nvim/lua/config/cmp.lua create mode 100644 nvim/.config/nvim/lua/config/diffview.lua create mode 100644 nvim/.config/nvim/lua/config/neogit.lua diff --git a/nvim/.config/nvim/init.lua b/nvim/.config/nvim/init.lua index 140f8c5..d626365 100644 --- a/nvim/.config/nvim/init.lua +++ b/nvim/.config/nvim/init.lua @@ -12,4 +12,3 @@ require('autocmd') -- Theme require('theme') - diff --git a/nvim/.config/nvim/lua/config/cmp.lua b/nvim/.config/nvim/lua/config/cmp.lua new file mode 100644 index 0000000..f333ce8 --- /dev/null +++ b/nvim/.config/nvim/lua/config/cmp.lua @@ -0,0 +1,112 @@ +-- Setup nvim-cmp. +local cmp = require "cmp" +local lspkind = require("lspkind") + +local has_words_before = function() + 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 feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), + mode, true) +end + +lspkind.init({ + symbol_map = { + Text = "", + Method = "", + 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({ + formatting = { + format = lspkind.cmp_format { + with_text = false, + maxwidth = 50, + menu = { + buffer = "BUF", + nvim_lsp = "LSP", + path = "PATH", + vsnip = "SNIP", + calc = "CALC", + spell = "SPELL", + emoji = "EMOJI" + } + } + }, + experimental = {native_menu = false, ghost_text = false}, + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + end + }, + mapping = { + [""] = 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.Replace, + select = false + }, + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + end + end, {"i", "s"}), + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, {"i", "s"}) + }, + sources = { + {name = "nvim_lsp"}, {name = "buffer", keyword_length = 5}, + {name = "vsnip"}, {name = "calc"}, {name = "emoji"}, {name = "spell"}, + {name = "path"} + } +}) + +-- Use buffer source for `/`. +cmp.setup.cmdline("/", {sources = {{name = "buffer"}}}) + +-- Use cmdline & path source for ':'. +cmp.setup.cmdline(":", { + sources = cmp.config.sources({{name = "path"}}, {{name = "cmdline"}}) +}) diff --git a/nvim/.config/nvim/lua/config/diffview.lua b/nvim/.config/nvim/lua/config/diffview.lua new file mode 100644 index 0000000..6d01c08 --- /dev/null +++ b/nvim/.config/nvim/lua/config/diffview.lua @@ -0,0 +1,37 @@ +local cb = require'diffview.config'.diffview_callback + +require'diffview'.setup { + diff_binaries = false, -- Show diffs for binaries + use_icons = true, -- Requires nvim-web-devicons + file_panel = { + width = 35, + }, + key_bindings = { + disable_defaults = false, -- Disable the default key bindings + -- The `view` bindings are active in the diff buffers, only when the current + -- tabpage is a Diffview. + view = { + [""] = cb("select_next_entry"), -- Open the diff for the next file + [""] = cb("select_prev_entry"), -- Open the diff for the previous file + ["e"] = cb("focus_files"), -- Bring focus to the files panel + ["b"] = cb("toggle_files"), -- Toggle the files panel. + }, + file_panel = { + ["j"] = cb("next_entry"), -- Bring the cursor to the next file entry + [""] = cb("next_entry"), + ["k"] = cb("prev_entry"), -- Bring the cursor to the previous file entry. + [""] = cb("prev_entry"), + [""] = cb("select_entry"), -- Open the diff for the selected entry. + ["o"] = cb("select_entry"), + ["<2-LeftMouse>"] = cb("select_entry"), + ["-"] = cb("toggle_stage_entry"), -- Stage / unstage the selected entry. + ["S"] = cb("stage_all"), -- Stage all entries. + ["U"] = cb("unstage_all"), -- Unstage all entries. + ["R"] = cb("refresh_files"), -- Update stats and entries in the file list. + [""] = cb("select_next_entry"), + [""] = cb("select_prev_entry"), + ["e"] = cb("focus_files"), + ["b"] = cb("toggle_files"), + } + } +} diff --git a/nvim/.config/nvim/lua/config/neogit.lua b/nvim/.config/nvim/lua/config/neogit.lua new file mode 100644 index 0000000..9048173 --- /dev/null +++ b/nvim/.config/nvim/lua/config/neogit.lua @@ -0,0 +1,32 @@ +local neogit = require('neogit') +--neogit.config.use_magit_keybindings() + +neogit.setup { +disable_signs = false, + disable_context_highlighting = false, + disable_commit_confirmation = false, + -- customize displayed signs + signs = { + -- { CLOSED, OPENED } + section = { ">", "v" }, + item = { ">", "v" }, + hunk = { "", "" }, + }, + integrations = { + diffview = true + }, + -- override/add mappings + mappings = { + -- modify status buffer mappings + status = { + -- Adds a mapping with "B" as key that does the "BranchPopup" command + -- ["B"] = "BranchPopup", + -- ["C"] = "CommitPopup", + -- ["P"] = "PullPopup", + -- ["S"] = "Stage", + -- ["D"] = "Discard", + -- Removes the default mapping of "s" + -- ["s"] = "", + } + } +} diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index f5067ad..553326c 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -54,7 +54,21 @@ use { use "nvim-treesitter/nvim-treesitter-textobjects" +use { + "hrsh7th/nvim-cmp", + requires = { + {"hrsh7th/cmp-nvim-lsp"}, {"hrsh7th/cmp-buffer"}, {"hrsh7th/cmp-path"}, + {"hrsh7th/cmp-cmdline"}, {"hrsh7th/cmp-vsnip"}, + {"f3fora/cmp-spell", {"hrsh7th/cmp-calc"}, {"hrsh7th/cmp-emoji"}} + }, + config = get_config("cmp") +} + +use {"onsails/lspkind-nvim", requires = {{"famiu/bufdelete.nvim"}}} + -- LSP +use {"ray-x/lsp_signature.nvim", requires = {{"neovim/nvim-lspconfig"}}} + use { "neovim/nvim-lspconfig", config = get_config("lsp") @@ -64,9 +78,25 @@ use { config = get_config("lsp-installer") } - use {"folke/which-key.nvim", event = "VimEnter", config = get_config("which")} +-- requirement for Neogit +use { + "sindrets/diffview.nvim", + cmd = { + "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", + "DiffviewFocusFiles" + }, + config = get_config("diffview") +} + +use { + "TimUntersberger/neogit", + requires = {"nvim-lua/plenary.nvim"}, + cmd = "Neogit", + config = get_config("neogit") +} + -- Theme use { 'EdenEast/nightfox.nvim', diff --git a/nvim/.config/nvim/plugin/packer_compiled.lua b/nvim/.config/nvim/plugin/packer_compiled.lua index 2861c16..8514924 100644 --- a/nvim/.config/nvim/plugin/packer_compiled.lua +++ b/nvim/.config/nvim/plugin/packer_compiled.lua @@ -69,24 +69,105 @@ end time([[try_loadstring definition]], false) time([[Defining packer_plugins]], true) _G.packer_plugins = { + ["bufdelete.nvim"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/bufdelete.nvim", + url = "https://github.com/famiu/bufdelete.nvim" + }, + ["cmp-buffer"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/cmp-buffer", + url = "https://github.com/hrsh7th/cmp-buffer" + }, + ["cmp-calc"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/cmp-calc", + url = "https://github.com/hrsh7th/cmp-calc" + }, + ["cmp-cmdline"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/cmp-cmdline", + url = "https://github.com/hrsh7th/cmp-cmdline" + }, + ["cmp-emoji"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/cmp-emoji", + url = "https://github.com/hrsh7th/cmp-emoji" + }, + ["cmp-nvim-lsp"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", + url = "https://github.com/hrsh7th/cmp-nvim-lsp" + }, + ["cmp-path"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/cmp-path", + url = "https://github.com/hrsh7th/cmp-path" + }, + ["cmp-spell"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/cmp-spell", + url = "https://github.com/f3fora/cmp-spell" + }, + ["cmp-vsnip"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/cmp-vsnip", + url = "https://github.com/hrsh7th/cmp-vsnip" + }, + ["diffview.nvim"] = { + commands = { "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles" }, + config = { 'require("config/diffview")' }, + loaded = false, + needs_bufread = false, + only_cond = false, + path = "/Users/michael/.local/share/nvim/site/pack/packer/opt/diffview.nvim", + url = "https://github.com/sindrets/diffview.nvim" + }, + ["lsp_signature.nvim"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/lsp_signature.nvim", + url = "https://github.com/ray-x/lsp_signature.nvim" + }, + ["lspkind-nvim"] = { + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/lspkind-nvim", + url = "https://github.com/onsails/lspkind-nvim" + }, ["lualine.nvim"] = { config = { 'require("config/lualine")' }, loaded = true, path = "/Users/michael/.local/share/nvim/site/pack/packer/start/lualine.nvim", url = "https://github.com/nvim-lualine/lualine.nvim" }, + neogit = { + commands = { "Neogit" }, + config = { 'require("config/neogit")' }, + loaded = false, + needs_bufread = true, + only_cond = false, + path = "/Users/michael/.local/share/nvim/site/pack/packer/opt/neogit", + url = "https://github.com/TimUntersberger/neogit" + }, ["nightfox.nvim"] = { config = { 'require("config/nightfox")' }, loaded = true, path = "/Users/michael/.local/share/nvim/site/pack/packer/start/nightfox.nvim", url = "https://github.com/EdenEast/nightfox.nvim" }, + ["nvim-cmp"] = { + config = { 'require("config/cmp")' }, + loaded = true, + path = "/Users/michael/.local/share/nvim/site/pack/packer/start/nvim-cmp", + url = "https://github.com/hrsh7th/nvim-cmp" + }, ["nvim-lsp-installer"] = { + config = { 'require("config/lsp-installer")' }, loaded = true, path = "/Users/michael/.local/share/nvim/site/pack/packer/start/nvim-lsp-installer", url = "https://github.com/williamboman/nvim-lsp-installer" }, ["nvim-lspconfig"] = { + config = { 'require("config/lsp")' }, loaded = true, path = "/Users/michael/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", url = "https://github.com/neovim/nvim-lspconfig" @@ -140,6 +221,30 @@ _G.packer_plugins = { } time([[Defining packer_plugins]], false) +-- Config for: nvim-lsp-installer +time([[Config for nvim-lsp-installer]], true) +require("config/lsp-installer") +time([[Config for nvim-lsp-installer]], false) +-- Config for: nvim-cmp +time([[Config for nvim-cmp]], true) +require("config/cmp") +time([[Config for nvim-cmp]], false) +-- Config for: nightfox.nvim +time([[Config for nightfox.nvim]], true) +require("config/nightfox") +time([[Config for nightfox.nvim]], false) +-- Config for: nvim-lspconfig +time([[Config for nvim-lspconfig]], true) +require("config/lsp") +time([[Config for nvim-lspconfig]], false) +-- Config for: telescope.nvim +time([[Config for telescope.nvim]], true) +require("config/telescope") +time([[Config for telescope.nvim]], false) +-- Config for: nvim-treesitter +time([[Config for nvim-treesitter]], true) +require("config/treesitter") +time([[Config for nvim-treesitter]], false) -- Config for: nvim-tree.lua time([[Config for nvim-tree.lua]], true) require("config/nvim-tree") @@ -148,18 +253,16 @@ time([[Config for nvim-tree.lua]], false) time([[Config for lualine.nvim]], true) require("config/lualine") time([[Config for lualine.nvim]], false) --- Config for: nvim-treesitter -time([[Config for nvim-treesitter]], true) -require("config/treesitter") -time([[Config for nvim-treesitter]], false) --- Config for: telescope.nvim -time([[Config for telescope.nvim]], true) -require("config/telescope") -time([[Config for telescope.nvim]], false) --- Config for: nightfox.nvim -time([[Config for nightfox.nvim]], true) -require("config/nightfox") -time([[Config for nightfox.nvim]], false) + +-- Command lazy-loads +time([[Defining lazy-load commands]], true) +pcall(vim.cmd, [[command -nargs=* -range -bang -complete=file Neogit lua require("packer.load")({'neogit'}, { cmd = "Neogit", l1 = , l2 = , bang = , args = , mods = "" }, _G.packer_plugins)]]) +pcall(vim.cmd, [[command -nargs=* -range -bang -complete=file DiffviewOpen lua require("packer.load")({'diffview.nvim'}, { cmd = "DiffviewOpen", l1 = , l2 = , bang = , args = , mods = "" }, _G.packer_plugins)]]) +pcall(vim.cmd, [[command -nargs=* -range -bang -complete=file DiffviewClose lua require("packer.load")({'diffview.nvim'}, { cmd = "DiffviewClose", l1 = , l2 = , bang = , args = , mods = "" }, _G.packer_plugins)]]) +pcall(vim.cmd, [[command -nargs=* -range -bang -complete=file DiffviewToggleFiles lua require("packer.load")({'diffview.nvim'}, { cmd = "DiffviewToggleFiles", l1 = , l2 = , bang = , args = , mods = "" }, _G.packer_plugins)]]) +pcall(vim.cmd, [[command -nargs=* -range -bang -complete=file DiffviewFocusFiles lua require("packer.load")({'diffview.nvim'}, { cmd = "DiffviewFocusFiles", l1 = , l2 = , bang = , args = , mods = "" }, _G.packer_plugins)]]) +time([[Defining lazy-load commands]], false) + vim.cmd [[augroup packer_load_aucmds]] vim.cmd [[au!]] -- Event lazy-loads