renaming: lua-tree -> nvim-tree

This commit is contained in:
kiyan42 2020-12-27 19:09:05 +01:00 committed by Kiyan
parent 2e7118ca17
commit 05711754d9
12 changed files with 189 additions and 196 deletions

View file

@ -1,4 +1,4 @@
Tree.lua is a simple tree for neovim nvim-tree.lua is a file explorer / filesystem tree view plugin for neovim
Copyright © 2019 Yazdani Kiyan Copyright © 2019 Yazdani Kiyan
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View file

@ -2,43 +2,36 @@
## Notice ## Notice
This plugin doesn't support windows. \ This plugin doesn't support windows yet. \
This plugin requires [neovim nightly](https://github.com/neovim/neovim/wiki/Installing-Neovim). \ This plugin requires [neovim nightly](https://github.com/neovim/neovim/wiki/Installing-Neovim).
You can switch to commit `afc86a9` if you use neovim 0.4.x. \
Note that the old version has less features and is much slower than the new one.
## Install ## Install
Install with [vim-plug](https://github.com/junegunn/vim-plug): Install with [vim-plug](https://github.com/junegunn/vim-plug):
```vim ```vim
" master (neovim git) " requires
Plug 'kyazdani42/nvim-web-devicons' " for file icons Plug 'kyazdani42/nvim-web-devicons' " for file icons
Plug 'kyazdani42/nvim-tree.lua' Plug 'kyazdani42/nvim-tree.lua'
" old version that runs on neovim 0.4.x
Plug 'kyazdani42/nvim-tree.lua', { 'commit': 'afc86a9' }
" for icons in old version
Plug 'ryanoasis/vim-devicons'
``` ```
## Setup ## Setup
```vim ```vim
let g:lua_tree_side = 'right' | 'left' "left by default let g:nvim_tree_side = 'right' | 'left' "left by default
let g:lua_tree_width = 40 "30 by default let g:nvim_tree_width = 40 "30 by default
let g:lua_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default let g:nvim_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default
let g:lua_tree_auto_open = 1 "0 by default, opens the tree when typing `vim $DIR` or `vim` let g:nvim_tree_auto_open = 1 "0 by default, opens the tree when typing `vim $DIR` or `vim`
let g:lua_tree_auto_close = 1 "0 by default, closes the tree when it's the last window let g:nvim_tree_auto_close = 1 "0 by default, closes the tree when it's the last window
let g:lua_tree_quit_on_open = 1 "0 by default, closes the tree when you open a file let g:nvim_tree_quit_on_open = 1 "0 by default, closes the tree when you open a file
let g:lua_tree_follow = 1 "0 by default, this option allows the cursor to be updated when entering a buffer let g:nvim_tree_follow = 1 "0 by default, this option allows the cursor to be updated when entering a buffer
let g:lua_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open let g:nvim_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open
let g:lua_tree_hide_dotfiles = 1 "0 by default, this option hides files and folders starting with a dot `.` let g:nvim_tree_hide_dotfiles = 1 "0 by default, this option hides files and folders starting with a dot `.`
let g:lua_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons). let g:nvim_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons).
let g:lua_tree_root_folder_modifier = ':~' "This is the default. See :help filename-modifiers for more options let g:nvim_tree_root_folder_modifier = ':~' "This is the default. See :help filename-modifiers for more options
let g:lua_tree_tab_open = 1 "0 by default, will open the tree when entering a new tab and the tree was previously open let g:nvim_tree_tab_open = 1 "0 by default, will open the tree when entering a new tab and the tree was previously open
let g:lua_tree_width_allow_resize = 1 "0 by default, will not resize the tree when opening a file let g:nvim_tree_width_allow_resize = 1 "0 by default, will not resize the tree when opening a file
let g:lua_tree_show_icons = { let g:nvim_tree_show_icons = {
\ 'git': 1, \ 'git': 1,
\ 'folders': 0, \ 'folders': 0,
\ 'files': 0, \ 'files': 0,
@ -50,7 +43,7 @@ let g:lua_tree_show_icons = {
" You can edit keybindings be defining this variable " You can edit keybindings be defining this variable
" You don't have to define all keys. " You don't have to define all keys.
" NOTE: the 'edit' key will wrap/unwrap a folder and open a file " NOTE: the 'edit' key will wrap/unwrap a folder and open a file
let g:lua_tree_bindings = { let g:nvim_tree_bindings = {
\ 'edit': ['<CR>', 'o'], \ 'edit': ['<CR>', 'o'],
\ 'edit_vsplit': '<C-v>', \ 'edit_vsplit': '<C-v>',
\ 'edit_split': '<C-x>', \ 'edit_split': '<C-x>',
@ -73,11 +66,11 @@ let g:lua_tree_bindings = {
" Disable default mappings by plugin " Disable default mappings by plugin
" Bindings are enable by default, disabled on any non-zero value " Bindings are enable by default, disabled on any non-zero value
" let lua_tree_disable_keybindings=1 " let nvim_tree_disable_keybindings=1
" default will show icon by default if no icon is provided " default will show icon by default if no icon is provided
" default shows no icon by default " default shows no icon by default
let g:lua_tree_icons = { let g:nvim_tree_icons = {
\ 'default': '', \ 'default': '',
\ 'symlink': '', \ 'symlink': '',
\ 'git': { \ 'git': {
@ -94,15 +87,15 @@ let g:lua_tree_icons = {
\ } \ }
\ } \ }
nnoremap <C-n> :LuaTreeToggle<CR> nnoremap <C-n> :NvimTreeToggle<CR>
nnoremap <leader>r :LuaTreeRefresh<CR> nnoremap <leader>r :NvimTreeRefresh<CR>
nnoremap <leader>n :LuaTreeFindFile<CR> nnoremap <leader>n :NvimTreeFindFile<CR>
" LuaTreeOpen and LuaTreeClose are also available if you need them " NvimTreeOpen and NvimTreeClose are also available if you need them
set termguicolors " this variable must be enabled for colors to be applied properly set termguicolors " this variable must be enabled for colors to be applied properly
" a list of groups can be found at `:help lua_tree_highlight` " a list of groups can be found at `:help nvim_tree_highlight`
highlight LuaTreeFolderIcon guibg=blue highlight NvimTreeFolderIcon guibg=blue
``` ```
## KeyBindings ## KeyBindings
@ -126,7 +119,7 @@ highlight LuaTreeFolderIcon guibg=blue
- `<C-x>` will open the file in a horizontal split - `<C-x>` will open the file in a horizontal split
- `<C-t>` will open the file in a new tab - `<C-t>` will open the file in a new tab
- `<Tab>` will open the file as a preview (keeps the cursor in the tree) - `<Tab>` will open the file as a preview (keeps the cursor in the tree)
- `I` will toggle visibility of folders hidden via |g:lua_tree_ignore| - `I` will toggle visibility of folders hidden via |g:nvim_tree_ignore|
- `H` will toggle visibility of dotfiles (files/folders starting with a `.`) - `H` will toggle visibility of dotfiles (files/folders starting with a `.`)
- `R` will refresh the tree - `R` will refresh the tree
- `gx` opens the file with the `open` command on MACOS and `xdg-open` in linux - `gx` opens the file with the `open` command on MACOS and `xdg-open` in linux

View file

@ -12,69 +12,69 @@ This file explorer doesn't work on windows and requires neovim `nightly`
============================================================================== ==============================================================================
QUICK START *nvim-tree-quickstart* QUICK START *nvim-tree-quickstart*
open the tree with :LuaTreeToggle open the tree with :NvimTreeToggle
> >
nnoremap <C-n> :LuaTreeToggle<CR> nnoremap <C-n> :NvimTreeToggle<CR>
lua require 'tree'.toggle() lua require 'nvim-tree'.toggle()
< <
============================================================================== ==============================================================================
COMMANDS *nvim-tree-commands* COMMANDS *nvim-tree-commands*
|:LuaTreeOpen| *:LuaTreeOpen* |:NvimTreeOpen| *:NvimTreeOpen*
opens the tree opens the tree
|:LuaTreeClose| *:LuaTreeClose* |:NvimTreeClose| *:NvimTreeClose*
closes the tree closes the tree
|:LuaTreeToggle| *:LuaTreeToggle* |:NvimTreeToggle| *:NvimTreeToggle*
open or close the tree open or close the tree
|:LuaTreeRefresh| *:LuaTreeRefresh* |:NvimTreeRefresh| *:NvimTreeRefresh*
refresh the tree refresh the tree
|:LuaTreeFindFile| *:LuaTreeFindFile* |:NvimTreeFindFile| *:NvimTreeFindFile*
The command will change the cursor in the tree for the current bufname. The command will change the cursor in the tree for the current bufname.
It will also open the leafs of the tree leading to the file in the buffer It will also open the leafs of the tree leading to the file in the buffer
(if you opened a file with something else than the LuaTree, like `fzf` or (if you opened a file with something else than the NvimTree, like `fzf` or
`:split`) `:split`)
|:LuaTreeClipboard| *:LuaTreeClipboard* |:NvimTreeClipboard| *:NvimTreeClipboard*
Print clipboard content for both cut and copy Print clipboard content for both cut and copy
============================================================================== ==============================================================================
OPTIONS *nvim-tree-options* OPTIONS *nvim-tree-options*
|g:lua_tree_width| *g:lua_tree_width* |g:nvim_tree_width| *g:nvim_tree_width*
width of the window (default to 30) width of the window (default to 30)
|g:lua_tree_side| *g:lua_tree_side* |g:nvim_tree_side| *g:nvim_tree_side*
where the window will open (default to 'left') where the window will open (default to 'left')
- 'left' or 'right' - 'left' or 'right'
|g:lua_tree_ignore| *g:lua_tree_ignore* |g:nvim_tree_ignore| *g:nvim_tree_ignore*
An array of strings that the tree won't load and display. An array of strings that the tree won't load and display.
useful to hide large data/cache folders. useful to hide large data/cache folders.
> >
example: let g:lua_tree_ignore = [ '.git', 'node_modules' ] example: let g:nvim_tree_ignore = [ '.git', 'node_modules' ]
|g:lua_tree_show_icons| *g:lua_tree_show_icons* |g:nvim_tree_show_icons| *g:nvim_tree_show_icons*
Dictionnary, if your terminal or font doesn't support certain unicode Dictionnary, if your terminal or font doesn't support certain unicode
character, the tree UI might be messed up. The following configuration character, the tree UI might be messed up. The following configuration
can disable icons per type: can disable icons per type:
> >
let g:lua_tree_show_icons = { let g:nvim_tree_show_icons = {
\ 'git': 1, \ 'git': 1,
\ 'folders': 1, \ 'folders': 1,
\ 'icons': 1 \ 'icons': 1
@ -85,7 +85,7 @@ to render the icons. The `icons` key can only work if `nvim-web-devicons`
is installed and in your |runtimepath| is installed and in your |runtimepath|
(https://github.com/kyazdani42/nvim-web-devicons) (https://github.com/kyazdani42/nvim-web-devicons)
|g:lua_tree_icons| *g:lua_tree_icons* |g:nvim_tree_icons| *g:nvim_tree_icons*
You can set icons for: You can set icons for:
@ -94,7 +94,7 @@ You can set icons for:
or if you are not using icons. or if you are not using icons.
- Symlinks. If an icon is not provided, the `default` icon is used. - Symlinks. If an icon is not provided, the `default` icon is used.
> >
let g:lua_tree_icons = { let g:nvim_tree_icons = {
\ 'default': '', \ 'default': '',
\ 'symlink': '', \ 'symlink': '',
\ 'git': { \ 'git': {
@ -111,66 +111,66 @@ You can set icons for:
\ } \ }
\ } \ }
|g:lua_tree_git_hl| *g:lua_tree_git_hl* |g:nvim_tree_git_hl| *g:nvim_tree_git_hl*
You can enable file highlight for git attributes by setting this property. You can enable file highlight for git attributes by setting this property.
This can be used with or without the icons. This can be used with or without the icons.
|g:lua_tree_follow| *g:lua_tree_follow* |g:nvim_tree_follow| *g:nvim_tree_follow*
Can be `0` or `1`. When `1`, will update the cursor to update to the correct Can be `0` or `1`. When `1`, will update the cursor to update to the correct
location in the tree on |BufEnter|. location in the tree on |BufEnter|.
Default is 0 Default is 0
|g:lua_tree_auto_open| *g:lua_tree_auto_open* |g:nvim_tree_auto_open| *g:nvim_tree_auto_open*
Can be `0` or `1`. When `1`, will open the tree when the package is loaded. Can be `0` or `1`. When `1`, will open the tree when the package is loaded.
It's not relying on VimEnter anymore. It's not relying on VimEnter anymore.
Default is 0 Default is 0
|g:lua_tree_auto_close| *g:lua_tree_auto_close* |g:nvim_tree_auto_close| *g:nvim_tree_auto_close*
Can be `0` or `1`. When `1`, will bind |BufEnter| to automatically Can be `0` or `1`. When `1`, will bind |BufEnter| to automatically
close the tree if it's the last window. close the tree if it's the last window.
Default is 0 Default is 0
|g:lua_tree_quit_on_open| *g:lua_tree_quit_on_open* |g:nvim_tree_quit_on_open| *g:nvim_tree_quit_on_open*
Can be `0` or `1`. When `1`, will close the tree when a file is opened. Can be `0` or `1`. When `1`, will close the tree when a file is opened.
Applies to: `preview`, `edit`, `edit_vsplit`, `edit_split`, `edit_tab`. Applies to: `preview`, `edit`, `edit_vsplit`, `edit_split`, `edit_tab`.
Default is 0 Default is 0
|g:lua_tree_disable_keybindings| *g:lua_tree_disable_keybindings* |g:nvim_tree_disable_keybindings| *g:nvim_tree_disable_keybindings*
Can be `0` or `1`. When `1`, will disable all keybindings by the plugin. Can be `0` or `1`. When `1`, will disable all keybindings by the plugin.
|g:lua_tree_bindings| as well as default bindings will not take effect. |g:nvim_tree_bindings| as well as default bindings will not take effect.
Default is 0 Default is 0
|g:lua_tree_indent_markers| *g:lua_tree_indent_markers* |g:nvim_tree_indent_markers| *g:nvim_tree_indent_markers*
Can be `0` or `1`. When `1`, will display indent markers when folders are open Can be `0` or `1`. When `1`, will display indent markers when folders are open
Default is 0 Default is 0
|g:lua_tree_hide_dotfiles| *g:lua_tree_hide_dotfiles* |g:nvim_tree_hide_dotfiles| *g:nvim_tree_hide_dotfiles*
Can be `0` or `1`. When `1`, will hide dotfiles, files or folders which start Can be `0` or `1`. When `1`, will hide dotfiles, files or folders which start
with the `.` character. with the `.` character.
Default is 0 Default is 0
|g:lua_tree_root_folder_modifier| *g:lua_tree_root_folder_modifier* |g:nvim_tree_root_folder_modifier| *g:nvim_tree_root_folder_modifier*
In what format to show root folder. See `:help filename-modifiers` for In what format to show root folder. See `:help filename-modifiers` for
available options. available options.
Default is `:~` Default is `:~`
|g:lua_tree_tab_open| *g:lua_tree_tab_open* |g:nvim_tree_tab_open| *g:nvim_tree_tab_open*
Can be 0 or 1. When 1, will open the tree when entering a new tab if the Can be 0 or 1. When 1, will open the tree when entering a new tab if the
tree was previously open. tree was previously open.
Default is 0 Default is 0
|g:lua_tree_width_allow_resize| *g:lua_tree_width_allow_resize* |g:nvim_tree_width_allow_resize| *g:nvim_tree_width_allow_resize*
Can be 0 or 1. When 1, it will not resize the tree to it's original width Can be 0 or 1. When 1, it will not resize the tree to it's original width
when opening a new file. when opening a new file.
@ -203,7 +203,7 @@ INFORMATIONS *nvim-tree-info*
- '<C-x>' will open the file in a horizontal split - '<C-x>' will open the file in a horizontal split
- '<C-t>' will open the file in a new tab - '<C-t>' will open the file in a new tab
- '<Tab>' will open the file as a preview (keeps the cursor in the tree) - '<Tab>' will open the file as a preview (keeps the cursor in the tree)
- 'I' will toggle visibility of folders hidden via |g:lua_tree_ignore| - 'I' will toggle visibility of folders hidden via |g:nvim_tree_ignore|
- 'R' will refresh the tree - 'R' will refresh the tree
- 'gx' opens the file with the `open` command on macos and `xdg-open` - 'gx' opens the file with the `open` command on macos and `xdg-open`
on linux. on linux.
@ -211,12 +211,12 @@ on linux.
- Double left click acts like '<CR>' - Double left click acts like '<CR>'
- Double right click acts like '<C-]>' - Double right click acts like '<C-]>'
|g:lua_tree_bindings| *g:lua_tree_bindings* |g:nvim_tree_bindings| *g:nvim_tree_bindings*
you can change default keybindings by defining this variable. you can change default keybindings by defining this variable.
default keybindings will be applied to undefined keys. default keybindings will be applied to undefined keys.
> >
let g:lua_tree_bindings = { let g:nvim_tree_bindings = {
\ edit: ['<cr>', 'o'], // Multiple keys provided via list \ edit: ['<cr>', 'o'], // Multiple keys provided via list
\ edit_vsplit: '<c-v>', \ edit_vsplit: '<c-v>',
\ edit_split: '<c-x>', \ edit_split: '<c-x>',
@ -259,50 +259,50 @@ Mouse support defined in |KeyBindings|
============================================================================== ==============================================================================
HIGHLIGHT GROUPS *nvim-tree-highlight* HIGHLIGHT GROUPS *nvim-tree-highlight*
|lua_tree_highlight| *lua_tree_highlight* |nvim_tree_highlight| *nvim_tree_highlight*
All the following highlight groups can be configured by hand. It is not All the following highlight groups can be configured by hand. It is not
advised to colorize the background of these groups. advised to colorize the background of these groups.
Example (in your `init.vim`): Example (in your `init.vim`):
> >
highlight LuaTreeSymlink guifg=blue gui=bold,underline highlight NvimTreeSymlink guifg=blue gui=bold,underline
< <
You should have 'termguicolors' enabled, otherwise, colors will not be You should have 'termguicolors' enabled, otherwise, colors will not be
applied. applied.
LuaTreeSymlink NvimTreeSymlink
LuaTreeFolderName NvimTreeFolderName
LuaTreeRootFolder NvimTreeRootFolder
LuaTreeFolderIcon NvimTreeFolderIcon
LuaTreeExecFile NvimTreeExecFile
LuaTreeSpecialFile NvimTreeSpecialFile
LuaTreeImageFile NvimTreeImageFile
LuaTreeMarkdownFile NvimTreeMarkdownFile
LuaTreeIndentMarker NvimTreeIndentMarker
LuaTreeLicenseIcon NvimTreeLicenseIcon
LuaTreeYamlIcon NvimTreeYamlIcon
LuaTreeTomlIcon NvimTreeTomlIcon
LuaTreeGitignoreIcon NvimTreeGitignoreIcon
LuaTreeJsonIcon NvimTreeJsonIcon
LuaTreeLuaIcon NvimTreeLuaIcon
LuaTreePythonIcon NvimTreePythonIcon
LuaTreeShellIcon NvimTreeShellIcon
LuaTreeJavascriptIcon NvimTreeJavascriptIcon
LuaTreeCIcon NvimTreeCIcon
LuaTreeReactIcon NvimTreeReactIcon
LuaTreeHtmlIcon NvimTreeHtmlIcon
LuaTreeRustIcon NvimTreeRustIcon
LuaTreeVimIcon NvimTreeVimIcon
LuaTreeTypescriptIcon NvimTreeTypescriptIcon
LuaTreeGitDirty NvimTreeGitDirty
LuaTreeGitStaged NvimTreeGitStaged
LuaTreeGitMerge NvimTreeGitMerge
LuaTreeGitRenamed NvimTreeGitRenamed
LuaTreeGitNew NvimTreeGitNew
There are also links to normal bindings to style the tree itself. There are also links to normal bindings to style the tree itself.
@ -315,10 +315,10 @@ CursorColumn
There are also links for file highlight with git properties There are also links for file highlight with git properties
These all link to there Git equivalent These all link to there Git equivalent
LuaTreeFileDirty NvimTreeFileDirty
LuaTreeFileStaged NvimTreeFileStaged
LuaTreeFileMerge NvimTreeFileMerge
LuaTreeFileNew NvimTreeFileNew
LuaTreeFileRenamed NvimTreeFileRenamed
vim:tw=78:ts=8:noet:ft=help:norl: vim:tw=78:ts=8:noet:ft=help:norl:

View file

@ -56,12 +56,12 @@ local function get_links()
CursorLine = 'CursorLine', CursorLine = 'CursorLine',
VertSplit = 'VertSplit', VertSplit = 'VertSplit',
CursorColumn = 'CursorColumn', CursorColumn = 'CursorColumn',
FileDirty = 'LuaTreeGitDirty', FileDirty = 'NvimTreeGitDirty',
FileNew = 'LuaTreeGitNew', FileNew = 'NvimTreeGitNew',
FileRenamed = 'LuaTreeGitRenamed', FileRenamed = 'NvimTreeGitRenamed',
FileMerge = 'LuaTreeGitMerge', FileMerge = 'NvimTreeGitMerge',
FileStaged = 'LuaTreeGitStaged', FileStaged = 'NvimTreeGitStaged',
FileDeleted = 'LuaTreeGitDeleted', FileDeleted = 'NvimTreeGitDeleted',
} }
end end
@ -72,12 +72,12 @@ function M.setup()
local higlight_groups = get_hl_groups() local higlight_groups = get_hl_groups()
for k, d in pairs(higlight_groups) do for k, d in pairs(higlight_groups) do
local gui = d.gui or 'NONE' local gui = d.gui or 'NONE'
api.nvim_command('hi def LuaTree'..k..' gui='..gui..' guifg='..d.fg) api.nvim_command('hi def NvimTree'..k..' gui='..gui..' guifg='..d.fg)
end end
local links = get_links() local links = get_links()
for k, d in pairs(links) do for k, d in pairs(links) do
api.nvim_command('hi def link LuaTree'..k..' '..d) api.nvim_command('hi def link NvimTree'..k..' '..d)
end end
end end

View file

@ -1,7 +1,7 @@
local M = {} local M = {}
function M.get_icon_state() function M.get_icon_state()
local show_icons = vim.g.lua_tree_show_icons or { git = 1, folders = 1, files = 1 } local show_icons = vim.g.nvim_tree_show_icons or { git = 1, folders = 1, files = 1 }
local icons = { local icons = {
default = "", default = "",
symlink = "", symlink = "",
@ -20,7 +20,7 @@ function M.get_icon_state()
} }
} }
local user_icons = vim.g.lua_tree_icons local user_icons = vim.g.nvim_tree_icons
if user_icons then if user_icons then
if user_icons.default then if user_icons.default then
icons.default = user_icons.default icons.default = user_icons.default
@ -50,7 +50,7 @@ function M.get_icon_state()
end end
function M.get_bindings() function M.get_bindings()
local keybindings = vim.g.lua_tree_bindings or {} local keybindings = vim.g.nvim_tree_bindings or {}
return { return {
edit = keybindings.edit or {'<CR>', 'o'}, edit = keybindings.edit or {'<CR>', 'o'},
edit_vsplit = keybindings.edit_vsplit or '<C-v>', edit_vsplit = keybindings.edit_vsplit or '<C-v>',
@ -75,8 +75,8 @@ end
function M.window_options() function M.window_options()
local opts = {} local opts = {}
opts.winhl = 'EndOfBuffer:LuaTreeEndOfBuffer,Normal:LuaTreeNormal,CursorLine:LuaTreeCursorLine,VertSplit:LuaTreeVertSplit' opts.winhl = 'EndOfBuffer:NvimTreeEndOfBuffer,Normal:NvimTreeNormal,CursorLine:NvimTreeCursorLine,VertSplit:NvimTreeVertSplit'
if vim.g.lua_tree_side == 'right' then if vim.g.nvim_tree_side == 'right' then
opts.side = 'L' opts.side = 'L'
opts.open_command = 'h' opts.open_command = 'h'
opts.preview_command = 'l' opts.preview_command = 'l'

View file

@ -13,7 +13,7 @@ local function clear_prompt()
end end
local function refresh_tree() local function refresh_tree()
vim.api.nvim_command(":LuaTreeRefresh") vim.api.nvim_command(":NvimTreeRefresh")
end end
local function create_file(file) local function create_file(file)

View file

@ -14,10 +14,10 @@ local M = {}
M.Tree = { M.Tree = {
entries = {}, entries = {},
buf_name = 'LuaTree', buf_name = 'NvimTree',
cwd = nil, cwd = nil,
win_width = vim.g.lua_tree_width or 30, win_width = vim.g.nvim_tree_width or 30,
win_width_allow_resize = vim.g.lua_tree_width_allow_resize, win_width_allow_resize = vim.g.nvim_tree_width_allow_resize,
loaded = false, loaded = false,
bufnr = nil, bufnr = nil,
winnr = function() winnr = function()
@ -125,7 +125,7 @@ function M.refresh_tree()
-- if stat.mtime.sec ~= M.Tree.last_modified then -- if stat.mtime.sec ~= M.Tree.last_modified then
refresh_nodes(M.Tree) refresh_nodes(M.Tree)
-- end -- end
if config.get_icon_state().show_git_icon or vim.g.lua_tree_git_hl then if config.get_icon_state().show_git_icon or vim.g.nvim_tree_git_hl then
git.reload_roots() git.reload_roots()
refresh_git(M.Tree) refresh_git(M.Tree)
end end
@ -206,7 +206,7 @@ function M.open_file(mode, filename)
api.nvim_command('vertical resize '..M.Tree.win_width) api.nvim_command('vertical resize '..M.Tree.win_width)
M.win_focus(cur_win) M.win_focus(cur_win)
end end
if vim.g.lua_tree_quit_on_open == 1 and mode ~= 'preview' then if vim.g.nvim_tree_quit_on_open == 1 and mode ~= 'preview' then
M.close() M.close()
end end
end end
@ -218,13 +218,13 @@ function M.change_dir(foldername)
end end
local function set_mapping(buf, key, fn) local function set_mapping(buf, key, fn)
api.nvim_buf_set_keymap(buf, 'n', key, ':lua require"tree".'..fn..'<cr>', { api.nvim_buf_set_keymap(buf, 'n', key, ':lua require"nvim-tree".'..fn..'<cr>', {
nowait = true, noremap = true, silent = true nowait = true, noremap = true, silent = true
}) })
end end
local function set_mappings() local function set_mappings()
if vim.g.lua_tree_disable_keybindings == 1 then if vim.g.nvim_tree_disable_keybindings == 1 then
return return
end end

View file

@ -7,7 +7,7 @@ local luv = vim.loop
local M = { local M = {
show_ignored = false, show_ignored = false,
show_dotfiles = vim.g.lua_tree_hide_dotfiles ~= 1, show_dotfiles = vim.g.nvim_tree_hide_dotfiles ~= 1,
} }
local path_to_matching_str = require'lib.utils'.path_to_matching_str local path_to_matching_str = require'lib.utils'.path_to_matching_str
@ -66,8 +66,8 @@ end
local function gen_ignore_check() local function gen_ignore_check()
local ignore_list = {} local ignore_list = {}
if vim.g.lua_tree_ignore and #vim.g.lua_tree_ignore > 0 then if vim.g.nvim_tree_ignore and #vim.g.nvim_tree_ignore > 0 then
for _, entry in pairs(vim.g.lua_tree_ignore) do for _, entry in pairs(vim.g.nvim_tree_ignore) do
ignore_list[entry] = true ignore_list[entry] = true
end end
end end
@ -211,7 +211,7 @@ function M.populate(entries, cwd)
table.insert(entries, file) table.insert(entries, file)
end end
if (not icon_config.show_git_icon) and vim.g.lua_tree_git_hl ~= 1 then if (not icon_config.show_git_icon) and vim.g.nvim_tree_git_hl ~= 1 then
return return
end end

View file

@ -6,7 +6,7 @@ local api = vim.api
local lines = {} local lines = {}
local hl = {} local hl = {}
local index = 0 local index = 0
local namespace_id = api.nvim_create_namespace('LuaTreeHighlights') local namespace_id = api.nvim_create_namespace('NvimTreeHighlights')
local icon_state = config.get_icon_state() local icon_state = config.get_icon_state()
@ -29,7 +29,7 @@ if icon_state.show_folder_icon then
end end
set_folder_hl = function(line, depth, icon_len, name_len, hl_group) set_folder_hl = function(line, depth, icon_len, name_len, hl_group)
table.insert(hl, {hl_group, line, depth+icon_len, depth+icon_len+name_len}) table.insert(hl, {hl_group, line, depth+icon_len, depth+icon_len+name_len})
table.insert(hl, {'LuaTreeFolderIcon', line, depth, depth+icon_len}) table.insert(hl, {'NvimTreeFolderIcon', line, depth, depth+icon_len})
end end
end end
@ -69,38 +69,38 @@ end
local get_git_icons = function() return "" end local get_git_icons = function() return "" end
local get_git_hl = function() return end local get_git_hl = function() return end
if vim.g.lua_tree_git_hl == 1 then if vim.g.nvim_tree_git_hl == 1 then
local git_hl = { local git_hl = {
["M "] = { { hl = "LuaTreeFileStaged" } }, ["M "] = { { hl = "NvimTreeFileStaged" } },
[" M"] = { { hl = "LuaTreeFileDirty" } }, [" M"] = { { hl = "NvimTreeFileDirty" } },
["MM"] = { ["MM"] = {
{ hl = "LuaTreeFileStaged" }, { hl = "NvimTreeFileStaged" },
{ hl = "LuaTreeFileDirty" } { hl = "NvimTreeFileDirty" }
}, },
["A "] = { ["A "] = {
{ hl = "LuaTreeFileStaged" }, { hl = "NvimTreeFileStaged" },
{ hl = "LuaTreeFileNew" } { hl = "NvimTreeFileNew" }
}, },
["AD"] = { ["AD"] = {
{ hl = "LuaTreeFileStaged" }, { hl = "NvimTreeFileStaged" },
{ hl = "LuaTreeFileDeleted" } { hl = "NvimTreeFileDeleted" }
}, },
["AM"] = { ["AM"] = {
{ hl = "LuaTreeFileStaged" }, { hl = "NvimTreeFileStaged" },
{ hl = "LuaTreeFileNew" }, { hl = "NvimTreeFileNew" },
{ hl = "LuaTreeFileDirty" } { hl = "NvimTreeFileDirty" }
}, },
["??"] = { { hl = "LuaTreeFileNew" } }, ["??"] = { { hl = "NvimTreeFileNew" } },
["R "] = { { hl = "LuaTreeFileRenamed" } }, ["R "] = { { hl = "NvimTreeFileRenamed" } },
["UU"] = { { hl = "LuaTreeFileMerge" } }, ["UU"] = { { hl = "NvimTreeFileMerge" } },
[" D"] = { { hl = "LuaTreeFileDeleted" } }, [" D"] = { { hl = "NvimTreeFileDeleted" } },
["D "] = { ["D "] = {
{ hl = "LuaTreeFileDeleted" }, { hl = "NvimTreeFileDeleted" },
{ hl = "LuaTreeFileStaged" } { hl = "NvimTreeFileStaged" }
}, },
[" A"] = { { hl = "none" } }, [" A"] = { { hl = "none" } },
["RM"] = { { hl = "LuaTreeFileRenamed" } }, ["RM"] = { { hl = "NvimTreeFileRenamed" } },
dirty = { { hl = "LuaTreeFileDirty" } }, dirty = { { hl = "NvimTreeFileDirty" } },
} }
get_git_hl = function(node) get_git_hl = function(node)
local git_status = node.git_status local git_status = node.git_status
@ -121,33 +121,33 @@ end
if icon_state.show_git_icon then if icon_state.show_git_icon then
local git_icon_state = { local git_icon_state = {
["M "] = { { icon = icon_state.icons.git_icons.staged, hl = "LuaTreeGitStaged" } }, ["M "] = { { icon = icon_state.icons.git_icons.staged, hl = "NvimTreeGitStaged" } },
[" M"] = { { icon = icon_state.icons.git_icons.unstaged, hl = "LuaTreeGitDirty" } }, [" M"] = { { icon = icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" } },
["MM"] = { ["MM"] = {
{ icon = icon_state.icons.git_icons.staged, hl = "LuaTreeGitStaged" }, { icon = icon_state.icons.git_icons.staged, hl = "NvimTreeGitStaged" },
{ icon = icon_state.icons.git_icons.unstaged, hl = "LuaTreeGitDirty" } { icon = icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" }
}, },
["A "] = { ["A "] = {
{ icon = icon_state.icons.git_icons.staged, hl = "LuaTreeGitStaged" }, { icon = icon_state.icons.git_icons.staged, hl = "NvimTreeGitStaged" },
{ icon = icon_state.icons.git_icons.untracked, hl = "LuaTreeGitNew" } { icon = icon_state.icons.git_icons.untracked, hl = "NvimTreeGitNew" }
}, },
[" A"] = { [" A"] = {
{ icon = icon_state.icons.git_icons.untracked, hl = "LuaTreeGitNew" }, { icon = icon_state.icons.git_icons.untracked, hl = "NvimTreeGitNew" },
}, },
["AM"] = { ["AM"] = {
{ icon = icon_state.icons.git_icons.staged, hl = "LuaTreeGitStaged" }, { icon = icon_state.icons.git_icons.staged, hl = "NvimTreeGitStaged" },
{ icon = icon_state.icons.git_icons.untracked, hl = "LuaTreeGitNew" }, { icon = icon_state.icons.git_icons.untracked, hl = "NvimTreeGitNew" },
{ icon = icon_state.icons.git_icons.unstaged, hl = "LuaTreeGitDirty" } { icon = icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" }
}, },
["??"] = { { icon = icon_state.icons.git_icons.untracked, hl = "LuaTreeGitDirty" } }, ["??"] = { { icon = icon_state.icons.git_icons.untracked, hl = "NvimTreeGitDirty" } },
["R "] = { { icon = icon_state.icons.git_icons.renamed, hl = "LuaTreeGitRenamed" } }, ["R "] = { { icon = icon_state.icons.git_icons.renamed, hl = "NvimTreeGitRenamed" } },
["RM"] = { ["RM"] = {
{ icon = icon_state.icons.git_icons.unstaged, hl = "LuaTreeGitDirty" }, { icon = icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" },
{ icon = icon_state.icons.git_icons.renamed, hl = "LuaTreeGitRenamed" }, { icon = icon_state.icons.git_icons.renamed, hl = "NvimTreeGitRenamed" },
}, },
["UU"] = { { icon = icon_state.icons.git_icons.unmerged, hl = "LuaTreeGitMerge" } }, ["UU"] = { { icon = icon_state.icons.git_icons.unmerged, hl = "NvimTreeGitMerge" } },
[" D"] = { { icon = icon_state.icons.git_icons.deleted, hl = "LuaTreeGitDeleted" } }, [" D"] = { { icon = icon_state.icons.git_icons.deleted, hl = "NvimTreeGitDeleted" } },
dirty = { { icon = icon_state.icons.git_icons.unstaged, hl = "LuaTreeGitDirty" } }, dirty = { { icon = icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" } },
} }
get_git_icons = function(node, line, depth, icon_len) get_git_icons = function(node, line, depth, icon_len)
@ -157,7 +157,7 @@ if icon_state.show_git_icon then
local icon = "" local icon = ""
local icons = git_icon_state[git_status] local icons = git_icon_state[git_status]
if not icons then if not icons then
if vim.g.lua_tree_git_hl ~= 1 then if vim.g.nvim_tree_git_hl ~= 1 then
utils.echo_warning('Unrecognized git state "'..git_status..'". Please open up an issue on https://github.com/kyazdani42/nvim-tree.lua/issues with this message.') utils.echo_warning('Unrecognized git state "'..git_status..'". Please open up an issue on https://github.com/kyazdani42/nvim-tree.lua/issues with this message.')
end end
icons = git_icon_state.dirty icons = git_icon_state.dirty
@ -175,7 +175,7 @@ local get_padding = function(depth)
return string.rep(' ', depth) return string.rep(' ', depth)
end end
if vim.g.lua_tree_indent_markers == 1 then if vim.g.nvim_tree_indent_markers == 1 then
get_padding = function(depth, idx, tree, _, markers) get_padding = function(depth, idx, tree, _, markers)
local padding = "" local padding = ""
if depth ~= 0 then if depth ~= 0 then
@ -209,13 +209,13 @@ local special = {
["readme.md"] = true, ["readme.md"] = true,
} }
local root_folder_modifier = vim.g.lua_tree_root_folder_modifier or ':~' local root_folder_modifier = vim.g.nvim_tree_root_folder_modifier or ':~'
local function update_draw_data(tree, depth, markers) local function update_draw_data(tree, depth, markers)
if tree.cwd and tree.cwd ~= '/' then if tree.cwd and tree.cwd ~= '/' then
local root_name = vim.fn.fnamemodify(tree.cwd, root_folder_modifier):gsub('/$', '').."/.." local root_name = vim.fn.fnamemodify(tree.cwd, root_folder_modifier):gsub('/$', '').."/.."
table.insert(lines, root_name) table.insert(lines, root_name)
table.insert(hl, {'LuaTreeRootFolder', index, 0, string.len(root_name)}) table.insert(hl, {'NvimTreeRootFolder', index, 0, string.len(root_name)})
index = 1 index = 1
end end
@ -223,7 +223,7 @@ local function update_draw_data(tree, depth, markers)
local padding = get_padding(depth, idx, tree, node, markers) local padding = get_padding(depth, idx, tree, node, markers)
local offset = string.len(padding) local offset = string.len(padding)
if depth > 0 then if depth > 0 then
table.insert(hl, { 'LuaTreeIndentMarker', index, 0, offset }) table.insert(hl, { 'NvimTreeIndentMarker', index, 0, offset })
end end
local git_hl = get_git_hl(node) local git_hl = get_git_hl(node)
@ -232,7 +232,7 @@ local function update_draw_data(tree, depth, markers)
local icon = get_folder_icon(node.open, node.link_to ~= nil) local icon = get_folder_icon(node.open, node.link_to ~= nil)
local git_icon = get_git_icons(node, index, offset, #icon+1) or "" local git_icon = get_git_icons(node, index, offset, #icon+1) or ""
-- INFO: this is mandatory in order to keep gui attributes (bold/italics) -- INFO: this is mandatory in order to keep gui attributes (bold/italics)
set_folder_hl(index, offset, #icon, #node.name+#git_icon, 'LuaTreeFolderName') set_folder_hl(index, offset, #icon, #node.name+#git_icon, 'NvimTreeFolderName')
if git_hl then if git_hl then
set_folder_hl(index, offset, #icon, #node.name+#git_icon, git_hl) set_folder_hl(index, offset, #icon, #node.name+#git_icon, git_hl)
end end
@ -245,7 +245,7 @@ local function update_draw_data(tree, depth, markers)
end end
elseif node.link_to then elseif node.link_to then
local icon = get_symlink_icon() local icon = get_symlink_icon()
local link_hl = git_hl or 'LuaTreeSymlink' local link_hl = git_hl or 'NvimTreeSymlink'
table.insert(hl, { link_hl, index, offset, -1 }) table.insert(hl, { link_hl, index, offset, -1 })
table.insert(lines, padding..icon..node.name..""..node.link_to) table.insert(lines, padding..icon..node.name..""..node.link_to)
index = index + 1 index = index + 1
@ -256,7 +256,7 @@ local function update_draw_data(tree, depth, markers)
if special[node.name] then if special[node.name] then
icon = get_special_icon() icon = get_special_icon()
git_icons = get_git_icons(node, index, offset, 0) git_icons = get_git_icons(node, index, offset, 0)
table.insert(hl, {'LuaTreeSpecialFile', index, offset+#git_icons, -1}) table.insert(hl, {'NvimTreeSpecialFile', index, offset+#git_icons, -1})
else else
icon = get_file_icon(node.name, node.extension, index, offset) icon = get_file_icon(node.name, node.extension, index, offset)
git_icons = get_git_icons(node, index, offset, #icon) git_icons = get_git_icons(node, index, offset, #icon)
@ -264,9 +264,9 @@ local function update_draw_data(tree, depth, markers)
table.insert(lines, padding..icon..git_icons..node.name) table.insert(lines, padding..icon..git_icons..node.name)
if node.executable then if node.executable then
table.insert(hl, {'LuaTreeExecFile', index, offset+#icon+#git_icons, -1 }) table.insert(hl, {'NvimTreeExecFile', index, offset+#icon+#git_icons, -1 })
elseif picture[node.extension] then elseif picture[node.extension] then
table.insert(hl, {'LuaTreeImageFile', index, offset+#icon+#git_icons, -1 }) table.insert(hl, {'NvimTreeImageFile', index, offset+#icon+#git_icons, -1 })
end end
if git_hl then if git_hl then

View file

@ -7,7 +7,7 @@ end
function M.echo_warning(msg) function M.echo_warning(msg)
api.nvim_command('echohl WarningMsg') api.nvim_command('echohl WarningMsg')
api.nvim_command("echom '[LuaTree] "..msg:gsub("'", "''").."'") api.nvim_command("echom '[NvimTree] "..msg:gsub("'", "''").."'")
api.nvim_command('echohl None') api.nvim_command('echohl None')
end end

View file

@ -13,7 +13,7 @@ function M.toggle()
if lib.win_open() then if lib.win_open() then
lib.close() lib.close()
else else
if vim.g.lua_tree_follow == 1 then if vim.g.nvim_tree_follow == 1 then
vim.schedule(function() M.find_file(true) end) vim.schedule(function() M.find_file(true) end)
else else
vim.schedule(lib.open) vim.schedule(lib.open)
@ -122,7 +122,7 @@ function M.on_enter()
if is_dir then if is_dir then
api.nvim_command('cd '..bufname) api.nvim_command('cd '..bufname)
end end
local should_open = vim.g.lua_tree_auto_open == 1 and (bufname == '' or is_dir) local should_open = vim.g.nvim_tree_auto_open == 1 and (bufname == '' or is_dir)
colors.setup() colors.setup()
lib.init(should_open, should_open) lib.init(should_open, should_open)
end end
@ -177,7 +177,7 @@ end
function M.buf_enter() function M.buf_enter()
update_root_dir() update_root_dir()
if vim.g.lua_tree_follow == 1 then if vim.g.nvim_tree_follow == 1 then
M.find_file(false) M.find_file(false)
end end
end end

View file

@ -6,27 +6,27 @@ set cpo&vim
let g:loaded_netrw = 1 let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1 let g:loaded_netrwPlugin = 1
hi def link LuaTreePopup Normal hi def link NvimTreePopup Normal
augroup LuaTree augroup NvimTree
au BufWritePost * lua require'tree'.refresh() au BufWritePost * lua require'nvim-tree'.refresh()
au BufEnter * lua require'tree'.buf_enter() au BufEnter * lua require'nvim-tree'.buf_enter()
if get(g:, 'lua_tree_auto_close') == 1 if get(g:, 'lua_tree_auto_close') == 1
au WinClosed * lua require'tree'.on_leave() au WinClosed * lua require'nvim-tree'.on_leave()
endif endif
au ColorScheme * lua require'tree'.reset_highlight() au ColorScheme * lua require'nvim-tree'.reset_highlight()
au User FugitiveChanged lua require'tree'.refresh() au User FugitiveChanged lua require'nvim-tree'.refresh()
if get(g:, 'lua_tree_tab_open') == 1 if get(g:, 'lua_tree_tab_open') == 1
au TabEnter * lua require'tree'.tab_change() au TabEnter * lua require'nvim-tree'.tab_change()
endif endif
augroup end augroup end
command! LuaTreeOpen lua require'tree'.open() command! NvimTreeOpen lua require'nvim-tree'.open()
command! LuaTreeClose lua require'tree'.close() command! NvimTreeClose lua require'nvim-tree'.close()
command! LuaTreeToggle lua require'tree'.toggle() command! NvimTreeToggle lua require'nvim-tree'.toggle()
command! LuaTreeRefresh lua require'tree'.refresh() command! NvimTreeRefresh lua require'nvim-tree'.refresh()
command! LuaTreeClipboard lua require'tree'.print_clipboard() command! NvimTreeClipboard lua require'nvim-tree'.print_clipboard()
command! LuaTreeFindFile lua require'tree'.find_file(true) command! NvimTreeFindFile lua require'nvim-tree'.find_file(true)
let &cpo = s:save_cpo let &cpo = s:save_cpo
unlet s:save_cpo unlet s:save_cpo