diff --git a/init.lua b/init.lua index 83c7afee..80f1092c 100644 --- a/init.lua +++ b/init.lua @@ -241,127 +241,8 @@ local function gh(repo) return 'https://github.com/' .. repo end -- ============================================================ -- SECTION 4: UI / CORE UX PLUGINS --- guess-indent, gitsigns, which-key, colorscheme, todo-comments, mini modules +-- Extracted to lua/kickstart/plugins/{guess-indent,gitsigns,which-key,tokyonight,todo-comments,mini}.lua -- ============================================================ -do - -- [[ Installing and Configuring Plugins ]] - -- - -- To install a plugin simply call `vim.pack.add` with its git url. - -- This will download the default branch of the plugin, which will usually be `main` or `master` - -- You can also have more advanced specs, which we will talk about later. - -- - -- For most plugins its not enough to install them, you also need to call their `.setup()` to start them. - -- - -- For example, lets say we want to install `guess-indent.nvim` - a plugin for - -- automatically detecting and setting the indentation. - -- - -- We first install it from https://github.com/NMAC427/guess-indent.nvim - -- and then call its `setup()` function to start it with default settings. - vim.pack.add { gh 'NMAC427/guess-indent.nvim' } - require('guess-indent').setup {} - - -- Here is a more advanced configuration example that passes options to `gitsigns.nvim` - -- - -- See `:help gitsigns` to understand what each configuration key does. - -- Adds git related signs to the gutter, as well as utilities for managing changes - vim.pack.add { gh 'lewis6991/gitsigns.nvim' } - require('gitsigns').setup { - signs = { - add = { text = '+' }, ---@diagnostic disable-line: missing-fields - change = { text = '~' }, ---@diagnostic disable-line: missing-fields - delete = { text = '_' }, ---@diagnostic disable-line: missing-fields - topdelete = { text = '‾' }, ---@diagnostic disable-line: missing-fields - changedelete = { text = '~' }, ---@diagnostic disable-line: missing-fields - }, - } - - -- Useful plugin to show you pending keybinds. - vim.pack.add { gh 'folke/which-key.nvim' } - require('which-key').setup { - -- Delay between pressing a key and opening which-key (milliseconds) - delay = 0, - icons = { mappings = vim.g.have_nerd_font }, - -- Document existing key chains - spec = { - { 's', group = '[S]earch', mode = { 'n', 'v' } }, - { 't', group = '[T]oggle' }, - { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, -- Enable gitsigns recommended keymaps first - { 'gr', group = 'LSP Actions', mode = { 'n' } }, - }, - } - - -- [[ Colorscheme ]] - -- You can easily change to a different colorscheme. - -- Change the name of the colorscheme plugin below, and then - -- change the command under that to load whatever the name of that colorscheme is. - -- - -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. - vim.pack.add { gh 'folke/tokyonight.nvim' } - ---@diagnostic disable-next-line: missing-fields - require('tokyonight').setup { - styles = { - comments = { italic = false }, -- Disable italics in comments - }, - } - - -- Load the colorscheme here. - -- Like many other themes, this one has different styles, and you could load - -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'. - vim.cmd.colorscheme 'tokyonight-night' - - -- Highlight todo, notes, etc in comments - vim.pack.add { gh 'folke/todo-comments.nvim' } - require('todo-comments').setup { signs = false } - - -- [[ mini.nvim ]] - -- A collection of various small independent plugins/modules - vim.pack.add { gh 'nvim-mini/mini.nvim' } - - -- If a nerd font is available, load the icons module for pretty icons in various plugins. - if vim.g.have_nerd_font then - require('mini.icons').setup() - -- Used for backwards compatibility with plugins that require `nvim-web-devicons` (e.g. telescope.nvim) - MiniIcons.mock_nvim_web_devicons() - end - - -- Better Around/Inside textobjects - -- - -- Examples: - -- - va) - [V]isually select [A]round [)]paren - -- - yiiq - [Y]ank [I]nside [I]+1 [Q]uote - -- - ci' - [C]hange [I]nside [']quote - require('mini.ai').setup { - -- NOTE: Avoid conflicts with the built-in incremental selection mappings on Neovim>=0.12 (see `:help treesitter-incremental-selection`) - mappings = { - around_next = 'aa', - inside_next = 'ii', - }, - n_lines = 500, - } - - -- Add/delete/replace surroundings (brackets, quotes, etc.) - -- - -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren - -- - sd' - [S]urround [D]elete [']quotes - -- - sr)' - [S]urround [R]eplace [)] ['] - require('mini.surround').setup() - - -- 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' - -- Set `use_icons` to true if you have a 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' end - - -- ... and there is more! - -- Check out: https://github.com/nvim-mini/mini.nvim -end -- ============================================================ -- SECTION 5: SEARCH & NAVIGATION diff --git a/lua/kickstart/plugins/gitsigns.lua b/lua/kickstart/plugins/gitsigns.lua index b7e40a87..aac8e88d 100644 --- a/lua/kickstart/plugins/gitsigns.lua +++ b/lua/kickstart/plugins/gitsigns.lua @@ -1,12 +1,19 @@ --- Adds git related signs to the gutter, as well as utilities for managing changes --- NOTE: gitsigns is already included in init.lua but contains only the base --- config. This will add also the recommended keymaps. +-- gitsigns: git signs in the gutter + hunk navigation/actions +local gh = require('kickstart.util').gh -vim.pack.add { 'https://github.com/lewis6991/gitsigns.nvim' } +vim.pack.add { gh 'lewis6991/gitsigns.nvim' } require('gitsigns').setup { + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, on_attach = function(bufnr) - local gitsigns = require 'gitsigns' + local gs = package.loaded.gitsigns + if not gs then return end local function map(mode, l, r, opts) opts = opts or {} @@ -16,42 +23,32 @@ require('gitsigns').setup { -- Navigation map('n', ']c', function() - if vim.wo.diff then - vim.cmd.normal { ']c', bang = true } - else - gitsigns.nav_hunk 'next' - end + if vim.wo.diff then vim.cmd.normal { ']c', bang = true } else gs.nav_hunk 'next' end end, { desc = 'Jump to next git [c]hange' }) - map('n', '[c', function() - if vim.wo.diff then - vim.cmd.normal { '[c', bang = true } - else - gitsigns.nav_hunk 'prev' - end + if vim.wo.diff then vim.cmd.normal { '[c', bang = true } else gs.nav_hunk 'prev' end end, { desc = 'Jump to previous git [c]hange' }) -- Actions - -- visual mode - map('v', 'hs', function() gitsigns.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } end, { desc = 'git [s]tage hunk' }) - map('v', 'hr', function() gitsigns.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } end, { desc = 'git [r]eset hunk' }) - -- normal mode - map('n', 'hs', gitsigns.stage_hunk, { desc = 'git [s]tage hunk' }) - map('n', 'hr', gitsigns.reset_hunk, { desc = 'git [r]eset hunk' }) - map('n', 'hS', gitsigns.stage_buffer, { desc = 'git [S]tage buffer' }) - map('n', 'hR', gitsigns.reset_buffer, { desc = 'git [R]eset buffer' }) - map('n', 'hp', gitsigns.preview_hunk, { desc = 'git [p]review hunk' }) - map('n', 'hi', gitsigns.preview_hunk_inline, { desc = 'git preview hunk [i]nline' }) - map('n', 'hb', function() gitsigns.blame_line { full = true } end, { desc = 'git [b]lame line' }) - map('n', 'hd', gitsigns.diffthis, { desc = 'git [d]iff against index' }) - map('n', 'hD', function() gitsigns.diffthis '@' end, { desc = 'git [D]iff against last commit' }) - map('n', 'hQ', function() gitsigns.setqflist 'all' end, { desc = 'git hunk [Q]uickfix list (all files in repo)' }) - map('n', 'hq', gitsigns.setqflist, { desc = 'git hunk [q]uickfix list (all changes in this file)' }) + map('v', 'hs', function() gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } end, { desc = 'git [s]tage hunk' }) + map('v', 'hr', function() gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } end, { desc = 'git [r]eset hunk' }) + map('n', 'hs', gs.stage_hunk, { desc = 'git [s]tage hunk' }) + map('n', 'hr', gs.reset_hunk, { desc = 'git [r]eset hunk' }) + map('n', 'hS', gs.stage_buffer, { desc = 'git [S]tage buffer' }) + map('n', 'hR', gs.reset_buffer, { desc = 'git [R]eset buffer' }) + map('n', 'hp', gs.preview_hunk, { desc = 'git [p]review hunk' }) + map('n', 'hi', gs.preview_hunk_inline, { desc = 'git preview hunk [i]nline' }) + map('n', 'hb', function() gs.blame_line { full = true } end, { desc = 'git [b]lame line' }) + map('n', 'hd', gs.diffthis, { desc = 'git [d]iff against index' }) + map('n', 'hD', function() gs.diffthis '@' end, { desc = 'git [D]iff against last commit' }) + map('n', 'hQ', function() gs.setqflist 'all' end, { desc = 'git hunk [Q]uickfix list (all files)' }) + map('n', 'hq', gs.setqflist, { desc = 'git hunk [q]uickfix list (this file)' }) + -- Toggles - map('n', 'tb', gitsigns.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' }) - map('n', 'tw', gitsigns.toggle_word_diff, { desc = '[T]oggle git intra-line [w]ord diff' }) + map('n', 'tb', gs.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' }) + map('n', 'tw', gs.toggle_word_diff, { desc = '[T]oggle git intra-line [w]ord diff' }) -- Text object - map({ 'o', 'x' }, 'ih', gitsigns.select_hunk) + map({ 'o', 'x' }, 'ih', gs.select_hunk) end, } diff --git a/lua/kickstart/plugins/guess-indent.lua b/lua/kickstart/plugins/guess-indent.lua new file mode 100644 index 00000000..b3344a4c --- /dev/null +++ b/lua/kickstart/plugins/guess-indent.lua @@ -0,0 +1,4 @@ +local gh = require('kickstart.util').gh + +vim.pack.add { gh 'NMAC427/guess-indent.nvim' } +require('guess-indent').setup {} diff --git a/lua/kickstart/plugins/mini.lua b/lua/kickstart/plugins/mini.lua new file mode 100644 index 00000000..30f59ba3 --- /dev/null +++ b/lua/kickstart/plugins/mini.lua @@ -0,0 +1,26 @@ +local gh = require('kickstart.util').gh + +vim.pack.add { gh 'nvim-mini/mini.nvim' } + +-- Icons (only if Nerd Font available) +if vim.g.have_nerd_font then + require('mini.icons').setup() + MiniIcons.mock_nvim_web_devicons() +end + +-- Better Around/Inside textobjects (vag, cia, etc.) +require('mini.ai').setup { + mappings = { + around_next = 'aa', + inside_next = 'ii', + }, + n_lines = 500, +} + +-- Surround (add/delete/replace brackets, quotes, etc.) +require('mini.surround').setup() + +-- Statusline +local statusline = require 'mini.statusline' +statusline.setup { use_icons = vim.g.have_nerd_font } +statusline.section_location = function() return '%2l:%-2v' end diff --git a/lua/kickstart/plugins/todo-comments.lua b/lua/kickstart/plugins/todo-comments.lua new file mode 100644 index 00000000..a92596ad --- /dev/null +++ b/lua/kickstart/plugins/todo-comments.lua @@ -0,0 +1,4 @@ +local gh = require('kickstart.util').gh + +vim.pack.add { gh 'folke/todo-comments.nvim' } +require('todo-comments').setup { signs = false } diff --git a/lua/kickstart/plugins/tokyonight.lua b/lua/kickstart/plugins/tokyonight.lua new file mode 100644 index 00000000..69b6983f --- /dev/null +++ b/lua/kickstart/plugins/tokyonight.lua @@ -0,0 +1,10 @@ +local gh = require('kickstart.util').gh + +vim.pack.add { gh 'folke/tokyonight.nvim' } +require('tokyonight').setup { + styles = { + comments = { italic = false }, + }, +} + +vim.cmd.colorscheme 'tokyonight-night' diff --git a/lua/kickstart/plugins/which-key.lua b/lua/kickstart/plugins/which-key.lua new file mode 100644 index 00000000..3c9615b9 --- /dev/null +++ b/lua/kickstart/plugins/which-key.lua @@ -0,0 +1,13 @@ +local gh = require('kickstart.util').gh + +vim.pack.add { gh 'folke/which-key.nvim' } +require('which-key').setup { + delay = 0, + icons = { mappings = vim.g.have_nerd_font }, + spec = { + { 's', group = '[S]earch', mode = { 'n', 'v' } }, + { 't', group = '[T]oggle' }, + { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, + { 'gr', group = 'LSP Actions', mode = { 'n' } }, + }, +}