LunarVim / Neovim-from-scratch

📚 A Neovim config designed from scratch to be understandable
https://www.chrisatmachine.com/
GNU General Public License v3.0
5.41k stars 1.17k forks source link

FYI some options for nvim-tree have been removed, moved, or renamed #124

Closed greyowl closed 1 year ago

greyowl commented 2 years ago

NvimTree options in question

spark-c commented 2 years ago

For reference, the related issue/commits can be found here.

spark-c commented 2 years ago

For anyone passing by with this same issue, here's a little more detail as I understand it, with a temporary fix:

NvimTree is in the process of migrating their options out of their nvim_tree.setup function. This means that rather than living within the nvim_tree.setup{ ... } block in ~/.config/nvim/lua/user/nvim-tree.lua as they currently are, they now should be declared as vim globals. You can see how this looks by checking out the Setup section of their README.

As a total vim and lua noob, I have no idea what the best way to handle this is... but if you're looking for a temporary solution like me (here are the steps but I've also included my copy at the bottom of this comment, you can just cp/paste):

Declaring values

" vimscript
let g:nvim_tree_git_hl = 1 "0 by default...

-- lua
vim.g["nvim_tree_git_hl"] = 1 --0 by default...

Table syntax:

" vimscript
{ 'README.md': 1, 'Makefile': 1, 'MAKEFILE': 1 }

--lua:
{ ["README.md"] = 1, Makefile = 1, MAKEFILE = 1 }
-- since README.md is not valid without quotes, it is placed within brackets.
-- Don't place unquoted values (Makefile) within brackets, or they will be evaluated as variables

Running vimscript commands with lua:

" vimscript
nnoremap <C-n> :NvimTreeToggle<CR>

--lua
vim.cmd "nnoremap <C-n> :NvimTreeToggle<CR>"
--or
vim.cmd [[nnoremap <C-n> :NvimTreeToggle<CR>]]

Once you make these replacements in your nvim-tree.lua file, you'll need to go down to the nvim-tree.setup block in the same file and remove references to the outdated options (view.auto_resize, etc). Once those are deleted from that block, you should be able to run nvim without the errors from nvim-tree.

Here is what I've added to my nvim-tree.lua around line 24, between nvim.g.nvim_tree_icons{...} and local status_ok, nvim_tree = pcall...

-- in ~/.config/nvim/lua/user/nvim-tree.lua

-- TEMPORARY HACK
vim.g["nvim_tree_git_hl"] = 1 --0 by default, will enable file highlight for git attributes (can be used without the icons).
vim.g["nvim_tree_highlight_opened_files"] = 1 --0 by default, will enable folder and file icon highlight for opened files/directories.
vim.g["nvim_tree_root_folder_modifier"] = ':~' --This is the default. See :help filename-modifiers for more options
vim.g["nvim_tree_add_trailing"] = 1 --0 by default, append a trailing slash to folder names
vim.g["nvim_tree_group_empty"] = 1 -- 0 by default, compact folders that only contain a single folder into one node in the file tree
vim.g["nvim_tree_icon_padding"] = ' ' --one space by default, used for rendering the space between the icon and the filename. Use with caution, it could break rendering if you set an empty string depending on your font.
vim.g["nvim_tree_symlink_arrow"] = ' >> ' -- defaults to ' ➛ '. used as a separator between symlinks' source and target.
vim.g["nvim_tree_respect_buf_cwd"] = 1 --0 by default, will change cwd of nvim-tree to that of new buffer's when opening nvim-tree.
vim.g["nvim_tree_create_in_closed_folder"] = 1 --0 by default, When creating files, sets the path of a file when cursor is on a closed folder to the parent folder when 0, and inside the folder when 1.
vim.g["nvim_tree_special_files"] = { ["README.md"] = 1, Makefile = 1, MAKEFILE = 1 } -- List of filenames that gets highlighted with NvimTreeSpecialFile
vim.g["nvim_tree_show_icons"] = {
      git = 1,
      folders = 0,
      files = 0,
      folder_arrows = 0,
    }
--If 0, do not show the icons for one of 'git' 'folder' and 'files'
--1 by default, notice that if 'files' is 1, it will only display
--if nvim-web-devicons is installed and on your runtimepath.
--if folder is 1, you can also tell folder_arrows 1 to show small arrows next to the folder icons.
--but this will not work when you set renderer.indent_markers.enable (because of UI conflict)

-- default will show icon by default if no icon is provided
-- default shows no icon by default
vim.g["nvim_tree_icons"] = {
          default = "",
          symlink = "",
          git = {
          unstaged = "✗",
          staged = "✓",
          unmerged = "",
          renamed = "➜",
          untracked = "★",
          deleted = "",
          ignored = "◌"
        },
        folder = {
          arrow_open = "",
          arrow_closed = "",
          default = "",
          open = "",
          empty = "",
          empty_open = "",
          symlink = "",
          symlink_open = "",
        }
      }

