From 0a47d7713362a14f999c47090ab693f125a5812c Mon Sep 17 00:00:00 2001 From: realfresh <7835503+realfresh@users.noreply.github.com/Users/reemus/Archive/linux/backup/.gitconfig> Date: Wed, 25 Dec 2024 13:55:30 +0800 Subject: [PATCH] autocommit --- init.lua | 98 ++++++++++++++++++++++++++++++++++--- lua/custom/plugins/init.lua | 41 +++++++++++++++- 2 files changed, 132 insertions(+), 7 deletions(-) diff --git a/init.lua b/init.lua index 4ce35f4b..d48cfbac 100644 --- a/init.lua +++ b/init.lua @@ -34,7 +34,7 @@ What is Kickstart? If you don't know anything about Lua, I recommend taking some time to read through a guide. One possible example which will only take 10-15 minutes: - - https://learnxinyminutes.com/docs/lua/ + - https://learnxinyminutes.com/docs/lua/ini After understanding a bit more about Lua, you can use `:help lua-guide` as a reference for how Neovim integrates Lua. @@ -91,7 +91,7 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.opt` @@ -155,7 +155,7 @@ vim.opt.inccommand = 'split' vim.opt.cursorline = true -- Minimal number of screen lines to keep above and below the cursor. -vim.opt.scrolloff = 10 +vim.opt.scrolloff = 20 -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` @@ -204,6 +204,20 @@ vim.api.nvim_create_autocmd('TextYankPost', { end, }) +-- WARN: My Configuration + +-- vim.opt.fillchars = { fold = ' ' } +-- vim.opt.foldmethod = 'indent' +-- vim.opt.foldenable = false +-- vim.opt.foldlevel = 99 +-- g.markdown_folding = 1 -- enable markdown folding + +vim.keymap.set('n', 'x', 'source %') +vim.keymap.set('n', 'x', ':.lua') +vim.keymap.set('v', 'x', ':lua') + +-- WARN: My Configuration + -- [[ Install `lazy.nvim` plugin manager ]] -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' @@ -247,12 +261,84 @@ require('lazy').setup({ 'lewis6991/gitsigns.nvim', opts = { signs = { - add = { text = '+' }, - change = { text = '~' }, + add = { text = '┃' }, + change = { text = '┃' }, delete = { text = '_' }, topdelete = { text = '‾' }, changedelete = { text = '~' }, + untracked = { text = '┆' }, }, + signs_staged = { + add = { text = '┃' }, + change = { text = '┃' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + untracked = { text = '┆' }, + }, + signs_staged_enable = true, + on_attach = function(bufnr) + local gitsigns = require 'gitsigns' + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then + vim.cmd.normal { ']c', bang = true } + else + gitsigns.nav_hunk 'next' + end + end) + + map('n', '[c', function() + if vim.wo.diff then + vim.cmd.normal { '[c', bang = true } + else + gitsigns.nav_hunk 'prev' + end + end) + + -- Keybinds + map('n', 'hp', gitsigns.preview_hunk) + + vim.cmd [[ + highlight GitSignsAdd guifg=green guibg=NONE + highlight GitSignsChange guifg=darkyellow guibg=NONE + highlight GitSignsDelete guifg=red guibg=NONE + ]] + + --[[ + -- Actions + map('n', 'hs', gitsigns.stage_hunk) + map('n', 'hr', gitsigns.reset_hunk) + map('v', 'hs', function() + gitsigns.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } + end) + map('v', 'hr', function() + gitsigns.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } + end) + map('n', 'hS', gitsigns.stage_buffer) + map('n', 'hu', gitsigns.undo_stage_hunk) + map('n', 'hR', gitsigns.reset_buffer) + map('n', 'hb', function() + gitsigns.blame_line { full = true } + end) + map('n', 'tb', gitsigns.toggle_current_line_blame) + map('n', 'hd', gitsigns.diffthis) + map('n', 'hD', function() + gitsigns.diffthis '~' + end) + map('n', 'td', gitsigns.toggle_deleted) + + -- Text object + map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk') + --]] + end, }, }, @@ -937,7 +1023,7 @@ require('lazy').setup({ -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope! diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index be0eb9d8..21714d7e 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -2,4 +2,43 @@ -- I promise not to create any merge conflicts in this directory :) -- -- See the kickstart.nvim README for more information -return {} +return { + -- Add this section for nvim-ufo and its dependencies + { + 'kevinhwang91/nvim-ufo', + dependencies = { + 'kevinhwang91/promise-async', + 'nvim-treesitter/nvim-treesitter', + }, + config = function() + -- Enable fold column + vim.o.foldcolumn = '1' + -- Set fold level to 99 (effectively expanding all folds) + vim.o.foldlevel = 99 + -- Start with all folds expanded + vim.o.foldlevelstart = 99 + -- Use nvim-ufo provider + vim.o.foldenable = true + + -- Using ufo provider need remap `zR` and `zM` + vim.keymap.set('n', 'zR', require('ufo').openAllFolds) + vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) + vim.keymap.set('n', 'zm', require('ufo').closeFoldsWith) -- closeAllFolds == closeFoldsWith(0) + vim.keymap.set('n', 'K', function() + local winid = require('ufo').peekFoldedLinesUnderCursor() + if not winid then + -- choose one of coc.nvim and nvim lsp + vim.fn.CocActionAsync 'definitionHover' -- coc.nvim + vim.lsp.buf.hover() + end + end) + + -- Configure UFO + require('ufo').setup { + provider_selector = function(bufnr, filetype, buftype) + return { 'treesitter', 'indent' } + end, + } + end, + }, +}