Skip to content

Commit bb5cbc8

Browse files
committed
Merge branch 'master' into 1480-break-symlink-cycles
2 parents ef47133 + ff6e796 commit bb5cbc8

File tree

5 files changed

+214
-73
lines changed

5 files changed

+214
-73
lines changed

doc/nvim-tree-lua.txt

Lines changed: 165 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ Subsequent calls to setup will replace the previous configuration.
174174
sync_root_with_cwd = false,
175175
reload_on_bufenter = false,
176176
respect_buf_cwd = false,
177+
on_attach = "disable", -- function(bufnr). If nil, will use the deprecated mapping strategy
178+
remove_keymaps = false, -- boolean (disable totally or not) or list of key (lhs)
177179
view = {
178180
adaptive_size = false,
179181
centralize_selection = false,
@@ -185,12 +187,24 @@ Subsequent calls to setup will replace the previous configuration.
185187
number = false,
186188
relativenumber = false,
187189
signcolumn = "yes",
190+
-- @deprecated
188191
mappings = {
189192
custom_only = false,
190193
list = {
191194
-- user mappings go here
192195
},
193196
},
197+
float = {
198+
enable = false,
199+
open_win_config = {
200+
relative = "editor",
201+
border = "rounded",
202+
width = 30,
203+
height = 30,
204+
row = 1,
205+
col = 1,
206+
},
207+
},
194208
},
195209
renderer = {
196210
add_trailing = false,
@@ -628,11 +642,33 @@ Window / buffer setup.
628642
Configuration options for |nvim-tree-mappings|
629643

630644
*nvim-tree.view.mappings.custom_only*
631-
DEPRECATED: see |nvim-tree.remove_keymaps|
632-
645+
Will use only the provided user mappings and not the default otherwise,
646+
extends the default mappings with the provided user mappings.
647+
Type: `boolean`, Default: `false`
633648

634649
*nvim-tree.view.mappings.list*
635-
DEPRECATED: see |nvim-tree.on_attach|
650+
A list of keymaps that will extend or override the default keymaps.
651+
Type: `table`
652+
Default: see |nvim-tree-default-mappings|
653+
654+
*nvim-tree.view.float*
655+
Configuration options for floating window
656+
657+
*nvim-tree.view.float.enable*
658+
Display nvim-tree window as float (enforces |nvim-tree.actions.open_file.quit_on_open| if set).
659+
Type: `boolean`, Default: `false`
660+
661+
*nvim-tree.view.float.open_win_config*
662+
Floating window config. See |nvim_open_win| for more details.
663+
Type: `table`, Default:
664+
`{`
665+
`relative = "editor",`
666+
`border = "rounded",`
667+
`width = 30,`
668+
`height = 30,`
669+
`row = 1,`
670+
`col = 1,`
671+
`}`
636672

637673
*nvim-tree.renderer*
638674
UI rendering setup
@@ -1076,55 +1112,132 @@ exists.
10761112
==============================================================================
10771113
6. MAPPINGS *nvim-tree-mappings*
10781114

1079-
Setting your own mapping in the configuration is deprecated, see |nvim-tree.on_attach| now.
1080-
1081-
You can remove default mappings with |nvim-tree.remove_keymaps|.
1082-
1083-
`<CR>`, `o`, `<2-LeftMouse>` open a file or folder; root will cd to the above directory
1084-
`<C-e>` edit the file in place, effectively replacing the tree explorer
1085-
`O` same as (edit) with no window picker
1086-
`<C-]>`, `<2-RightMouse>` cd in the directory under the cursor
1087-
`<C-v>` open the file in a vertical split
1088-
`<C-x>` open the file in a horizontal split
1089-
`<C-t>` open the file in a new tab
1090-
`<` navigate to the previous sibling of current file/directory
1091-
`>` navigate to the next sibling of current file/directory
1092-
`P` move cursor to the parent directory
1093-
`<BS>` close current opened directory or parent
1094-
`<Tab>` open the file as a preview (keeps the cursor in the tree)
1095-
`K` navigate to the first sibling of current file/directory
1096-
`J` navigate to the last sibling of current file/directory
1097-
`I` toggle visibility of files/folders hidden via |git.ignore| option
1098-
`H` toggle visibility of dotfiles via |filters.dotfiles| option
1099-
`U` toggle visibility of files/folders hidden via |filters.custom| option
1100-
`R` refresh the tree
1101-
`a` add a file; leaving a trailing `/` will add a directory
1102-
`d` delete a file (will prompt for confirmation)
1103-
`D` trash a file via |trash| option
1104-
`r` rename a file
1105-
`<C-r>` rename a file and omit the filename on input
1106-
`x` add/remove file/directory to cut clipboard
1107-
`c` add/remove file/directory to copy clipboard
1108-
`p` paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation
1109-
`y` copy name to system clipboard
1110-
`Y` copy relative path to system clipboard
1111-
`gy` copy absolute path to system clipboard
1112-
`[e` go to next diagnostic item
1113-
`[c` go to next git item
1114-
`]e` go to prev diagnostic item
1115-
`]c` go to prev git item
1116-
`-` navigate up to the parent directory of the current file/directory
1117-
`s` open a file with default system application or a folder with default file manager, using |system_open| option
1118-
`f` live filter nodes dynamically based on regex matching.
1119-
`F` clear live filter
1120-
`q` close tree window
1121-
`W` collapse the whole tree
1122-
`E` expand the whole tree, stopping after expanding |actions.expand_all.max_folder_discovery| folders; this might hang neovim for a while if running on a big folder
1123-
`S` prompt the user to enter a path and then expands the tree to match the path
1124-
`.` enter vim command mode with the file the cursor is on
1125-
`<C-k>` toggle a popup with file infos about the file under the cursor
1126-
`g?` toggle help
1127-
`m` Toggle node in bookmarks
1115+
Setting your own mapping in the configuration will soon be deprecated, see |nvim-tree.on_attach| for experimental replacement.
1116+
1117+
The `list` option in `view.mappings.list` is a table of
1118+
1119+
- `key` can be either a string or a table of string (lhs)
1120+
- `action` is the name of the action, set to `""` to remove default action
1121+
- `action_cb` is the function that will be called, it receives the node as a parameter. Optional for default actions
1122+
- `mode` is normal by default
1123+
>
1124+
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
1125+
1126+
local function print_node_path(node) {
1127+
print(node.absolute_path)
1128+
}
1129+
1130+
local list = {
1131+
{ key = {"<CR>", "o" }, action = "edit", mode = "n"},
1132+
{ key = "p", action = "print_path", action_cb = print_node_path },
1133+
{ key = "s", cb = tree_cb("vsplit") }, --tree_cb and the cb property are deprecated
1134+
{ key = "<2-RightMouse>", action = "" }, -- will remove default cd action
1135+
}
1136+
<
1137+
Mouse support defined in |KeyBindings|
1138+
1139+
DEFAULT MAPPINGS *nvim-tree-default-mappings*
1140+
1141+
`<CR>` edit open a file or folder; root will cd to the above directory
1142+
`o`
1143+
`<2-LeftMouse>`
1144+
`<C-e>` edit_in_place edit the file in place, effectively replacing the tree explorer
1145+
`O` edit_no_picker same as (edit) with no window picker
1146+
`<C-]>` cd cd in the directory under the cursor
1147+
`<2-RightMouse>`
1148+
`<C-v>` vsplit open the file in a vertical split
1149+
`<C-x>` split open the file in a horizontal split
1150+
`<C-t>` tabnew open the file in a new tab
1151+
`<` prev_sibling navigate to the previous sibling of current file/directory
1152+
`>` next_sibling navigate to the next sibling of current file/directory
1153+
`P` parent_node move cursor to the parent directory
1154+
`<BS>` close_node close current opened directory or parent
1155+
`<Tab>` preview open the file as a preview (keeps the cursor in the tree)
1156+
`K` first_sibling navigate to the first sibling of current file/directory
1157+
`J` last_sibling navigate to the last sibling of current file/directory
1158+
`I` toggle_git_ignored toggle visibility of files/folders hidden via |git.ignore| option
1159+
`H` toggle_dotfiles toggle visibility of dotfiles via |filters.dotfiles| option
1160+
`U` toggle_custom toggle visibility of files/folders hidden via |filters.custom| option
1161+
`R` refresh refresh the tree
1162+
`a` create add a file; leaving a trailing `/` will add a directory
1163+
`d` remove delete a file (will prompt for confirmation)
1164+
`D` trash trash a file via |trash| option
1165+
`r` rename rename a file
1166+
`<C-r>` full_rename rename a file and omit the filename on input
1167+
`x` cut add/remove file/directory to cut clipboard
1168+
`c` copy add/remove file/directory to copy clipboard
1169+
`p` paste paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation
1170+
`y` copy_name copy name to system clipboard
1171+
`Y` copy_path copy relative path to system clipboard
1172+
`gy` copy_absolute_path copy absolute path to system clipboard
1173+
`[e` prev_diag_item go to next diagnostic item
1174+
`[c` prev_git_item go to next git item
1175+
`]e` next_diag_item go to prev diagnostic item
1176+
`]c` next_git_item go to prev git item
1177+
`-` dir_up navigate up to the parent directory of the current file/directory
1178+
`s` system_open open a file with default system application or a folder with default file manager, using |system_open| option
1179+
`f` live_filter live filter nodes dynamically based on regex matching.
1180+
`F` clear_live_filter clear live filter
1181+
`q` close close tree window
1182+
`W` collapse_all collapse the whole tree
1183+
`E` expand_all expand the whole tree, stopping after expanding |actions.expand_all.max_folder_discovery| folders; this might hang neovim for a while if running on a big folder
1184+
`S` search_node prompt the user to enter a path and then expands the tree to match the path
1185+
`.` run_file_command enter vim command mode with the file the cursor is on
1186+
`<C-k>` toggle_file_info toggle a popup with file infos about the file under the cursor
1187+
`g?` toggle_help toggle help
1188+
`m` toggle_mark Toggle node in bookmarks
1189+
`bmv` bulk_move Move all bookmarked nodes into specified location
1190+
1191+
>
1192+
view.mappings.list = { -- BEGIN_DEFAULT_MAPPINGS
1193+
{ key = { "<CR>", "o", "<2-LeftMouse>" }, action = "edit" },
1194+
{ key = "<C-e>", action = "edit_in_place" },
1195+
{ key = "O", action = "edit_no_picker" },
1196+
{ key = { "<C-]>", "<2-RightMouse>" }, action = "cd" },
1197+
{ key = "<C-v>", action = "vsplit" },
1198+
{ key = "<C-x>", action = "split" },
1199+
{ key = "<C-t>", action = "tabnew" },
1200+
{ key = "<", action = "prev_sibling" },
1201+
{ key = ">", action = "next_sibling" },
1202+
{ key = "P", action = "parent_node" },
1203+
{ key = "<BS>", action = "close_node" },
1204+
{ key = "<Tab>", action = "preview" },
1205+
{ key = "K", action = "first_sibling" },
1206+
{ key = "J", action = "last_sibling" },
1207+
{ key = "I", action = "toggle_git_ignored" },
1208+
{ key = "H", action = "toggle_dotfiles" },
1209+
{ key = "U", action = "toggle_custom" },
1210+
{ key = "R", action = "refresh" },
1211+
{ key = "a", action = "create" },
1212+
{ key = "d", action = "remove" },
1213+
{ key = "D", action = "trash" },
1214+
{ key = "r", action = "rename" },
1215+
{ key = "<C-r>", action = "full_rename" },
1216+
{ key = "x", action = "cut" },
1217+
{ key = "c", action = "copy" },
1218+
{ key = "p", action = "paste" },
1219+
{ key = "y", action = "copy_name" },
1220+
{ key = "Y", action = "copy_path" },
1221+
{ key = "gy", action = "copy_absolute_path" },
1222+
{ key = "[e", action = "prev_diag_item" },
1223+
{ key = "[c", action = "prev_git_item" },
1224+
{ key = "]e", action = "next_diag_item" },
1225+
{ key = "]c", action = "next_git_item" },
1226+
{ key = "-", action = "dir_up" },
1227+
{ key = "s", action = "system_open" },
1228+
{ key = "f", action = "live_filter" },
1229+
{ key = "F", action = "clear_live_filter" },
1230+
{ key = "q", action = "close" },
1231+
{ key = "W", action = "collapse_all" },
1232+
{ key = "E", action = "expand_all" },
1233+
{ key = "S", action = "search_node" },
1234+
{ key = ".", action = "run_file_command" },
1235+
{ key = "<C-k>", action = "toggle_file_info" },
1236+
{ key = "g?", action = "toggle_help" },
1237+
{ key = "m", action = "toggle_mark" },
1238+
{ key = "bmv", action = "bulk_move" },
1239+
} -- END_DEFAULT_MAPPINGS
1240+
<
11281241

11291242
==============================================================================
11301243
7. HIGHLIGHT GROUPS *nvim-tree-highlight*

lua/nvim-tree.lua

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ local function setup_autocommands(opts)
414414
end,
415415
})
416416
end
417+
418+
if opts.view.float.enable then
419+
create_nvim_tree_autocmd("WinLeave", { pattern = "NvimTree_*", callback = view.close })
420+
end
417421
end
418422

