chore: update_to_buf_dir allow auto_open configuration

also improve the documentation with doc references
This commit is contained in:
kiyan
2021-10-02 13:53:51 +02:00
parent 4cfe355035
commit 137628acb6
3 changed files with 71 additions and 43 deletions

View File

@@ -50,7 +50,12 @@ require'nvim-tree'.setup {
-- opens the tree when changing/opening a new tab if the tree wasn't previously opened -- opens the tree when changing/opening a new tab if the tree wasn't previously opened
open_on_tab = false, open_on_tab = false,
-- hijacks new directory buffers when they are opened. -- hijacks new directory buffers when they are opened.
update_to_buf_dir = true, update_to_buf_dir = {
-- enable the feature
enable = true,
-- allow to open the tree if it was previously closed
auto_open = true,
},
-- hijack the cursor in the tree to put it at the start of the filename -- hijack the cursor in the tree to put it at the start of the filename
hijack_cursor = false, hijack_cursor = false,
-- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually) -- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually)

View File

@@ -59,7 +59,7 @@ Resize the NvimTree window to the given size. Example: `:NvimTreeresize 50`
resizes the window to the width of 50. resizes the window to the width of 50.
============================================================================== ==============================================================================
SETUP *nvim-tree-setup* SETUP *nvim-tree.setup*
To configure the tree (and make it runnable), you should call the setup To configure the tree (and make it runnable), you should call the setup
function. function.
@@ -70,7 +70,10 @@ function.
hijack_netrw = true, hijack_netrw = true,
open_on_setup = false, open_on_setup = false,
ignore_ft_on_setup = {}, ignore_ft_on_setup = {},
update_to_buf_dir = true, update_to_buf_dir = {
enable = true,
auto_open = true,
},
auto_close = false, auto_close = false,
open_on_tab = false, open_on_tab = false,
hijack_cursor = false, hijack_cursor = false,
@@ -101,51 +104,65 @@ As options are currently being migrated, configuration of global options in
|nvim-tree-options| should be done BEFORE the setup call. |nvim-tree-options| should be done BEFORE the setup call.
Here is a list of the options available in the setup call: Here is a list of the options available in the setup call:
*nvim-tree.disable_netrw*
- |disable_netrw|: completely disable netrw - |disable_netrw|: completely disable netrw
type: `boolean` type: `boolean`
default: `true` default: `true`
*nvim-tree.hijack_netrw*
- |hijack_netrw|: hijack netrw windows (overriden if |disable_netrw| is `true`) - |hijack_netrw|: hijack netrw windows (overriden if |disable_netrw| is `true`)
type: `boolean` type: `boolean`
default: `true` default: `true`
*nvim-tree.open_on_setup*
- |open_on_setup|: will automatically open the tree when running setup if current - |open_on_setup|: will automatically open the tree when running setup if current
buffer is a directory, is empty or is unnamed. buffer is a directory, is empty or is unnamed.
type: `boolean` type: `boolean`
default: `false` default: `false`
*nvim-tree.ignore_ft_on_setup*
- |ignore_ft_on_setup|: list of filetypes that will make |open_on_setup| not - |ignore_ft_on_setup|: list of filetypes that will make |open_on_setup| not
open. You can use this option if you don't want the tree to open in some open. You can use this option if you don't want the tree to open in some
scenarios (eg using vim startify). scenarios (eg using vim startify).
type: `{string}` type: `{string}`
default: `{}` default: `{}`
*nvim-tree.auto_close*
- |auto_close|: force closing neovim when the tree is the last window in the view. - |auto_close|: force closing neovim when the tree is the last window in the view.
type: `boolean` type: `boolean`
default: `false` default: `false`
*nvim-tree.open_on_tab*
- |open_on_tab|: opens the tree automatically when switching tabpage or opening a new - |open_on_tab|: opens the tree automatically when switching tabpage or opening a new
tabpage if the tree was previously open. tabpage if the tree was previously open.
type: `boolean` type: `boolean`
default: `false` default: `false`
*nvim-tree.update_to_buf_dir*
- |update_to_buf_dir|: hijacks new directory buffers when they are opened (`:e dir`). - |update_to_buf_dir|: hijacks new directory buffers when they are opened (`:e dir`).
If |open_on_setup| is enabled, it will open the tree if the tree is closed.
Disable this option if you use vim-dirvish. - |update_to_buf_dir.enable|: enable the feature. Disable this option if you use vim-dirvish.
type: `boolean` type: `boolean`
default: `true` default: `true`
- |update_to_buf_dir.auto_open|: opens the tree if the tree was previously closed.
type: `boolean`
default: `true`
*nvim-tree.hijack_cursor*
- |hijack_cursor|: keeps the cursor on the first letter of the filename when - |hijack_cursor|: keeps the cursor on the first letter of the filename when
moving in the tree. moving in the tree.
type: `boolean` type: `boolean`
default: `false` default: `false`
*nvim-tree.update_cwd*
- |update_cwd|: changes the tree root directory on `DirChanged` and refreshes - |update_cwd|: changes the tree root directory on `DirChanged` and refreshes
the tree. the tree.
type: `boolean` type: `boolean`
default: `false` default: `false`
*nvim-tree.update_focused_file*
- |update_focused_file|: update the focused file on `BufEnter`, un-collapses - |update_focused_file|: update the focused file on `BufEnter`, un-collapses
the folders recursively until it finds the file the folders recursively until it finds the file
@@ -166,6 +183,7 @@ Here is a list of the options available in the setup call:
type: `{string}` type: `{string}`
default: `{}` default: `{}`
*nvim-tree.system_open*
- |system_open|: configuration options for the system open command - |system_open|: configuration options for the system open command
- |system_open.cmd|: the command to run, leaving nil should work but - |system_open.cmd|: the command to run, leaving nil should work but
@@ -177,34 +195,36 @@ Here is a list of the options available in the setup call:
type: `{string}` type: `{string}`
default: `{}` default: `{}`
*nvim-tree.lsp_diagnostics*
- |lsp_diagnostics|: show lsp diagnostics in the signcolumn - |lsp_diagnostics|: show lsp diagnostics in the signcolumn
type: `boolean` type: `boolean`
default: false default: false
*nvim-tree.view*
- |view|: window / buffer setup - |view|: window / buffer setup
- |view.width|: width of the window, can be either a `%` string or - |view.width|: width of the window, can be either a `%` string or
a number representing columns a number representing columns
type: `string | number` type: `string | number`
default: `30` default: `30`
- |view.side|: side of the tree, can be one of 'left' | 'right' | 'bottom' | 'top' - |view.side|: side of the tree, can be one of 'left' | 'right' | 'bottom' | 'top'
Note that bottom/top are not working correctly yet. Note that bottom/top are not working correctly yet.
type: `string` type: `string`
default: 'left' default: 'left'
- |view.auto_resize|: auto resize the tree after opening a file - |view.auto_resize|: auto resize the tree after opening a file
type: `boolean` type: `boolean`
default: false default: false
- |view.mappings|: configuration options for keymaps - |view.mappings|: configuration options for keymaps
- |view.mappings.custom_only|: will use only the provided user mappings and not the default - |view.mappings.custom_only|: will use only the provided user mappings and not the default
otherwise, extends the default mappings with the provided user mappings otherwise, extends the default mappings with the provided user mappings
type: `boolean` type: `boolean`
default: false default: false
- |view,mappings.list|: a list of keymaps that will extend or override the default keymaps - |view,mappings.list|: a list of keymaps that will extend or override the default keymaps
type: list of `{ key: table of strings or string, mode: string (vim-mode), cb: callback function as a string }` type: list of `{ key: table of strings or string, mode: string (vim-mode), cb: callback function as a string }`
default: {} default: {}

