diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua index c3ee00b..785a166 100644 --- a/lua/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -1,6 +1,6 @@ local treesitter = require "nvim-treesitter" -treesitter.setup {} +treesitter.install { "all" } vim.api.nvim_create_autocmd("FileType", { callback = function(args) @@ -11,8 +11,6 @@ vim.api.nvim_create_autocmd("FileType", { end vim.treesitter.start() - if vim.treesitter.get_parser(args.buf):lang() ~= "python" then - vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" - end + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" end, }) diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 48b92f4..f6a4c90 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -10,6 +10,7 @@ return { { "nvim-treesitter/nvim-treesitter", lazy = false, + branch = "main", build = ":TSUpdate", config = function() require "config.treesitter" diff --git a/lua/plugins/undo-glow.lua b/lua/plugins/undo-glow.lua new file mode 100644 index 0000000..2f5091d --- /dev/null +++ b/lua/plugins/undo-glow.lua @@ -0,0 +1,221 @@ +return { + "y3owk1n/undo-glow.nvim", + version = "*", + opts = { + animation = { + enabled = true, + duration = 300, + animation_type = "fade", + window_scoped = true, + }, + highlights = { + undo = { + hl_color = { bg = "#693232" }, -- Dark muted red + }, + redo = { + hl_color = { bg = "#2F4640" }, -- Dark muted green + }, + yank = { + hl_color = { bg = "#7A683A" }, -- Dark muted yellow + }, + paste = { + hl_color = { bg = "#325B5B" }, -- Dark muted cyan + }, + search = { + hl_color = { bg = "#5C475C" }, -- Dark muted purple + }, + comment = { + hl_color = { bg = "#7A5A3D" }, -- Dark muted orange + }, + cursor = { + hl_color = { bg = "#793D54" }, -- Dark muted pink + }, + }, + priority = 2048 * 3, + }, + keys = { + { + "u", + function() + require("undo-glow").undo() + end, + mode = "n", + desc = "Undo with highlight", + noremap = true, + }, + { + "U", + function() + require("undo-glow").redo() + end, + mode = "n", + desc = "Redo with highlight", + noremap = true, + }, + { + "p", + function() + require("undo-glow").paste_below() + end, + mode = "n", + desc = "Paste below with highlight", + noremap = true, + }, + { + "P", + function() + require("undo-glow").paste_above() + end, + mode = "n", + desc = "Paste above with highlight", + noremap = true, + }, + { + "n", + function() + require("undo-glow").search_next { + animation = { + animation_type = "strobe", + }, + } + end, + mode = "n", + desc = "Search next with highlight", + noremap = true, + }, + { + "N", + function() + require("undo-glow").search_prev { + animation = { + animation_type = "strobe", + }, + } + end, + mode = "n", + desc = "Search prev with highlight", + noremap = true, + }, + { + "*", + function() + require("undo-glow").search_star { + animation = { + animation_type = "strobe", + }, + } + end, + mode = "n", + desc = "Search star with highlight", + noremap = true, + }, + { + "#", + function() + require("undo-glow").search_hash { + animation = { + animation_type = "strobe", + }, + } + end, + mode = "n", + desc = "Search hash with highlight", + noremap = true, + }, + { + "gc", + function() + -- This is an implementation to preserve the cursor position + local pos = vim.fn.getpos "." + vim.schedule(function() + vim.fn.setpos(".", pos) + end) + return require("undo-glow").comment() + end, + mode = { "n", "x" }, + desc = "Toggle comment with highlight", + expr = true, + noremap = true, + }, + { + "gc", + function() + require("undo-glow").comment_textobject() + end, + mode = "o", + desc = "Comment textobject with highlight", + noremap = true, + }, + { + "gcc", + function() + return require("undo-glow").comment_line() + end, + mode = "n", + desc = "Toggle comment line with highlight", + expr = true, + noremap = true, + }, + }, + init = function() + vim.api.nvim_create_autocmd("TextYankPost", { + desc = "Highlight when yanking (copying) text", + callback = function() + require("undo-glow").yank() + end, + }) + + -- This only handles neovim instance and do not highlight when switching panes in tmux + vim.api.nvim_create_autocmd("CursorMoved", { + desc = "Highlight when cursor moved significantly", + callback = function() + require("undo-glow").cursor_moved { + animation = { + animation_type = "slide", + }, + } + end, + }) + + -- This will handle highlights when focus gained, including switching panes in tmux + vim.api.nvim_create_autocmd("FocusGained", { + desc = "Highlight when focus gained", + callback = function() + ---@type UndoGlow.CommandOpts + local opts = { + animation = { + animation_type = "slide", + }, + } + + opts = require("undo-glow.utils").merge_command_opts( + "UgCursor", + opts + ) + local pos = require("undo-glow.utils").get_current_cursor_row() + + require("undo-glow").highlight_region( + vim.tbl_extend("force", opts, { + s_row = pos.s_row, + s_col = pos.s_col, + e_row = pos.e_row, + e_col = pos.e_col, + force_edge = opts.force_edge == nil and true + or opts.force_edge, + }) + ) + end, + }) + + vim.api.nvim_create_autocmd("CmdlineLeave", { + desc = "Highlight when search cmdline leave", + callback = function() + require("undo-glow").search_cmd { + animation = { + animation_type = "fade", + }, + } + end, + }) + end, +}