refactor: extract UI/core plugins from init.lua into plugin files
This commit is contained in:
parent
8f81178f7b
commit
0f9ad85731
121
init.lua
121
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 = {
|
||||
{ '<leader>s', group = '[S]earch', mode = { 'n', 'v' } },
|
||||
{ '<leader>t', group = '[T]oggle' },
|
||||
{ '<leader>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
|
||||
|
|
|
|||
|
|
@ -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', '<leader>hs', function() gitsigns.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } end, { desc = 'git [s]tage hunk' })
|
||||
map('v', '<leader>hr', function() gitsigns.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } end, { desc = 'git [r]eset hunk' })
|
||||
-- normal mode
|
||||
map('n', '<leader>hs', gitsigns.stage_hunk, { desc = 'git [s]tage hunk' })
|
||||
map('n', '<leader>hr', gitsigns.reset_hunk, { desc = 'git [r]eset hunk' })
|
||||
map('n', '<leader>hS', gitsigns.stage_buffer, { desc = 'git [S]tage buffer' })
|
||||
map('n', '<leader>hR', gitsigns.reset_buffer, { desc = 'git [R]eset buffer' })
|
||||
map('n', '<leader>hp', gitsigns.preview_hunk, { desc = 'git [p]review hunk' })
|
||||
map('n', '<leader>hi', gitsigns.preview_hunk_inline, { desc = 'git preview hunk [i]nline' })
|
||||
map('n', '<leader>hb', function() gitsigns.blame_line { full = true } end, { desc = 'git [b]lame line' })
|
||||
map('n', '<leader>hd', gitsigns.diffthis, { desc = 'git [d]iff against index' })
|
||||
map('n', '<leader>hD', function() gitsigns.diffthis '@' end, { desc = 'git [D]iff against last commit' })
|
||||
map('n', '<leader>hQ', function() gitsigns.setqflist 'all' end, { desc = 'git hunk [Q]uickfix list (all files in repo)' })
|
||||
map('n', '<leader>hq', gitsigns.setqflist, { desc = 'git hunk [q]uickfix list (all changes in this file)' })
|
||||
map('v', '<leader>hs', function() gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } end, { desc = 'git [s]tage hunk' })
|
||||
map('v', '<leader>hr', function() gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } end, { desc = 'git [r]eset hunk' })
|
||||
map('n', '<leader>hs', gs.stage_hunk, { desc = 'git [s]tage hunk' })
|
||||
map('n', '<leader>hr', gs.reset_hunk, { desc = 'git [r]eset hunk' })
|
||||
map('n', '<leader>hS', gs.stage_buffer, { desc = 'git [S]tage buffer' })
|
||||
map('n', '<leader>hR', gs.reset_buffer, { desc = 'git [R]eset buffer' })
|
||||
map('n', '<leader>hp', gs.preview_hunk, { desc = 'git [p]review hunk' })
|
||||
map('n', '<leader>hi', gs.preview_hunk_inline, { desc = 'git preview hunk [i]nline' })
|
||||
map('n', '<leader>hb', function() gs.blame_line { full = true } end, { desc = 'git [b]lame line' })
|
||||
map('n', '<leader>hd', gs.diffthis, { desc = 'git [d]iff against index' })
|
||||
map('n', '<leader>hD', function() gs.diffthis '@' end, { desc = 'git [D]iff against last commit' })
|
||||
map('n', '<leader>hQ', function() gs.setqflist 'all' end, { desc = 'git hunk [Q]uickfix list (all files)' })
|
||||
map('n', '<leader>hq', gs.setqflist, { desc = 'git hunk [q]uickfix list (this file)' })
|
||||
|
||||
-- Toggles
|
||||
map('n', '<leader>tb', gitsigns.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' })
|
||||
map('n', '<leader>tw', gitsigns.toggle_word_diff, { desc = '[T]oggle git intra-line [w]ord diff' })
|
||||
map('n', '<leader>tb', gs.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' })
|
||||
map('n', '<leader>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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
local gh = require('kickstart.util').gh
|
||||
|
||||
vim.pack.add { gh 'NMAC427/guess-indent.nvim' }
|
||||
require('guess-indent').setup {}
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
local gh = require('kickstart.util').gh
|
||||
|
||||
vim.pack.add { gh 'folke/todo-comments.nvim' }
|
||||
require('todo-comments').setup { signs = false }
|
||||
|
|
@ -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'
|
||||
|
|
@ -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 = {
|
||||
{ '<leader>s', group = '[S]earch', mode = { 'n', 'v' } },
|
||||
{ '<leader>t', group = '[T]oggle' },
|
||||
{ '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
|
||||
{ 'gr', group = 'LSP Actions', mode = { 'n' } },
|
||||
},
|
||||
}
|
||||
Loading…
Reference in New Issue