From a09c0a109676a4fc60274f1aaf57c1f78a916ce9 Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Thu, 1 May 2025 12:25:08 +0800 Subject: [PATCH] nvim: add undotree --- .../exact_components/exact_buffer/barbar.lua | 4 + .../exact_plugins/exact_components/undo.lua | 92 +++++++++++++------ .../exact_plugins/exact_ui/lualine.lua | 1 + 3 files changed, 71 insertions(+), 26 deletions(-) diff --git a/dot_config/nvim/exact_lua/exact_plugins/exact_components/exact_buffer/barbar.lua b/dot_config/nvim/exact_lua/exact_plugins/exact_components/exact_buffer/barbar.lua index a07c8a6..eae2bf1 100644 --- a/dot_config/nvim/exact_lua/exact_plugins/exact_components/exact_buffer/barbar.lua +++ b/dot_config/nvim/exact_lua/exact_plugins/exact_components/exact_buffer/barbar.lua @@ -17,6 +17,10 @@ return { -- animation = false, -- 禁用動畫效果 sidebar_filetypes = { ['neo-tree'] = {event = 'BufWipeout'}, + undotree = { + text = 'undotree', + align = 'center', -- *optionally* specify an alignment (either 'left', 'center', or 'right') + }, }, } diff --git a/dot_config/nvim/exact_lua/exact_plugins/exact_components/undo.lua b/dot_config/nvim/exact_lua/exact_plugins/exact_components/undo.lua index 658cf7c..b22b8ab 100644 --- a/dot_config/nvim/exact_lua/exact_plugins/exact_components/undo.lua +++ b/dot_config/nvim/exact_lua/exact_plugins/exact_components/undo.lua @@ -1,30 +1,70 @@ return { + { - "jiaoshijie/undotree", - dependencies = "nvim-lua/plenary.nvim", - config = true, - keys = { -- load the plugin only when using it's keybinding: - { "", "lua require('undotree').toggle()" }, - { "u", "lua require('undotree').toggle()" }, - }, - opts = { - float_diff = true, -- using float window previews diff, set this `true` will disable layout option - layout = "left_bottom", -- "left_bottom", "left_left_bottom" - position = "right", -- "left", "right", "bottom" - ignore_filetype = { 'undotree', 'undotreeDiff', 'qf', 'TelescopePrompt', 'spectre_panel', 'tsplayground' }, - window = { - winblend = 30, - }, - keymaps = { - ['j'] = "move_next", - ['k'] = "move_prev", - ['gj'] = "move2parent", - ['J'] = "move_change_next", - ['K'] = "move_change_prev", - [''] = "action_enter", - ['p'] = "enter_diffbuf", - ['q'] = "quit", - }, - }, + "mbbill/undotree", + config = function() + -- vim.g.mundo_preview_bottom = 1 + -- vim.g.mundo_auto_preview = 1 + -- vim.g.mundo_window_height = 20 + -- vim.g.mundo_window_width = 80 + -- vim.g.mundo_window_top = 0 + -- vim.g.mundo_window_left = 0 + + vim.keymap.set('n', '', vim.cmd.UndotreeToggle) + vim.g.undotree_WindowLayout = 3 + + vim.cmd([[ + function g:Undotree_CustomMap() + map J + map K + endfunction + ]]) + -- 使用 vim.cmd 執行 Vim 傳統語法 + -- vim.cmd([[ + -- nnoremap :UndotreeToggle + -- if !exists('g:undotree_WindowLayout') + -- let g:undotree_WindowLayout = 1 + -- endif + -- ]]) + + end, } + -- { + -- "mbbill/undotree", + -- dependencies = "nvim-lua/plenary.nvim", + -- config = true, + -- keys = { -- load the plugin only when using it's keybinding: + -- { "", "lua require('undotree').toggle()" }, + -- { "u", "lua require('undotree').toggle()" }, + -- }, + -- } + + -- { + -- "jiaoshijie/undotree", + -- dependencies = "nvim-lua/plenary.nvim", + -- config = true, + -- keys = { -- load the plugin only when using it's keybinding: + -- { "", "lua require('undotree').toggle()" }, + -- { "u", "lua require('undotree').toggle()" }, + -- }, + -- opts = { + -- float_diff = true, -- using float window previews diff, set this `true` will disable layout option + -- layout = "left_bottom", -- "left_bottom", "left_left_bottom" + -- position = "right", -- "left", "right", "bottom" + -- ignore_filetype = { 'undotree', 'undotreeDiff', 'qf', 'TelescopePrompt', 'spectre_panel', 'tsplayground' }, + -- window = { + -- winblend = 30, + -- }, + -- keymaps = { + -- ['j'] = "move_next", + -- ['k'] = "move_prev", + -- ['gj'] = "move2parent", + -- ['J'] = "move_change_next", + -- ['K'] = "move_change_prev", + -- [''] = "action_enter", + -- ['p'] = "enter_diffbuf", + -- ['q'] = "quit", + -- }, + -- }, + -- } } diff --git a/dot_config/nvim/exact_lua/exact_plugins/exact_ui/lualine.lua b/dot_config/nvim/exact_lua/exact_plugins/exact_ui/lualine.lua index 98f23c7..30c00fa 100644 --- a/dot_config/nvim/exact_lua/exact_plugins/exact_ui/lualine.lua +++ b/dot_config/nvim/exact_lua/exact_plugins/exact_ui/lualine.lua @@ -33,6 +33,7 @@ return { disabled_filetypes = { statusline = {}, winbar = {}, + {'undotree'} }, ignore_focus = {}, always_divide_middle = true,