From f5af7aa95d0b1ae352c44436a03966633ad76aad Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Thu, 20 Feb 2020 21:16:13 +0100 Subject: [PATCH] add some options for the user and info in the readme --- README.md | 38 +++++++++++++++++++++++++++++++++++--- lua/lib/winutils.lua | 19 ++++++++++++++++--- plugin/tree.vim | 3 ++- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 853b8f2c..66fafb85 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,41 @@ # A File Explorer For Neovim Written In Lua -![alt text](.github/tree.png?raw=true "file explorer") - ## Notice - I am working on this plugin to learn lua, neovim's api and create a file explorer with features i need. - This plugin does not work on windows. +## Install + +Install with [vim-plug](https://github.com/junegunn/vim-plug): +```vim +Plug 'kyazdani42/nvim-tree.lua' +``` + +## Setup + +```vim +let g:lua_tree_side = 'right' | 'left' "left by default +let g:lua_tree_size = 40 "30 by default + +nnoremap :LuaTreeToggle +nnoremap n :LuaTreeRefresh +``` + +## KeyBindings + +- move around like in any vim buffer +- `` on `..` will cd in the above directory +- `` will cd in the directory under the cursor +- type `a` to add a file +- type `r` to rename a file +- type `d` to delete a file (will prompt for confirmation) +- if the file is a directory, `` will open the directory +- otherwise it will open the file in the buffer near the tree +- if the file is a symlink, `` will follow the symlink +- type `` will open the file in a vertical split +- type `` will open the file in a horizontal split + ## Features - [x] Open file in current buffer or in split with FzF like bindings (`CR`, `C-v`, `C-x`) - [x] File icons with vim-devicons @@ -16,10 +45,13 @@ - [x] Git integration - [x] Mouse support +## Screenshot + +![alt text](.github/tree.png?raw=true "file explorer") + ## TODO - add docs - fix coloring when no dev icons -- add options for users (tree side, tree size) - cd command to move faster accross the fs if needed - quickly find file in the directory structure - use libuv functions instead of `touch` and `mkdir` in `create_file()` and allow file creation with path like `foo/bar/baz` diff --git a/lua/lib/winutils.lua b/lua/lib/winutils.lua index 9da75180..f8703690 100644 --- a/lua/lib/winutils.lua +++ b/lua/lib/winutils.lua @@ -34,11 +34,24 @@ end local BUF_OPTIONS = { 'nonumber', 'norelativenumber', 'winfixwidth', 'winfixheight', - 'winhighlight=EndOfBuffer:LuaTreeEndOfBuffer', 'noswapfile' + 'winhighlight=EndOfBuffer:LuaTreeEndOfBuffer', 'noswapfile', + 'splitbelow' } +local WIN_WIDTH = 30 +local SIDE = 'topleft' + +if api.nvim_call_function('exists', { 'g:lua_tree_width' }) == 1 then + WIN_WIDTH = api.nvim_get_var('lua_tree_width') +end + +if api.nvim_call_function('exists', { 'g:lua_tree_side' }) == 1 then + if api.nvim_get_var('lua_tree_side') == 'right' then + SIDE = 'rightbelow' + end +end + local function open() - local win_width = 30 local options = { bufhidden = 'delete'; buftype = 'nowrite'; @@ -52,7 +65,7 @@ local function open() api.nvim_buf_set_option(buf, opt, val) end - api.nvim_command('topleft '..win_width..'vnew') + api.nvim_command(SIDE.. ' '..WIN_WIDTH..'vnew') api.nvim_win_set_buf(0, buf) for _, opt in pairs(BUF_OPTIONS) do api.nvim_command('setlocal '..opt) diff --git a/plugin/tree.vim b/plugin/tree.vim index 302d2ada..b4717967 100644 --- a/plugin/tree.vim +++ b/plugin/tree.vim @@ -12,7 +12,8 @@ au BufWritePost * lua require'tree'.refresh() au BufEnter * lua require'tree'.check_windows_and_close() au VimEnter * lua require'tree'.check_buffer_and_open() -command! LuaTree lua require'tree'.toggle() +command! LuaTreeToggle lua require'tree'.toggle() +command! LuaTreeRefresh lua require'tree'.refresh() let &cpo = s:save_cpo unlet s:save_cpo