Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite the whole api #14

Merged
merged 1 commit into from May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,5 +1,5 @@
Tree.lua is a simple tree for neovim
Copyright © 2012 Yazdani Kiyan
Copyright © 2019 Yazdani Kiyan

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
68 changes: 45 additions & 23 deletions README.md
Expand Up @@ -2,33 +2,42 @@

## Notice

- This plugin does not work on windows.
This plugin doesn't support windows. \
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 with [vim-plug](https://github.com/junegunn/vim-plug):
```vim
" master (neovim git)
Plug 'kyazdani42/nvim-web-devicons' " for file icons
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

```vim
let g:lua_tree_side = 'right' | 'left' "left by default
let g:lua_tree_size = 40 "30 by default
let g:lua_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default, not working on mac atm
let g:lua_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:lua_tree_auto_close = 1 "0 by default, closes the tree when it's the last window
let g:lua_tree_follow = 1 "0 by default, this option will bind BufEnter to the LuaTreeFindFile command
" :help LuaTreeFindFile for more info
let g:lua_tree_follow = 1 "0 by default, this option allows the cursor to be updated when entering a buffer
let g:lua_tree_show_icons = {
\ 'git': 1,
\ 'folders': 0,
\ 'files': 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 web-devicons is installed and on your runtimepath
"if nvim-web-devicons is installed and on your runtimepath

" You can edit keybindings be defining this variable
" You don't have to define all keys.
Expand All @@ -44,14 +53,27 @@ let g:lua_tree_bindings = {
\ 'rename': 'r'
\ }

" default will show icon by default if no icon is provided
" default shows no icon by default
let g:lua_tree_icons = {
\ 'default': '',
\ 'git': {
\ 'unstaged': "✗",
\ 'staged': "✓",
\ 'unmerged': "═",
\ 'renamed': "➜",
\ 'untracked': "★"
\ }
\ }

nnoremap <C-n> :LuaTreeToggle<CR>
nnoremap <leader>r :LuaTreeRefresh<CR>
nnoremap <leader>n :LuaTreeFindFile<CR>
" LuaTreeOpen and LuaTreeClose are also available if you need them

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`
highlight LuaTreeFolderName guibg=cyan gui=bold,underline
highlight LuaTreeFolderIcon guibg=blue
```

Expand All @@ -60,33 +82,33 @@ highlight LuaTreeFolderIcon guibg=blue
- move around like in any vim buffer
- `<CR>` on `..` will cd in the above directory
- `.` will cd in the directory under the cursor
- type `a` to add a file
- type `a` to add a file. Adding a directory requires leaving a leading `/` at the end of the path.
> 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
- type `r` to rename a file
- type `d` to delete a file (will prompt for confirmation)
- if the file is a directory, `<CR>` will open the directory
- otherwise it will open the file in the buffer near the tree
- if the file is a symlink, `<CR>` will follow the symlink
- if the file is a directory, `<CR>` will open the directory otherwise it will open the file in the buffer near the tree
- if the file is a symlink, `<CR>` will follow the symlink (if the target is a file)
- type `<C-v>` will open the file in a vertical split
- type `<C-x>` will open the file in a horizontal split
- type `<C-t>` will open the file in a new tab
- type `gx` to open the file with the `open` command on MACOS and `xdg-open` in linux
- Double left click acts like `<CR>`
- Double right click acts like `.`

## Note

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.

## Features
- [x] Open file in current buffer or in split with FzF like bindings (`<CR>`, `<C-v>`, `<C-x>`, `<C-t>`)
- [x] File icons with vim-devicons
- [x] Syntax highlighting ([exa](https://github.com/ogham/exa) like)
- [x] Change directory with `.`
- [x] Add / Rename / delete files
- [x] Git integration
- [x] Mouse support
- Open file in current buffer or in split with FzF like bindings (`<CR>`, `<C-v>`, `<C-x>`, `<C-t>`)
- File icons with nvim-web-devicons
- Syntax highlighting ([exa](https://github.com/ogham/exa) like)
- Change directory with `.`
- Add / Rename / delete files
- Git integration
- Mouse support
- It's fast

## Screenshot

![alt text](.github/screenshot.png?raw=true "file explorer")

## TODO

- Tree creation could be async
- bufferize tree
- better default colors (use vim highlight groups)
49 changes: 40 additions & 9 deletions doc/nvim-tree-lua.txt
Expand Up @@ -7,6 +7,8 @@ Author: Yazdani Kiyan <yazdani.kiyan@protonmail.com>
==============================================================================
INTRODUCTION *nvim-tree-introduction*

This file explorer doesn't work on windows and requires neovim `nightly`

==============================================================================
QUICK START *nvim-tree-quickstart*

Expand All @@ -19,6 +21,14 @@ open the tree with :LuaTreeToggle
==============================================================================
COMMANDS *nvim-tree-commands*

|:LuaTreeOpen| *:LuaTreeOpen*

opens the tree

|:LuaTreeClose| *:LuaTreeClose*

closes the tree

|:LuaTreeToggle| *:LuaTreeToggle*

open or close the tree
Expand All @@ -32,7 +42,8 @@ refresh the tree
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
(if you opened a file with something else than the LuaTree, like `fzf`)
(if you opened a file with something else than the LuaTree, like `fzf` or
`:split`)

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

|g:lua_tree_ignore| *g:lua_tree_ignore*

An array of strings that the tree won't display.
Each pattern is passed into the 'ls' function as `--ignore=PATTERN`
An array of strings that the tree won't load and display.
useful to hide large data/cache folders.
>
example: let g:lua_tree_ignore = [ '.git', 'node_modules' ]

Expand All @@ -66,12 +77,30 @@ can disable icons per type:
\}

Can be one of `1` and `0` for each key. By default the tree will try
to render the icons. The `icons` key can only work if `vim-devicons`
to render the icons. The `icons` key can only work if `nvim-web-devicons`
is installed and in your |runtimepath|
(https://github.com/kyazdani42/nvim-web-devicons)

|g:lua_tree_icons| *g:lua_tree_icons*

You can set some icons for the git status and the default icon that shows
when no icon is found for a file.
>
let g:lua_tree_icons = {
\ 'default': '',
\ 'git': {
\ 'unstaged': "✗",
\ 'staged': "✓",
\ 'unmerged': "═",
\ 'renamed': "➜",
\ 'untracked': "★"
\ }
\ }
<
|g:lua_tree_follow| *g:lua_tree_follow*

Can be `0` or `1`. When `1`, will bind |:LuaTreeFindFile| to |BufEnter|
Can be `0` or `1`. When `1`, will update the cursor to update to the correct
location in the tree on |BufEnter|.
Default is 0

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

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

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

Syntax highlighting uses g:terminal_color_ from colorschemes, fallbacks to
ugly colors otherwise.
Expand All @@ -140,8 +170,9 @@ Git integration tells when a file is:
- ✗ unstaged or folder is dirty
- ✓ staged
- ★ new file
- ✓✗ partially staged
- ✓★ new file staged
- ✓ ✗ partially staged
- ✓ ★ new file staged
- ✓ ★ ✗ new file staged and has unstaged modifications
- ═ merging
- ➜ renamed

Expand Down
3 changes: 3 additions & 0 deletions doc/tags
@@ -1,10 +1,13 @@
:LuaTreeClose nvim-tree-lua.txt /*:LuaTreeClose*
:LuaTreeFindFile nvim-tree-lua.txt /*:LuaTreeFindFile*
:LuaTreeOpen nvim-tree-lua.txt /*:LuaTreeOpen*
:LuaTreeRefresh nvim-tree-lua.txt /*:LuaTreeRefresh*
:LuaTreeToggle nvim-tree-lua.txt /*:LuaTreeToggle*
g:lua_tree_auto_close nvim-tree-lua.txt /*g:lua_tree_auto_close*
g:lua_tree_auto_open nvim-tree-lua.txt /*g:lua_tree_auto_open*
g:lua_tree_bindings nvim-tree-lua.txt /*g:lua_tree_bindings*
g:lua_tree_follow nvim-tree-lua.txt /*g:lua_tree_follow*
g:lua_tree_icons nvim-tree-lua.txt /*g:lua_tree_icons*
g:lua_tree_ignore nvim-tree-lua.txt /*g:lua_tree_ignore*
g:lua_tree_show_icons nvim-tree-lua.txt /*g:lua_tree_show_icons*
g:lua_tree_side nvim-tree-lua.txt /*g:lua_tree_side*
Expand Down