Skip to content

Commit 35442a6

Browse files
committed
Refacto: rewrite everything
- The tree is created with libuv functions, which makes it blazingly fast. - The tree may now be faster than any other vim trees, it can handle directories with thousands of files without any latency at all (tested on 40K files, works flawlessly). - More solid logic for opening and closing the tree. - tree state is remembered (closing / opening a folder keeps opened subdirectories open) - detection of multiple git projects in the tree - more icon support - smart rendering - smart updates - ms windows support - gx replacement function running xdg-open on linux, open on macos
1 parent afc86a9 commit 35442a6

18 files changed

+1151
-1011
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Tree.lua is a simple tree for neovim
2-
Copyright © 2012 Yazdani Kiyan
2+
Copyright © 2019 Yazdani Kiyan
33

44
This program is free software: you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by

README.md

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,42 @@
22

33
## Notice
44

5-
- This plugin does not work on windows.
5+
This plugin doesn't support windows. \
6+
This plugin requires [neovim nightly](https://github.com/neovim/neovim/wiki/Installing-Neovim). \
7+
You can switch to commit `afc86a9` if you use neovim 0.4.x. \
8+
Note that the old version has less features and is much slower than the new one.
69

710
## Install
811

912
Install with [vim-plug](https://github.com/junegunn/vim-plug):
1013
```vim
14+
" master (neovim git)
15+
Plug 'kyazdani42/nvim-web-devicons' " for file icons
1116
Plug 'kyazdani42/nvim-tree.lua'
17+
18+
" old version that runs on neovim 0.4.x
19+
Plug 'kyazdani42/nvim-tree.lua' { 'commit': 'afc86a9' }
20+
" for icons in old version
21+
Plug 'ryanoasis/vim-devicons'
1222
```
1323

1424
## Setup
1525

1626
```vim
1727
let g:lua_tree_side = 'right' | 'left' "left by default
1828
let g:lua_tree_size = 40 "30 by default
19-
let g:lua_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default, not working on mac atm
29+
let g:lua_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default
2030
let g:lua_tree_auto_open = 1 "0 by default, opens the tree when typing `vim $DIR` or `vim`
2131
let g:lua_tree_auto_close = 1 "0 by default, closes the tree when it's the last window
22-
let g:lua_tree_follow = 1 "0 by default, this option will bind BufEnter to the LuaTreeFindFile command
23-
" :help LuaTreeFindFile for more info
32+
let g:lua_tree_follow = 1 "0 by default, this option allows the cursor to be updated when entering a buffer
2433
let g:lua_tree_show_icons = {
2534
\ 'git': 1,
2635
\ 'folders': 0,
2736
\ 'files': 0,
2837
\}
2938
"If 0, do not show the icons for one of 'git' 'folder' and 'files'
3039
"1 by default, notice that if 'files' is 1, it will only display
31-
"if web-devicons is installed and on your runtimepath
40+
"if nvim-web-devicons is installed and on your runtimepath
3241
3342
" You can edit keybindings be defining this variable
3443
" You don't have to define all keys.
@@ -44,14 +53,27 @@ let g:lua_tree_bindings = {
4453
\ 'rename': 'r'
4554
\ }
4655
56+
" default will show icon by default if no icon is provided
57+
" default shows no icon by default
58+
let g:lua_tree_icons = {
59+
\ 'default': '',
60+
\ 'git': {
61+
\ 'unstaged': "✗",
62+
\ 'staged': "✓",
63+
\ 'unmerged': "═",
64+
\ 'renamed': "➜",
65+
\ 'untracked': "★"
66+
\ }
67+
\ }
68+
4769
nnoremap <C-n> :LuaTreeToggle<CR>
4870
nnoremap <leader>r :LuaTreeRefresh<CR>
4971
nnoremap <leader>n :LuaTreeFindFile<CR>
72+
" LuaTreeOpen and LuaTreeClose are also available if you need them
5073
5174
set termguicolors " this variable must be enabled for colors to be applied properly
5275
5376
" a list of groups can be found at `:help lua_tree_highlight`
54-
highlight LuaTreeFolderName guibg=cyan gui=bold,underline
5577
highlight LuaTreeFolderIcon guibg=blue
5678
```
5779

@@ -60,33 +82,33 @@ highlight LuaTreeFolderIcon guibg=blue
6082
- move around like in any vim buffer
6183
- `<CR>` on `..` will cd in the above directory
6284
- `.` will cd in the directory under the cursor
63-
- type `a` to add a file
85+
- type `a` to add a file. Adding a directory requires leaving a leading `/` at the end of the path.
86+
> you can add multiple directories by doing foo/bar/baz/f and it will add foo bar and baz directories and f as a file
6487
- type `r` to rename a file
6588
- type `d` to delete a file (will prompt for confirmation)
66-
- if the file is a directory, `<CR>` will open the directory
67-
- otherwise it will open the file in the buffer near the tree
68-
- if the file is a symlink, `<CR>` will follow the symlink
89+
- if the file is a directory, `<CR>` will open the directory otherwise it will open the file in the buffer near the tree
90+
- if the file is a symlink, `<CR>` will follow the symlink (if the target is a file)
6991
- type `<C-v>` will open the file in a vertical split
7092
- type `<C-x>` will open the file in a horizontal split
7193
- type `<C-t>` will open the file in a new tab
94+
- type `gx` to open the file with the `open` command on MACOS and `xdg-open` in linux
7295
- Double left click acts like `<CR>`
7396
- Double right click acts like `.`
7497

98+
## Note
99+
100+
This plugin is very fast because it uses the `libuv` `scandir` and `scandir_next` functions instead of spawning an `ls` process which can get slow on large files when combining with `stat` to get file informations.
101+
75102
## Features
76-
- [x] Open file in current buffer or in split with FzF like bindings (`<CR>`, `<C-v>`, `<C-x>`, `<C-t>`)
77-
- [x] File icons with vim-devicons
78-
- [x] Syntax highlighting ([exa](https://github.com/ogham/exa) like)
79-
- [x] Change directory with `.`
80-
- [x] Add / Rename / delete files
81-
- [x] Git integration
82-
- [x] Mouse support
103+
- Open file in current buffer or in split with FzF like bindings (`<CR>`, `<C-v>`, `<C-x>`, `<C-t>`)
104+
- File icons with nvim-devicons
105+
- Syntax highlighting ([exa](https://github.com/ogham/exa) like)
106+
- Change directory with `.`
107+
- Add / Rename / delete files
108+
- Git integration
109+
- Mouse support
110+
- It's fast
83111

84112
## Screenshot
85113

86114
![alt text](.github/screenshot.png?raw=true "file explorer")
87-
88-
## TODO
89-
90-
- Tree creation could be async
91-
- bufferize tree
92-
- better default colors (use vim highlight groups)

doc/nvim-tree-lua.txt

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Author: Yazdani Kiyan <yazdani.kiyan@protonmail.com>
77
==============================================================================
88
INTRODUCTION *nvim-tree-introduction*
99

10+
This file explorer doesn't work on windows and requires neovim `nightly`
11+
1012
==============================================================================
1113
QUICK START *nvim-tree-quickstart*
1214

@@ -19,6 +21,14 @@ open the tree with :LuaTreeToggle
1921
==============================================================================
2022
COMMANDS *nvim-tree-commands*
2123

24+
|:LuaTreeOpen| *:LuaTreeOpen*
25+
26+
opens the tree
27+
28+
|:LuaTreeClose| *:LuaTreeClose*
29+
30+
closes the tree
31+
2232
|:LuaTreeToggle| *:LuaTreeToggle*
2333

2434
open or close the tree
@@ -32,7 +42,8 @@ refresh the tree
3242
The command will change the cursor in the tree for the current bufname.
3343

3444
It will also open the leafs of the tree leading to the file in the buffer
35-
(if you opened a file with something else than the LuaTree, like `fzf`)
45+
(if you opened a file with something else than the LuaTree, like `fzf` or
46+
`:split`)
3647

3748
==============================================================================
3849
OPTIONS *nvim-tree-options*
@@ -48,8 +59,8 @@ where the window will open (default to 'left')
4859

4960
|g:lua_tree_ignore| *g:lua_tree_ignore*
5061

51-
An array of strings that the tree won't display.
52-
Each pattern is passed into the 'ls' function as `--ignore=PATTERN`
62+
An array of strings that the tree won't load and display.
63+
useful to hide large data/cache folders.
5364
>
5465
example: let g:lua_tree_ignore = [ '.git', 'node_modules' ]
5566
@@ -66,12 +77,30 @@ can disable icons per type:
6677
\}
6778
6879
Can be one of `1` and `0` for each key. By default the tree will try
69-
to render the icons. The `icons` key can only work if `vim-devicons`
80+
to render the icons. The `icons` key can only work if `nvim-devicons`
7081
is installed and in your |runtimepath|
82+
(https://github.com/kyazdani42/nvim-devicons)
83+
84+
|g:lua_tree_icons| *g:lua_tree_icons*
7185

86+
You can set some icons for the git status and the default icon that shows
87+
when no icon is found for a file.
88+
>
89+
let g:lua_tree_icons = {
90+
\ 'default': '',
91+
\ 'git': {
92+
\ 'unstaged': "✗",
93+
\ 'staged': "✓",
94+
\ 'unmerged': "═",
95+
\ 'renamed': "➜",
96+
\ 'untracked': "★"
97+
\ }
98+
\ }
99+
<
72100
|g:lua_tree_follow| *g:lua_tree_follow*
73101

74-
Can be `0` or `1`. When `1`, will bind |:LuaTreeFindFile| to |BufEnter|
102+
Can be `0` or `1`. When `1`, will update the cursor to update to the correct
103+
location in the tree on |BufEnter|.
75104
Default is 0
76105

77106
|g:lua_tree_auto_open| *g:lua_tree_auto_open*
@@ -105,6 +134,8 @@ INFORMATIONS *nvim-tree-info*
105134
- type '<C-v>' will open the file in a vertical split
106135
- type '<C-x>' will open the file in a horizontal split
107136
- type '<C-t>' will open the file in a new tab
137+
- type 'gx' to open the file with the `open` command on macos and `xdg-open`
138+
on linux.
108139

109140
- Double left click acts like '<CR>'
110141
- Double right click acts like '.'
@@ -130,8 +161,7 @@ default keybindings will be applied to undefined keys.
130161
File icons with vim-devicons.
131162

132163
Uses other type of icons so a good font support is recommended.
133-
If the tree renders weird glyphs, install correct fonts or try to change
134-
your terminal.
164+
If the tree renders weird glyphs, install the correct fonts.
135165

136166
Syntax highlighting uses g:terminal_color_ from colorschemes, fallbacks to
137167
ugly colors otherwise.
@@ -140,8 +170,9 @@ Git integration tells when a file is:
140170
- ✗ unstaged or folder is dirty
141171
- ✓ staged
142172
- ★ new file
143-
- ✓✗ partially staged
144-
- ✓★ new file staged
173+
- ✓ ✗ partially staged
174+
- ✓ ★ new file staged
175+
- ✓ ★ ✗ new file staged and has unstaged modifications
145176
- ═ merging
146177
- ➜ renamed
147178

doc/tags

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
:LuaTreeClose nvim-tree-lua.txt /*:LuaTreeClose*
12
:LuaTreeFindFile nvim-tree-lua.txt /*:LuaTreeFindFile*
3+
:LuaTreeOpen nvim-tree-lua.txt /*:LuaTreeOpen*
24
:LuaTreeRefresh nvim-tree-lua.txt /*:LuaTreeRefresh*
35
:LuaTreeToggle nvim-tree-lua.txt /*:LuaTreeToggle*
46
g:lua_tree_auto_close nvim-tree-lua.txt /*g:lua_tree_auto_close*
57
g:lua_tree_auto_open nvim-tree-lua.txt /*g:lua_tree_auto_open*
68
g:lua_tree_bindings nvim-tree-lua.txt /*g:lua_tree_bindings*
79
g:lua_tree_follow nvim-tree-lua.txt /*g:lua_tree_follow*
10+
g:lua_tree_icons nvim-tree-lua.txt /*g:lua_tree_icons*
811
g:lua_tree_ignore nvim-tree-lua.txt /*g:lua_tree_ignore*
912
g:lua_tree_show_icons nvim-tree-lua.txt /*g:lua_tree_show_icons*
1013
g:lua_tree_side nvim-tree-lua.txt /*g:lua_tree_side*

0 commit comments

Comments
 (0)