如何在NvChad中安装Undotree?

问题描述 投票:0回答:1

我正在学习使用 NeoVim,并已从 NvChad 基本配置开始,并在其中设置了基本的 python LSP。

我最近看到一个视频,其中一个人正在使用一个名为 UndoTree 的插件,并想将其安装在我的设置中,但我似乎无法安装它。

这是我的plugins.lua 文件,其中包含lazy.nvim 包管理器的所有插件

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

这是我为 UndoTree 插件编写的自定义配置文件

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",
  },
})

这是我启动后收到的错误消息

nvim

这是我的

:Lazy profile
输出

neovim vim-plugin
1个回答
0
投票

免责声明:我不是

neovim
lua
nvchad
vimscript
方面的专家。

据我所知,这不是您应该配置的方式

undotree
。该插件完全在 vimscript 中实现,因此,您将无法使用
require
来加载模块,因为它没有 lua 模块。

相反,您可以使用类似 init 函数的东西来使用 vim 全局变量来配置插件。您也可以在这里配置键盘映射,就像下面的脚本一样,但最好只使用

mappings.lua
文件,就像在 示例 nvchad 设置中一样,它看起来像:

M.general = {
  n = {
    ["<leader>j"] = { "<cmd>UndotreeToggle<CR>", "Toggle Undotree" }
...
  },
}

你的

plugins.lua
可能看起来像这样:

...
  {
    "mbbill/undotree",
    cmd = "UndotreeToggle",
    init = function()
      require "custom.inits.undotree"
    end,
  },
...

初始化文件可以遵循这样的模式:

vim.g.undotree_WindowLayout = "left_bottom"
...

我无法找到您在 文档 中设置的大部分配置,因此我只包含了我看到的一个设置作为示例。

另请注意,我将

undotree
配置为在您调用
UndotreeToggle
时加载,这意味着您必须先调用该命令。这就是我使用插件的方式(通过使用
undotree
热键切换树以开始使用
<leader>j
- 或您选择设置的任何其他内容),但您可以更改此行为或像您一样禁用延迟加载如果您愿意的话,已经有了。

希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.