View File

@@ -12,15 +12,6 @@ local _config = {
is_windows = vim.fn.has('win32') == 1 or vim.fn.has('win32unix') == 1, is_windows = vim.fn.has('win32') == 1 or vim.fn.has('win32unix') == 1,
is_macos = vim.fn.has('mac') == 1 or vim.fn.has('macunix') == 1, is_macos = vim.fn.has('mac') == 1 or vim.fn.has('macunix') == 1,
is_unix = vim.fn.has('unix') == 1, is_unix = vim.fn.has('unix') == 1,
update_focused_file = {
enable = false,
update_cwd = false,
ignore_list = {},
},
system_open = {},
ignore_ft_on_setup = {},
open_on_setup = false,
update_to_buf_dir = true,
} }
local M = {} local M = {}
@@ -302,7 +293,8 @@ function M.on_leave()
end end
function M.open_on_directory() function M.open_on_directory()
if not (_config.update_to_buf_dir and (_config.open_on_setup or view.win_open())) then local should_proceed = _config.update_to_buf_dir.auto_open or view.win_open()
if not _config.update_to_buf_dir.enable or not should_proceed then
return return
end end
local buf = api.nvim_get_current_buf() local buf = api.nvim_get_current_buf()
@@ -408,7 +400,10 @@ local DEFAULT_OPTS = {
hijack_netrw = true, hijack_netrw = true,
open_on_setup = false, open_on_setup = false,
open_on_tab = false, open_on_tab = false,
update_to_buf_dir = true, update_to_buf_dir = {
enable = true,
auto_open = true,
},
auto_close = false, auto_close = false,
hijack_cursor = false, hijack_cursor = false,
update_cwd = false, update_cwd = false,
@@ -434,7 +429,15 @@ function M.setup(conf)
_config.system_open = opts.system_open _config.system_open = opts.system_open
_config.open_on_setup = opts.open_on_setup _config.open_on_setup = opts.open_on_setup
_config.ignore_ft_on_setup = opts.ignore_ft_on_setup _config.ignore_ft_on_setup = opts.ignore_ft_on_setup
if type(opts.update_to_buf_dir) == "boolean" then
require'nvim-tree.utils'.echo_warning("update_to_buf_dir is now a table, see :help nvim-tree.update_to_buf_dir")
_config.update_to_buf_dir = {
enable = opts.update_to_buf_dir,
auto_open = opts.update_to_buf_dir,
}
else
_config.update_to_buf_dir = opts.update_to_buf_dir _config.update_to_buf_dir = opts.update_to_buf_dir
end
require'nvim-tree.colors'.setup() require'nvim-tree.colors'.setup()
require'nvim-tree.view'.setup(opts.view or {}) require'nvim-tree.view'.setup(opts.view or {})