From ede599bae8fc58cbe5feac3b2a6307a19179608d Mon Sep 17 00:00:00 2001 From: juanito87 Date: Mon, 22 Apr 2024 21:28:19 -0300 Subject: [PATCH] Renaming files, moving to modular config. --- init.lua | 4 + lua/autocommands.lua | 10 +- lua/lazy-config.lua | 63 +++------- .../plugins => plugins_config}/autopairs.lua | 0 .../plugins => plugins_config}/debug.lua | 0 .../plugins => plugins_config}/gitsigns.lua | 11 +- lua/plugins_config/harpoon.lua | 18 +++ lua/{kickstart => plugins_config}/health.lua | 0 .../indent_line.lua | 0 .../plugins => plugins_config}/lint.lua | 0 .../plugins => plugins_config}/neo-tree.lua | 0 lua/plugins_config/telescope.lua | 111 ++++++++++++++++++ lua/plugins_config/vim-fugitive.lua | 42 +++++++ lua/plugins_config/which-key.lua | 22 ++++ lua/plugins_config/worktree.lua | 3 + 15 files changed, 231 insertions(+), 53 deletions(-) rename lua/{kickstart/plugins => plugins_config}/autopairs.lua (100%) rename lua/{kickstart/plugins => plugins_config}/debug.lua (100%) rename lua/{kickstart/plugins => plugins_config}/gitsigns.lua (92%) create mode 100644 lua/plugins_config/harpoon.lua rename lua/{kickstart => plugins_config}/health.lua (100%) rename lua/{kickstart/plugins => plugins_config}/indent_line.lua (100%) rename lua/{kickstart/plugins => plugins_config}/lint.lua (100%) rename lua/{kickstart/plugins => plugins_config}/neo-tree.lua (100%) create mode 100644 lua/plugins_config/telescope.lua create mode 100644 lua/plugins_config/vim-fugitive.lua create mode 100644 lua/plugins_config/which-key.lua create mode 100644 lua/plugins_config/worktree.lua diff --git a/init.lua b/init.lua index 80640821..1b04fff5 100644 --- a/init.lua +++ b/init.lua @@ -93,6 +93,10 @@ vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal vim.g.have_nerd_font = true +-- [[ Global variables ]] +Autocmd = vim.api.nvim_create_autocmd +Fugitive = vim.api.nvim_create_augroup('juanito_Fugitive', {}) + -- [[ Setting options ]] require 'options' diff --git a/lua/autocommands.lua b/lua/autocommands.lua index 16295ad8..f1f111de 100644 --- a/lua/autocommands.lua +++ b/lua/autocommands.lua @@ -1,13 +1,11 @@ -- [[ Autocommands ]] -- See `:help lua-guide-autocommands` -- Definitions -local autocmd = vim.api.nvim_create_autocmd --- local augroup = vim.api.nvim_create_augroup -- Highlight when yanking (copying) text -- Try it with `yap` in normal mode -- See `:help vim.highlight.on_yank()` -autocmd('TextYankPost', { +Autocmd('TextYankPost', { desc = 'Highlight when yanking (copying) text', group = vim.api.nvim_create_augroup('highlight-yank', { clear = true }), callback = function() @@ -20,7 +18,7 @@ local function augroup(name) return vim.api.nvim_create_augroup('lazyvim_' .. name, { clear = true }) end -autocmd({ 'VimResized' }, { +Autocmd({ 'VimResized' }, { group = augroup 'resize_splits', callback = function() vim.cmd 'tabdo wincmd =' @@ -28,7 +26,7 @@ autocmd({ 'VimResized' }, { }) -- Remove auto comment next line -autocmd({ 'BufEnter' }, { +Autocmd({ 'BufEnter' }, { group = augroup 'remove_auto_comment', callback = function() vim.cmd 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o' @@ -36,7 +34,7 @@ autocmd({ 'BufEnter' }, { }) -- Set cursorline only in focused window -autocmd({ 'WinEnter', 'WinLeave' }, { +Autocmd({ 'WinEnter', 'WinLeave' }, { group = augroup 'cursorline', callback = function() vim.wo.cursorline = vim.fn.win_getid() == vim.fn.win_getid() diff --git a/lua/lazy-config.lua b/lua/lazy-config.lua index 179e2f1f..d506c4b4 100644 --- a/lua/lazy-config.lua +++ b/lua/lazy-config.lua @@ -1,7 +1,4 @@ -- [[ Configure and install plugins ]] --- Definitions -local autocmd = vim.api.nvim_create_autocmd --- -- To check the current status of your plugins, run -- :Lazy -- @@ -13,7 +10,16 @@ local autocmd = vim.api.nvim_create_autocmd -- NOTE: Here is where you install your plugins. require('lazy').setup({ -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). + -- Plugins with default values 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically + -- Plugins with custom values + require 'plugins_config/vim-fugitive', -- Manage git in nvim + require 'plugins_config/which-key', -- Show created key bindings + -- require 'plugins_config/gitsigns', -- Manage git signs + + 'APZelos/blamer.nvim', -- Show git blame + 'ThePrimeagen/git-worktree.nvim', -- Manage worktrees from nvim + 'theprimeagen/harpoon', -- Improve workflow for multiple files -- NOTE: Plugins can also be added by using a table, -- with the first argument being the link and the following @@ -32,18 +38,6 @@ require('lazy').setup({ -- 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 = '~' }, - }, - }, - }, -- NOTE: Plugins can also be configured to run Lua code when they are loaded. -- @@ -60,29 +54,6 @@ require('lazy').setup({ -- after the plugin has been loaded: -- config = function() ... end - { -- Useful plugin to show you pending keybinds. - 'folke/which-key.nvim', - event = 'VimEnter', -- Sets the loading event to 'VimEnter' - config = function() -- This is the function that runs, AFTER loading - require('which-key').setup() - - -- Document existing key chains - require('which-key').register { - ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, - ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, - ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, - ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, - ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, - ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, - ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, - } - -- visual mode - require('which-key').register({ - ['h'] = { 'Git [H]unk' }, - }, { mode = 'v' }) - end, - }, - -- NOTE: Plugins can specify dependencies. -- -- The dependencies are proper plugin specifications as well - anything @@ -241,8 +212,8 @@ require('lazy').setup({ -- That is to say, every time a new file is opened that is associated with -- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this -- function will be executed to configure the current buffer - autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('lsp-attach', { clear = true }), + Autocmd('LspAttach', { + group = Augroup('lsp-attach', { clear = true }), callback = function(event) -- NOTE: Remember that Lua is a real programming language, and as such it is possible -- to define small helper and utility functions so you don't have to repeat yourself. @@ -301,12 +272,12 @@ require('lazy').setup({ -- When you move your cursor, the highlights will be cleared (the second autocommand). local client = vim.lsp.get_client_by_id(event.data.client_id) if client and client.server_capabilities.documentHighlightProvider then - autocmd({ 'CursorHold', 'CursorHoldI' }, { + Autocmd({ 'CursorHold', 'CursorHoldI' }, { buffer = event.buf, callback = vim.lsp.buf.document_highlight, }) - autocmd({ 'CursorMoved', 'CursorMovedI' }, { + Autocmd({ 'CursorMoved', 'CursorMovedI' }, { buffer = event.buf, callback = vim.lsp.buf.clear_references, }) @@ -429,8 +400,12 @@ require('lazy').setup({ formatters_by_ft = { lua = { 'stylua' }, -- Conform can also run multiple formatters sequentially - -- python = { "isort", "black" }, - -- + python = { 'isort', 'black' }, + yaml = { 'yamlfix' }, + go = { 'gofmt' }, + rust = { 'rustfmt' }, + toml = { 'taplo' }, + jinja2 = { 'djlint' }, -- You can use a sub-list to tell conform to run *until* a formatter -- is found. -- javascript = { { "prettierd", "prettier" } }, diff --git a/lua/kickstart/plugins/autopairs.lua b/lua/plugins_config/autopairs.lua similarity index 100% rename from lua/kickstart/plugins/autopairs.lua rename to lua/plugins_config/autopairs.lua diff --git a/lua/kickstart/plugins/debug.lua b/lua/plugins_config/debug.lua similarity index 100% rename from lua/kickstart/plugins/debug.lua rename to lua/plugins_config/debug.lua diff --git a/lua/kickstart/plugins/gitsigns.lua b/lua/plugins_config/gitsigns.lua similarity index 92% rename from lua/kickstart/plugins/gitsigns.lua rename to lua/plugins_config/gitsigns.lua index 4bcc70f4..557c2200 100644 --- a/lua/kickstart/plugins/gitsigns.lua +++ b/lua/plugins_config/gitsigns.lua @@ -3,9 +3,15 @@ -- config. This will add also the recommended keymaps. return { - { 'lewis6991/gitsigns.nvim', opts = { + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, on_attach = function(bufnr) local gitsigns = require 'gitsigns' @@ -57,5 +63,4 @@ return { map('n', 'tD', gitsigns.toggle_deleted, { desc = '[T]oggle git show [D]eleted' }) end, }, - }, -} + } diff --git a/lua/plugins_config/harpoon.lua b/lua/plugins_config/harpoon.lua new file mode 100644 index 00000000..acec5d06 --- /dev/null +++ b/lua/plugins_config/harpoon.lua @@ -0,0 +1,18 @@ +local mark = require 'harpoon.mark' +local ui = require 'harpoon.ui' + +vim.keymap.set('n', 'a', mark.add_file) +vim.keymap.set('n', '', ui.toggle_quick_menu) + +vim.keymap.set('n', '', function() + ui.nav_file(1) +end) +vim.keymap.set('n', '', function() + ui.nav_file(2) +end) +vim.keymap.set('n', '', function() + ui.nav_file(3) +end) +vim.keymap.set('n', '', function() + ui.nav_file(4) +end) diff --git a/lua/kickstart/health.lua b/lua/plugins_config/health.lua similarity index 100% rename from lua/kickstart/health.lua rename to lua/plugins_config/health.lua diff --git a/lua/kickstart/plugins/indent_line.lua b/lua/plugins_config/indent_line.lua similarity index 100% rename from lua/kickstart/plugins/indent_line.lua rename to lua/plugins_config/indent_line.lua diff --git a/lua/kickstart/plugins/lint.lua b/lua/plugins_config/lint.lua similarity index 100% rename from lua/kickstart/plugins/lint.lua rename to lua/plugins_config/lint.lua diff --git a/lua/kickstart/plugins/neo-tree.lua b/lua/plugins_config/neo-tree.lua similarity index 100% rename from lua/kickstart/plugins/neo-tree.lua rename to lua/plugins_config/neo-tree.lua diff --git a/lua/plugins_config/telescope.lua b/lua/plugins_config/telescope.lua new file mode 100644 index 00000000..18aa92d2 --- /dev/null +++ b/lua/plugins_config/telescope.lua @@ -0,0 +1,111 @@ +return { -- Fuzzy Finder (files, lsp, etc) + 'nvim-telescope/telescope.nvim', + event = 'VimEnter', + branch = '0.1.x', + dependencies = { + 'nvim-lua/plenary.nvim', + { -- If encountering errors, see telescope-fzf-native README for installation instructions + 'nvim-telescope/telescope-fzf-native.nvim', + + -- `build` is used to run some command when the plugin is installed/updated. + -- This is only run then, not every time Neovim starts up. + build = 'make', + + -- `cond` is a condition used to determine whether this plugin should be + -- installed and loaded. + cond = function() + return vim.fn.executable 'make' == 1 + end, + }, + { 'nvim-telescope/telescope-ui-select.nvim' }, + + -- Useful for getting pretty icons, but requires a Nerd Font. + { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, + { 'ThePrimeagen/git-worktree' }, + }, + config = function() + -- Telescope is a fuzzy finder that comes with a lot of different things that + -- it can fuzzy find! It's more than just a "file finder", it can search + -- many different aspects of Neovim, your workspace, LSP, and more! + -- + -- The easiest way to use Telescope, is to start by doing something like: + -- :Telescope help_tags + -- + -- After running this command, a window will open up and you're able to + -- type in the prompt window. You'll see a list of `help_tags` options and + -- a corresponding preview of the help. + -- + -- Two important keymaps to use while in Telescope are: + -- - Insert mode: + -- - Normal mode: ? + -- + -- This opens a window that shows you all of the keymaps for the current + -- Telescope picker. This is really useful to discover what Telescope can + -- do as well as how to actually do it! + + -- [[ Configure Telescope ]] + -- See `:help telescope` and `:help telescope.setup()` + require('telescope').setup { + -- You can put your default mappings / updates / etc. in here + -- All the info you're looking for is in `:help telescope.setup()` + -- + -- defaults = { + -- mappings = { + -- i = { [''] = 'to_fuzzy_refine' }, + -- }, + -- }, + -- pickers = {} + extensions = { + ['ui-select'] = { + require('telescope.themes').get_dropdown(), + }, + }, + } + + -- Enable Telescope extensions if they are installed + pcall(require('telescope').load_extension, 'fzf') + pcall(require('telescope').load_extension, 'ui-select') + + -- See `:help telescope.builtin` + local builtin = require 'telescope.builtin' + vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) + vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) + vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) + vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) + vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) + vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) + vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) + vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) + vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) + vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + vim.keymap.set('n', 'wm', function() + require('telescope').extensions.git_worktree.git_worktrees() -- manage worktrees on telescope + end) + vim.keymap.set('n', 'wc', function() + require('telescope').extensions.git_worktree.create_git_worktree() -- create worktree + end) + + -- Slightly advanced example of overriding default behavior and theme + vim.keymap.set('n', '/', function() + -- You can pass additional configuration to Telescope to change the theme, layout, etc. + builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + winblend = 10, + previewer = false, + }) + end, { desc = '[/] Fuzzily search in current buffer' }) + + -- It's also possible to pass additional configuration options. + -- See `:help telescope.builtin.live_grep()` for information about particular keys + vim.keymap.set('n', 's/', function() + builtin.live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } + end, { desc = '[S]earch [/] in Open Files' }) + + -- Shortcut for searching your Neovim configuration files + vim.keymap.set('n', 'sn', function() + builtin.find_files { cwd = vim.fn.stdpath 'config' } + end, { desc = '[S]earch [N]eovim files' }) + end, +} diff --git a/lua/plugins_config/vim-fugitive.lua b/lua/plugins_config/vim-fugitive.lua new file mode 100644 index 00000000..23368a17 --- /dev/null +++ b/lua/plugins_config/vim-fugitive.lua @@ -0,0 +1,42 @@ +return { + 'tpope/vim-fugitive', + + -- set git status remap + vim.keymap.set('n', 'gs', vim.cmd.Git, { desc = 'Start git buffer and check status' }), + vim.keymap.set('n', 'dv', ':Gvdiffsplit!', { desc = 'Diff split against HEAD vertical' }), + vim.keymap.set('n', 'dh', ':Gdiffsplit!', { desc = 'Diff split against HEAD horizontal' }), + vim.keymap.set('n', 'dt', ':windo diffthis', { desc = 'Diff files in all windows' }), + vim.keymap.set('n', 'dm', ':Gdiff!', { desc = 'On conflicted file opens a 3-way diff' }), + vim.keymap.set('n', '2', ':diffget //2 | diffupdate', { desc = 'On the middle file get the diff from Head' }), + vim.keymap.set('n', '3', ':diffget //3 | diffupdate', { desc = 'On the middle file get the diff from the other branch' }), + vim.keymap.set('n', 'do', ':diffo!', { desc = 'Turn off diff mode' }), + + -- + Autocmd('BufWinEnter', { + group = Fugitive, + pattern = '*', + callback = function() + if vim.bo.ft ~= 'fugitive' then + return + end + + local bufnr = vim.api.nvim_get_current_buf() + local opts = { buffer = bufnr, remap = false } + vim.keymap.set('n', 'gc', function() + vim.cmd.Git 'commit' + end) + vim.keymap.set('n', 'p', function() + vim.cmd.Git 'push' + end, opts) + + -- rebase always + vim.keymap.set('n', 'P', function() + vim.cmd.Git { 'pull', '--rebase' } + end, opts) + + -- NOTE: It allows me to easily set the branch i am pushing and any tracking + -- needed if i did not set the branch up correctly + vim.keymap.set('n', 't', ':Git push -u origin ', opts) + end, + }), +} diff --git a/lua/plugins_config/which-key.lua b/lua/plugins_config/which-key.lua new file mode 100644 index 00000000..a5585ca4 --- /dev/null +++ b/lua/plugins_config/which-key.lua @@ -0,0 +1,22 @@ + return { -- Useful plugin to show you pending keybinds. + 'folke/which-key.nvim', + event = 'VimEnter', -- Sets the loading event to 'VimEnter' + config = function() -- This is the function that runs, AFTER loading + require('which-key').setup() + + -- Document existing key chains + require('which-key').register { + ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, + ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, + ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, + ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, + ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, + ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, + ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, + } + -- visual mode + require('which-key').register({ + ['h'] = { 'Git [H]unk' }, + }, { mode = 'v' }) + end, + } diff --git a/lua/plugins_config/worktree.lua b/lua/plugins_config/worktree.lua new file mode 100644 index 00000000..3b73e668 --- /dev/null +++ b/lua/plugins_config/worktree.lua @@ -0,0 +1,3 @@ +require('git-worktree').setup { + change_directory_command = 'tcd', -- command to change directory (e.g. lcd for NvimTree) +}