I am learning to use NeoVim and have started with the NvChad base configuration and have setup a basic python LSP in it.
I recently saw a video where a person was using a plugin called UndoTree and wanted to install it in my setup, but I cannot seem to install it.
Here is my plugins.lua file which contains all the plugins for the lazy.nvim package manager
local plugins = {
{
"williamboman/mason.nvim",
opts = {
ensure_installed = {
"black",
"pyright",
"mypy",
"ruff",
},
},
},
{
"neovim/nvim-lspconfig",
config = function ()
require "plugins.configs.lspconfig"
require "custom.configs.lspconfig"
end
},
-- Python Language Support
{
"jose-elias-alvarez/null-ls.nvim",
ft = {"python"},
opts = function ()
return require "custom.configs.null-ls"
end
},
-- Undo-Tree
-- Added this plugin
{
"mbbill/undotree",
lazy = false,
config = function ()
return require "custom.configs.undotree"
end
},
}
return plugins
This is the custom configuration file I have written for the UndoTree Plugin
local undotree = require('undotree')
undotree.setup({
float_diff = true, -- using float window previews diff, set this `true` will disable layout option
layout = "left_bottom", -- "left_bottom", "left_left_bottom"
ignore_filetype = { 'Undotree', 'UndotreeDiff', 'qf', 'TelescopePrompt', 'spectre_panel', 'tsplayground' },
window = {
winblend = 30,
},
keymaps = {
['j'] = "move_next",
['k'] = "move_prev",
['J'] = "move_change_next",
['K'] = "move_change_prev",
['<cr>'] = "action_enter",
['p'] = "enter_diffbuf",
['q'] = "quit",
},
})
This is the error message I am getting after starting nvim
This is my :Lazy profile output


Disclaimer: I am not an expert in
neovim,lua,nvchad, orvimscript.To the best of my understanding, this is not how you should configure
undotree. This plugin is entirely implemented in vimscript and therefore, you won't be able to userequireto load the module, as there is no lua module for it.Instead, you can use something like an init function to configure the plugin using vim globals. You can configure your keymaps here as well, like the below script, but it's better to just use the
mappings.luafile instead like in the example nvchad setup, which would look like:and your
plugins.luacould just look something like this:where the init file could follow a pattern like this:
I couldn't find most of the configuration you're setting in the docs so I only included the one setting I saw existed as an example. Check out the section on
undotree_WindowLayoutto understand the why it's set to2. Also, you can load the docs for this plugin by calling:help undo-treein neovim (this applies to pretty much every plugin, also you should have tab-complete in that menu so you can explore the options for a prefix, etc).Also note that I configured
undotreeto load when you callUndotreeToggle, which means you have to call that command first. This is how I would use the plugin (toggle the tree to start usingundotreeby using the<leader>jhotkey--or whatever else you choose to set this to), but you could change this behavior or disable lazy loading like you have already if you'd prefer that.If anyone else knows better or if this is the wrong approach, please let me know. But I hope this helps!