@@ -253,6 +253,7 @@ These are the default bindings:
|
|||||||
-- default mappings
|
-- default mappings
|
||||||
local list = {
|
local list = {
|
||||||
{ key = {"<CR>", "o", "<2-LeftMouse>"}, action = "edit" },
|
{ key = {"<CR>", "o", "<2-LeftMouse>"}, action = "edit" },
|
||||||
|
{ key = "<C-e>", action = "edit_in_place" },
|
||||||
{ key = {"O"}, action = "edit_no_picker" },
|
{ key = {"O"}, action = "edit_no_picker" },
|
||||||
{ key = {"<2-RightMouse>", "<C-]>"}, action = "cd" },
|
{ key = {"<2-RightMouse>", "<C-]>"}, action = "cd" },
|
||||||
{ key = "<C-v>", action = "vsplit" },
|
{ key = "<C-v>", action = "vsplit" },
|
||||||
@@ -293,9 +294,10 @@ You can toggle the help UI by pressing `g?`.
|
|||||||
|
|
||||||
## Tips & reminders
|
## Tips & reminders
|
||||||
|
|
||||||
1. you can add a directory by adding a `/` at the end of the paths, entering multiple directories `BASE/foo/bar/baz` will add directory foo, then bar and add a file baz to it.
|
1. You can add a directory by adding a `/` at the end of the paths, entering multiple directories `BASE/foo/bar/baz` will add directory foo, then bar and add a file baz to it.
|
||||||
2. you can update window options for the tree by setting `require"nvim-tree.view".View.winopts.MY_OPTION = MY_OPTION_VALUE`
|
2. You can update window options for the tree by setting `require"nvim-tree.view".View.winopts.MY_OPTION = MY_OPTION_VALUE`
|
||||||
3. `toggle` has a second parameter which allows to toggle without focusing the explorer (`require"nvim-tree.toggle(false, false)`).
|
3. `toggle` has a second parameter which allows to toggle without focusing the explorer (`require"nvim-tree.toggle(false, false)`).
|
||||||
|
4. You can allow nvim-tree to behave like vinegar (see `:help nvim-tree-vinegar`).
|
||||||
|
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|||||||
@@ -585,7 +585,7 @@ INFORMATIONS *nvim-tree-info*
|
|||||||
- type `>` to navigate to the next sibling of current file/directory
|
- type `>` to navigate to the next sibling of current file/directory
|
||||||
- type `J` to navigate to the first sibling of current file/directory
|
- type `J` to navigate to the first sibling of current file/directory
|
||||||
- type `K` to navigate to the last sibling of current file/directory
|
- type `K` to navigate to the last sibling of current file/directory
|
||||||
|
- type `<C-e>` to edit the file in place, effectively replacing the tree explorer.
|
||||||
- if the file is a directory, <CR> will open the directory
|
- if the file is a directory, <CR> will open the directory
|
||||||
- otherwise it will open the file in the buffer near the tree
|
- 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 symlink, <CR> will follow the symlink
|
||||||
@@ -605,6 +605,7 @@ Defaults to:
|
|||||||
lua <<EOF
|
lua <<EOF
|
||||||
local list = {
|
local list = {
|
||||||
{ key = {"<CR>", "o", "<2-LeftMouse>"}, action = "edit" },
|
{ key = {"<CR>", "o", "<2-LeftMouse>"}, action = "edit" },
|
||||||
|
{ key = "<C-e>", action = "edit_in_place" },
|
||||||
{ key = {"O"}, action = "edit_no_picker" },
|
{ key = {"O"}, action = "edit_no_picker" },
|
||||||
{ key = {"<2-RightMouse>", "<C-]>"}, action = "cd" },
|
{ key = {"<2-RightMouse>", "<C-]>"}, action = "cd" },
|
||||||
{ key = "<C-v>", action = "vsplit" },
|
{ key = "<C-v>", action = "vsplit" },
|
||||||
@@ -745,7 +746,42 @@ NvimTreeFileNew
|
|||||||
NvimTreeFileDeleted
|
NvimTreeFileDeleted
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
EVENTS *nvim-tree-events*
|
vinegar style *nvim-tree-vinegar*
|
||||||
|
|
||||||
|
|nvim_tree_vinegar| *nvim_tree_vinegar*
|
||||||
|
|
||||||
|
nvim-tree can behave like vinegar. To allow this, you will need to configure
|
||||||
|
it in a specific way:
|
||||||
|
|
||||||
|
- Use `require"nvim-tree".open_replacing_current_buffer()` instead of the
|
||||||
|
default open command.
|
||||||
|
You can easily implement a toggle using this too:
|
||||||
|
>
|
||||||
|
local function toggle_replace()
|
||||||
|
local view = require"nvim-tree.view"
|
||||||
|
if view.is_visible() then
|
||||||
|
require.close()
|
||||||
|
else
|
||||||
|
require"nvim-tree".open_replacing_current_buffer()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
<
|
||||||
|
- Use the `edit_in_place` action to edit files. It's bound to `<C-e>` by
|
||||||
|
default, vinegar uses `-`. You can override this with:
|
||||||
|
>
|
||||||
|
require"nvim-tree".setup {
|
||||||
|
view = {
|
||||||
|
mappings = {
|
||||||
|
{ key = "-", action = "edit_in_place" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<
|
||||||
|
You'll also need to set |nvim-tree.hijack_netrw| to `true` during setup.
|
||||||
|
A good functionnality to enable is |nvim-tree.hijack_directories|.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
events *nvim-tree-events*
|
||||||
|
|
||||||
|nvim_tree_events| *nvim_tree_events*
|
|nvim_tree_events| *nvim_tree_events*
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,25 @@ function M.open(cwd)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.open_replacing_current_buffer()
|
||||||
|
if view.is_visible() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local buf = api.nvim_get_current_buf()
|
||||||
|
local bufname = api.nvim_buf_get_name(buf)
|
||||||
|
if bufname == "" or vim.loop.fs_stat(bufname) == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local cwd = vim.fn.fnamemodify(bufname, ':p:h')
|
||||||
|
if not TreeExplorer or cwd ~= TreeExplorer.cwd then
|
||||||
|
lib.init(cwd)
|
||||||
|
end
|
||||||
|
view.open_in_current_win({ hijack_current_buf = false, resize = false })
|
||||||
|
require"nvim-tree.renderer".draw()
|
||||||
|
end
|
||||||
|
|
||||||
function M.tab_change()
|
function M.tab_change()
|
||||||
if view.is_visible({ any_tabpage = true }) then
|
if view.is_visible({ any_tabpage = true }) then
|
||||||
local bufname = vim.api.nvim_buf_get_name(0)
|
local bufname = vim.api.nvim_buf_get_name(0)
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ local nvim_tree_callback = require'nvim-tree.config'.nvim_tree_callback
|
|||||||
local M = {
|
local M = {
|
||||||
mappings = {
|
mappings = {
|
||||||
{ key = {"<CR>", "o", "<2-LeftMouse>"}, action = "edit" },
|
{ key = {"<CR>", "o", "<2-LeftMouse>"}, action = "edit" },
|
||||||
{ key = {"O"}, action = "edit_no_picker" },
|
{ key = "<C-e>", action = "edit_in_place" },
|
||||||
|
{ key = "O", action = "edit_no_picker" },
|
||||||
{ key = {"<2-RightMouse>", "<C-]>"}, action = "cd" },
|
{ key = {"<2-RightMouse>", "<C-]>"}, action = "cd" },
|
||||||
{ key = "<C-v>", action = "vsplit" },
|
{ key = "<C-v>", action = "vsplit" },
|
||||||
{ key = "<C-x>", action = "split"},
|
{ key = "<C-x>", action = "split"},
|
||||||
@@ -96,9 +97,10 @@ function M.on_keypress(action)
|
|||||||
end
|
end
|
||||||
elseif node.name == ".." then
|
elseif node.name == ".." then
|
||||||
return require'nvim-tree.actions.change-dir'.fn("..")
|
return require'nvim-tree.actions.change-dir'.fn("..")
|
||||||
elseif action == "cd" and node.nodes ~= nil then
|
|
||||||
return require'nvim-tree.actions.change-dir'.fn(lib.get_last_group_node(node).absolute_path)
|
|
||||||
elseif action == "cd" then
|
elseif action == "cd" then
|
||||||
|
if node.nodes ~= nil then
|
||||||
|
require'nvim-tree.actions.change-dir'.fn(lib.get_last_group_node(node).absolute_path)
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -154,6 +154,12 @@ function M.fn(mode, filename)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if mode == "edit_in_place" then
|
||||||
|
vim.cmd("edit " .. vim.fn.fnameescape(filename))
|
||||||
|
require"nvim-tree.view".abandon_current_window()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local tabpage = api.nvim_get_current_tabpage()
|
local tabpage = api.nvim_get_current_tabpage()
|
||||||
local win_ids = api.nvim_tabpage_list_wins(tabpage)
|
local win_ids = api.nvim_tabpage_list_wins(tabpage)
|
||||||
|
|
||||||
|
|||||||
@@ -194,12 +194,20 @@ local function set_current_win()
|
|||||||
M.View.tabpages[current_tab] = { winnr = a.nvim_get_current_win() }
|
M.View.tabpages[current_tab] = { winnr = a.nvim_get_current_win() }
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.open_in_current_win()
|
function M.open_in_current_win(opts)
|
||||||
create_buffer(a.nvim_get_current_buf())
|
opts = opts or { hijack_current_buf = true, resize = true }
|
||||||
|
create_buffer(opts.hijack_current_buf and a.nvim_get_current_buf())
|
||||||
set_current_win()
|
set_current_win()
|
||||||
set_window_options_and_buffer()
|
set_window_options_and_buffer()
|
||||||
|
if opts.resize then
|
||||||
M.reposition_window()
|
M.reposition_window()
|
||||||
M.resize()
|
M.resize()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.abandon_current_window()
|
||||||
|
local tab = a.nvim_get_current_tabpage()
|
||||||
|
M.View.tabpages[tab] = { winnr = nil }
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.is_visible(opts)
|
function M.is_visible(opts)
|
||||||
|
|||||||
Reference in New Issue
Block a user