From 7014b6aff49212c16c82b92043e87b0244d80b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A2=9C=E8=B4=B5=E5=BD=AC?= Date: Sat, 14 Aug 2021 17:06:56 +0800 Subject: [PATCH] Feat: add focus on tree functionality (#563) --- README.md | 2 +- doc/nvim-tree-lua.txt | 4 ++++ lua/nvim-tree.lua | 7 +++++++ plugin/tree.vim | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5283cafd..0477b738 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ let g:nvim_tree_icons = { nnoremap :NvimTreeToggle nnoremap r :NvimTreeRefresh nnoremap n :NvimTreeFindFile -" NvimTreeOpen and NvimTreeClose are also available if you need them +" NvimTreeOpen, NvimTreeClose and NvimTreeFocus are also available if you need them set termguicolors " this variable must be enabled for colors to be applied properly diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 5768961f..320aa6d0 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -33,6 +33,10 @@ closes the tree open or close the tree +|:NvimTreeFocus| *:NvimTreeFocus* + +open the tree if it is closed, and then focus on the tree + |:NvimTreeRefresh| *:NvimTreeRefresh* refresh the tree diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 706b6c18..f22f81f5 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -11,6 +11,13 @@ local api = vim.api local M = {} +function M.focus() + if not view.win_open() then + lib.open() + end + view.focus(); +end + function M.toggle() if view.win_open() then view.close() diff --git a/plugin/tree.vim b/plugin/tree.vim index 86a124b9..05080c30 100644 --- a/plugin/tree.vim +++ b/plugin/tree.vim @@ -37,6 +37,7 @@ augroup end command! NvimTreeOpen lua require'nvim-tree'.open() command! NvimTreeClose lua require'nvim-tree'.close() command! NvimTreeToggle lua require'nvim-tree'.toggle() +command! NvimTreeFocus lua require'nvim-tree'.focus() command! NvimTreeRefresh lua require'nvim-tree'.refresh() command! NvimTreeClipboard lua require'nvim-tree'.print_clipboard() command! NvimTreeFindFile lua require'nvim-tree'.find_file(true)