From 8fd602a27e7f71b4891dacb6ef26d6dea93e5b0c Mon Sep 17 00:00:00 2001 From: Rakshit Sinha Date: Fri, 22 Nov 2024 23:59:38 -0800 Subject: [PATCH] Added git integrations --- lua/rakshit/core/keymaps.lua | 62 +++++++++++++++------------- lua/rakshit/plugins/git-blame.lua | 19 +++++++++ lua/rakshit/plugins/gitsigns.lua | 19 +++++++++ lua/rakshit/plugins/init.lua | 42 ++++++------------- lua/rakshit/plugins/vim-fugitive.lua | 3 ++ 5 files changed, 86 insertions(+), 59 deletions(-) create mode 100644 lua/rakshit/plugins/git-blame.lua create mode 100644 lua/rakshit/plugins/gitsigns.lua create mode 100644 lua/rakshit/plugins/vim-fugitive.lua diff --git a/lua/rakshit/core/keymaps.lua b/lua/rakshit/core/keymaps.lua index 732ad0a4..05a04b5b 100644 --- a/lua/rakshit/core/keymaps.lua +++ b/lua/rakshit/core/keymaps.lua @@ -1,23 +1,23 @@ -- Set as the leader key -- See `:help mapleader` -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) -vim.g.mapleader = ' ' -vim.g.maplocalleader = ' ' +vim.g.mapleader = " " +vim.g.maplocalleader = " " -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` -- Clear highlights on search when pressing in normal mode -- See `:help hlsearch` -vim.keymap.set('n', '', 'nohlsearch') +vim.keymap.set("n", "", "nohlsearch") -- Delete entire word with Alt+Backspace -vim.keymap.set('i', '', '') +vim.keymap.set("i", "", "") -- Diagnostic keymaps -vim.keymap.set('n', '[d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' }) -vim.keymap.set('n', ']d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' }) -vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror message' }) -vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) +vim.keymap.set("n", "[d", vim.diagnostic.goto_next, { desc = "Go to next [D]iagnostic message" }) +vim.keymap.set("n", "]d", vim.diagnostic.goto_prev, { desc = "Go to previous [D]iagnostic message" }) +vim.keymap.set("n", "e", vim.diagnostic.open_float, { desc = "Show diagnostic [E]rror message" }) +vim.keymap.set("n", "q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" }) -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- for people to discover. Otherwise, you normally need to press , which @@ -25,39 +25,43 @@ vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagn -- -- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping -- or just use to exit terminal mode -vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) +vim.keymap.set("t", "", "", { desc = "Exit terminal mode" }) -- TIP: Disable arrow keys in normal mode -vim.keymap.set('n', '', 'echo "Use h to move!!"') -vim.keymap.set('n', '', 'echo "Use l to move!!"') -vim.keymap.set('n', '', 'echo "Use k to move!!"') -vim.keymap.set('n', '', 'echo "Use j to move!!"') +vim.keymap.set("n", "", 'echo "Use h to move!!"') +vim.keymap.set("n", "", 'echo "Use l to move!!"') +vim.keymap.set("n", "", 'echo "Use k to move!!"') +vim.keymap.set("n", "", 'echo "Use j to move!!"') -- Keybinds to make split navigation easier. -- Use CTRL+ to switch between windowsC -- -- See `:help wincmd` for a list of all window commands -vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) +vim.keymap.set("n", "", "", { desc = "Move focus to the left window" }) +vim.keymap.set("n", "", "", { desc = "Move focus to the right window" }) +vim.keymap.set("n", "", "", { desc = "Move focus to the lower window" }) +vim.keymap.set("n", "", "", { desc = "Move focus to the upper window" }) -- Window management -vim.keymap.set('n', 'sv', 'v', { desc = '[S]plit window [V]ertically' }) -vim.keymap.set('n', 'sh', 's', { desc = '[S]plit window [H]orizontally' }) -vim.keymap.set('n', 'se', '=', { desc = 'Make [S]plit [E]qual size' }) -vim.keymap.set('n', 'sx', 'close', { desc = 'Current [S]plit [X]Close' }) +vim.keymap.set("n", "sv", "v", { desc = "[S]plit window [V]ertically" }) +vim.keymap.set("n", "sh", "s", { desc = "[S]plit window [H]orizontally" }) +vim.keymap.set("n", "se", "=", { desc = "Make [S]plit [E]qual size" }) +vim.keymap.set("n", "sx", "close", { desc = "Current [S]plit [X]Close" }) -- Tab management -vim.keymap.set('n', 'to', 'tabnew', { desc = 'Open new tab' }) -- open new tab -vim.keymap.set('n', 'tx', 'tabclose', { desc = 'Close current tab' }) -- close current tab -vim.keymap.set('n', 'tn', 'tabn', { desc = 'Go to next tab' }) -- go to next tab -vim.keymap.set('n', 'tp', 'tabp', { desc = 'Go to previous tab' }) -- go to previous tab -vim.keymap.set('n', 'tf', 'tabnew %', { desc = 'Open current buffer in new tab' }) -- move current buffer to new tab +vim.keymap.set("n", "to", "tabnew", { desc = "Open new tab" }) -- open new tab +vim.keymap.set("n", "tx", "tabclose", { desc = "Close current tab" }) -- close current tab +vim.keymap.set("n", "tn", "tabn", { desc = "Go to next tab" }) -- go to next tab +vim.keymap.set("n", "tp", "tabp", { desc = "Go to previous tab" }) -- go to previous tab +vim.keymap.set("n", "tf", "tabnew %", { desc = "Open current buffer in new tab" }) -- move current buffer to new tab -- Gopher plugin keymaps -vim.keymap.set('n', 'if', ' GoIfErr ', { desc = 'Add if err != nil snippet' }) +vim.keymap.set("n", "if", " GoIfErr ", { desc = "Add if err != nil snippet" }) -- Borrowed from my VS Code settings for better Vim navigations -vim.keymap.set('n', 'l', '$', { desc = 'Move to end of the line with leader + l' }) -vim.keymap.set('n', 'h', '_', { desc = 'Move to first character of the line with leader + h' }) +vim.keymap.set("n", "l", "$", { desc = "Move to end of the line with leader + l" }) +vim.keymap.set("n", "h", "_", { desc = "Move to first character of the line with leader + h" }) + +-- Gitsigns to toggle hunk preview and git line blame +vim.keymap.set("n", "gp", ":Gitsigns preview_hunk", { desc = "Preview changes made on the current line" }) +vim.keymap.set("n", "gt", ":Gitsigns toggle_current_line_blame", { desc = "View current line blame" }) diff --git a/lua/rakshit/plugins/git-blame.lua b/lua/rakshit/plugins/git-blame.lua new file mode 100644 index 00000000..46d0b699 --- /dev/null +++ b/lua/rakshit/plugins/git-blame.lua @@ -0,0 +1,19 @@ +return { + "f-person/git-blame.nvim", + -- load the plugin at startup + event = "VeryLazy", + -- Because of the keys part, you will be lazy loading this plugin. + -- The plugin wil only load once one of the keys is used. + -- If you want to load the plugin at startup, add something like event = "VeryLazy", + -- or lazy = false. One of both options will work. + opts = { + -- your configuration comes here + -- for example + enabled = true, -- if you want to enable the plugin + message_template = " • <>", -- template for the blame message, check the Message template section for more options + date_format = "%m-%d-%Y", -- template for the date, check Date format section for more options + virtual_text_column = 80, -- virtual text start column, check Start virtual text at column section for more options + message_when_not_committed = "Not committed yet", + display_virtual_text = 1, + }, +} diff --git a/lua/rakshit/plugins/gitsigns.lua b/lua/rakshit/plugins/gitsigns.lua new file mode 100644 index 00000000..348eaa1d --- /dev/null +++ b/lua/rakshit/plugins/gitsigns.lua @@ -0,0 +1,19 @@ +return { + -- Here is a more advanced example where we pass configuration + -- options to `gitsigns.nvim`. This is equivalent to the following Lua: + -- require('gitsigns').setup({ ... }) + -- + -- See `:help gitsigns` to understand what the configuration keys do + { -- Adds git related signs to the gutter, as well as utilities for managing changes + "lewis6991/gitsigns.nvim", + opts = { + signs = { + add = { text = "+" }, + change = { text = "~" }, + delete = { text = "_" }, + topdelete = { text = "‾" }, + changedelete = { text = "~" }, + }, + }, + }, +} diff --git a/lua/rakshit/plugins/init.lua b/lua/rakshit/plugins/init.lua index b7c37aee..9b4321cd 100644 --- a/lua/rakshit/plugins/init.lua +++ b/lua/rakshit/plugins/init.lua @@ -1,8 +1,8 @@ return { - 'nvim-lua/plenary.nvim', -- lua functions that many plugins use - 'christoomey/vim-tmux-navigator', -- tmux % split window navigation + "nvim-lua/plenary.nvim", -- lua functions that many plugins use + "christoomey/vim-tmux-navigator", -- tmux % split window navigation -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). - 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically + "tpope/vim-sleuth", -- Detect tabstop and shiftwidth automatically -- NOTE: Plugins can also be added by using a table, -- with the first argument being the link and the following @@ -11,40 +11,22 @@ return { -- Use `opts = {}` to force a plugin to be loaded. -- - -- Here is a more advanced example where we pass configuration - -- options to `gitsigns.nvim`. This is equivalent to the following Lua: - -- require('gitsigns').setup({ ... }) - -- - -- See `:help gitsigns` to understand what the configuration keys do - { -- Adds git related signs to the gutter, as well as utilities for managing changes - 'lewis6991/gitsigns.nvim', - opts = { - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, - }, - }, - -- LSP Plugins { -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins used for completion, annotations and signatures of Neovim apis - 'folke/lazydev.nvim', - ft = 'lua', + "folke/lazydev.nvim", + ft = "lua", opts = { library = { -- Load luvit types when the `vim.uv` word is found - { path = 'luvit-meta/library', words = { 'vim%.uv' } }, + { path = "luvit-meta/library", words = { "vim%.uv" } }, }, }, }, - { 'Bilal2453/luvit-meta', lazy = true }, + { "Bilal2453/luvit-meta", lazy = true }, { -- Collection of various small independent plugins/modules - 'echasnovski/mini.nvim', + "echasnovski/mini.nvim", config = function() -- Better Around/Inside textobjects -- @@ -52,7 +34,7 @@ return { -- - va) - [V]isually select [A]round [)]paren -- - yinq - [Y]ank [I]nside [N]ext [Q]uote -- - ci' - [C]hange [I]nside [']quote - require('mini.ai').setup { n_lines = 500 } + require("mini.ai").setup({ n_lines = 500 }) -- Add/delete/replace surroundings (brackets, quotes, etc.) -- @@ -64,16 +46,16 @@ return { -- Simple and easy statusline. -- You could remove this setup call if you don't like it, -- and try some other statusline plugin - local statusline = require 'mini.statusline' + local statusline = require("mini.statusline") -- set use_icons to true if you have a Nerd Font - statusline.setup { use_icons = vim.g.have_nerd_font } + statusline.setup({ use_icons = vim.g.have_nerd_font }) -- You can configure sections in the statusline by overriding their -- default behavior. For example, here we set the section for -- cursor location to LINE:COLUMN ---@diagnostic disable-next-line: duplicate-set-field statusline.section_location = function() - return '%2l:%-2v' + return "%2l:%-2v" end -- ... and there is more! diff --git a/lua/rakshit/plugins/vim-fugitive.lua b/lua/rakshit/plugins/vim-fugitive.lua new file mode 100644 index 00000000..2c2efeb2 --- /dev/null +++ b/lua/rakshit/plugins/vim-fugitive.lua @@ -0,0 +1,3 @@ +return { + "tpope/vim-fugitive", +}