vim.cmd "nnoremap <C-n> :NvimTreeToggle<CR>"
vim.cmd "nnoremap <leader>r :NvimTreeRefresh<CR>"
vim.cmd "nnoremap <leader>n :NvimTreeFindFile<CR>"
-- More available functions:
-- NvimTreeOpen
-- NvimTreeClose
-- NvimTreeFocus
-- NvimTreeFindFileToggle
-- NvimTreeResize
-- NvimTreeCollapse
-- NvimTreeCollapseKeepBuffers

vim.cmd [[set termguicolors]] -- this variable must be enabled for colors to be applied properly

-- a list of groups can be found at `:help nvim_tree_highlight`
vim.cmd [[highlight NvimTreeFolderIcon guibg=blue]]

-- END TEMPORARY HACK

And don't forget to remove the outdated commands from the nvim_tree.setup{...} block!

JannatinNaim commented 2 years ago

For people like me that have absolutely no idea how to fix this, just freeze the plugin installation to a commit from when this configuration worked. What I did was to use this commit hash 0f0f858348aacc94f98ba32880760c5a5440b825.

THIS IS SUPER JANK AND YOU SHOULD PROBABLY NOT USE THIS CAUSE YOU'LL MISS OUT ON THE LATEST UPDATES.

  use {
    "kyazdani42/nvim-tree.lua",
    requires = {
      "kyazdani42/nvim-web-devicons"
    },
    commit = "0f0f858348aacc94f98ba32880760c5a5440b825"
  }

Use this in your plugins installer and just use the config in this repo, things should work for now.

PS: Seems like you need to remove the auto_close = true and have the following line at the end of the file.

vim.cmd [[autocmd BufEnter * ++nested if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif]]
ahauser31 commented 2 years ago

@spark-c The way I read it, they are migrating options into the setup, not out of it. The configuration as it is now committed throws the following option errors for me: quit_on_open, git_hl, disable_window_picker, root_folder_modifier, show_icons

The problem is not that those are not in the setup, but rather that they are in the wrong place (top level) or they have not been moved yet. This is my config now - based on the committed one, but doesn't throw errors with the current version of nvim-tree:

-- following options are the default
-- each of these are documented in `:help nvim-tree.OPTION_NAME`
vim.g.nvim_tree_icons = {
  default = "",
  symlink = "",
  git = {
    unstaged = "",
    staged = "S",
    unmerged = "",
    renamed = "➜",
    deleted = "",
    untracked = "U",
    ignored = "◌",
  },
  folder = {
    default = "",
    open = "",
    empty = "",
    empty_open = "",
    symlink = "",
  },
}
vim.g.nvim_tree_git_hl = 1
vim.g.nvim_tree_show_icons = {
  git = 1,
  folders = 1,
  files = 1,
  folder_arrows = 1,
}
vim.g.nvim_tree_root_folder_modifier = ':t'

local status_ok, nvim_tree = pcall(require, "nvim-tree")
if not status_ok then
  return
end

local config_status_ok, nvim_tree_config = pcall(require, "nvim-tree.config")
if not config_status_ok then
  return
end

local tree_cb = nvim_tree_config.nvim_tree_callback

nvim_tree.setup {
  disable_netrw = true,
  hijack_netrw = true,
  open_on_setup = false,
  ignore_ft_on_setup = {
    "startify",
    "dashboard",
    "alpha",
  },
  -- auto_close = true,
  open_on_tab = false,
  hijack_cursor = false,
  update_cwd = true,
  update_to_buf_dir = {
    enable = true,
    auto_open = true,
  },
  diagnostics = {
    enable = true,
    icons = {
      hint = "",
      info = "",
      warning = "",
      error = "",
    },
  },
  update_focused_file = {
    enable = true,
    update_cwd = true,
    ignore_list = {},
  },
  git = {
    enable = true,
    ignore = true,
    timeout = 500,
  },
  view = {
    width = 30,
    height = 30,
    hide_root_folder = false,
    side = "left",
    auto_resize = true,
    mappings = {
      custom_only = false,
      list = {
        { key = { "l", "<CR>", "o" }, cb = tree_cb "edit" },
        { key = "h", cb = tree_cb "close_node" },
        { key = "v", cb = tree_cb "vsplit" },
      },
    },
    number = false,
    relativenumber = false,
  },
  actions = {
    open_file = {
      quit_on_open = false,
      window_picker = {
        enable = true,
      },
    },
  },
  -- quit_on_open = 0,
  -- git_hl = 1,
  -- disable_window_picker = 0,
  -- root_folder_modifier = ":t",
  -- show_icons = {
  --   git = 1,
  --   folders = 1,
  --   files = 1,
  --   folder_arrows = 1,
  --   tree_width = 30,
  -- },
}
JannatinNaim commented 2 years ago

I followed their official documentation and redid the configuration. Here's what I had to come up with. Although, the auto-closing autocommand they provide seems to conflict with the other plugins so that doesn't work.

https://github.com/JannatinNaim/.dotfiles/blob/main/nvim/lua/plugins/config/nvim-tree.lua