419423
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
@@ -447,13 +451,23 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
447451
number = false,
448452
relativenumber = false,
449453
signcolumn = "yes",
450-
-- @deprecated
451454
mappings = {
452455
custom_only = false,
453456
list = {
454457
-- user mappings go here
455458
},
456459
},
460+
float = {
461+
enable = false,
462+
open_win_config = {
463+
relative = "editor",
464+
border = "rounded",
465+
width = 30,
466+
height = 30,
467+
row = 1,
468+
col = 1,
469+
},
470+
},
457471
},
458472
renderer = {
459473
add_trailing = false,
@@ -606,6 +620,10 @@ local function merge_options(conf)
606620
return vim.tbl_deep_extend("force", DEFAULT_OPTS, conf or {})
607621
end
608622

623+
local FIELD_SKIP_VALIDATE = {
624+
open_win_config = true,
625+
}
626+
609627
local FIELD_OVERRIDE_TYPECHECK = {
610628
width = { string = true, ["function"] = true, number = true },
611629
height = { string = true, ["function"] = true, number = true },
@@ -623,25 +641,27 @@ local function validate_options(conf)
623641
end
624642

625643
for k, v in pairs(user) do
626-
local invalid
627-
local override_typecheck = FIELD_OVERRIDE_TYPECHECK[k] or {}
628-
if def[k] == nil then
629-
-- option does not exist
630-
invalid = string.format("unknown option: %s%s", prefix, k)
631-
elseif type(v) ~= type(def[k]) and not override_typecheck[type(v)] then
632-
-- option is of the wrong type and is not a function
633-
invalid = string.format("invalid option: %s%s expected: %s actual: %s", prefix, k, type(def[k]), type(v))
634-
end
644+
if not FIELD_SKIP_VALIDATE[k] then
645+
local invalid
646+
local override_typecheck = FIELD_OVERRIDE_TYPECHECK[k] or {}
647+
if def[k] == nil then
648+
-- option does not exist
649+
invalid = string.format("unknown option: %s%s", prefix, k)
650+
elseif type(v) ~= type(def[k]) and not override_typecheck[type(v)] then
651+
-- option is of the wrong type and is not a function
652+
invalid = string.format("invalid option: %s%s expected: %s actual: %s", prefix, k, type(def[k]), type(v))
653+
end
635654

636-
if invalid then
637-
if msg then
638-
msg = string.format("%s | %s", msg, invalid)
655+
if invalid then
656+
if msg then
657+
msg = string.format("%s | %s", msg, invalid)
658+
else
659+
msg = string.format("%s", invalid)
660+
end
661+
user[k] = nil
639662
else
640-
msg = string.format("%s", invalid)
663+
validate(v, def[k], prefix .. k .. ".")
641664
end
642-
user[k] = nil
643-
else
644-
validate(v, def[k], prefix .. k .. ".")
645665
end
646666
end
647667
end

lua/nvim-tree/actions/node/open-file.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ function M.fn(mode, filename)
280280
end
281281

282282
function M.setup(opts)
283-
M.quit_on_open = opts.actions.open_file.quit_on_open
283+
M.quit_on_open = opts.actions.open_file.quit_on_open or opts.view.float.enable
284284
M.resize_window = opts.actions.open_file.resize_window
285285
if opts.actions.open_file.window_picker.chars then
286286
opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper()

lua/nvim-tree/git/utils.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function M.get_toplevel(cwd)
1414
log.raw("git", toplevel)
1515
log.profile_end(ps, "git toplevel %s", cwd)
1616

17-
if not toplevel or #toplevel == 0 or toplevel:match "fatal" then
17+
if vim.v.shell_error ~= 0 or not toplevel or #toplevel == 0 or toplevel:match "fatal" then
1818
return nil
1919
end
2020

@@ -23,6 +23,9 @@ function M.get_toplevel(cwd)
2323
-- msys2 git support
2424
if has_cygpath then
2525
toplevel = vim.fn.system("cygpath -w " .. vim.fn.shellescape(toplevel))
26+
if vim.v.shell_error ~= 0 then
27+
return nil
28+
end
2629
end
2730
toplevel = toplevel:gsub("/", "\\")
2831
end

lua/nvim-tree/view.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,12 @@ local function set_window_options_and_buffer()
134134
end
135135

136136
local function open_window()
137-
a.nvim_command "vsp"
138-
M.reposition_window()
137+
if M.View.float.enable then
138+
a.nvim_open_win(0, true, M.View.float.open_win_config)
139+
else
140+
a.nvim_command "vsp"
141+
M.reposition_window()
142+
end
139143
setup_tabpage(a.nvim_get_current_tabpage())
140144
set_window_options_and_buffer()
141145
end
@@ -431,6 +435,7 @@ function M.setup(opts)
431435
M.View.winopts.number = options.number
432436
M.View.winopts.relativenumber = options.relativenumber
433437
M.View.winopts.signcolumn = options.signcolumn
438+
M.View.float = options.float
434439
M.on_attach = opts.on_attach
435440
end
436441

0 commit comments

Comments
 (0)