Skip to content

chore(mappings): remove mappings #1777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ assignees: ''
**Is this a question?**
Please start a new [Q&A discussion](https://github.com/nvim-tree/nvim-tree.lua/discussions/new) instead of raising a feature request.

**Can this functionality be implemented utilising API?**
nvim-tree exposes extensive API (see `:h nvim-tree-api`). Can it be used to achieve your goal? Is there a missing API that would make it possible?
Given stable status of nvim-tree it's preferred to add new API than new functionality.

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Take a look at the [wiki](https://github.com/nvim-tree/nvim-tree.lua/wiki) for S

[neovim >=0.7.0](https://github.com/neovim/neovim/wiki/Installing-Neovim)

[nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) is optional and used to display file icons. It requires a [patched font](https://www.nerdfonts.com/).
[nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) is optional and used to display file icons. It requires a [patched font](https://www.nerdfonts.com/). Your terminal emulator must be configured to use that font, usually "Hack Nerd Font"

## Install

Expand Down
86 changes: 52 additions & 34 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ Features

File Icons

https://github.com/nvim-tree/nvim-web-devicons is optional and used to display file icons. It requires a patched font: https://www.nerdfonts.com
https://github.com/nvim-tree/nvim-web-devicons is optional and used to display file icons.
It requires a patched font: https://www.nerdfonts.com
Your terminal emulator must be configured to use that font, usually "Hack Nerd Font"

 should look like an open folder.

Expand Down Expand Up @@ -169,7 +171,6 @@ Subsequent calls to setup will replace the previous configuration.
>
require("nvim-tree").setup { -- BEGIN_DEFAULT_OPTS
auto_reload_on_write = true,
create_in_closed_folder = false,
disable_netrw = false,
hijack_cursor = false,
hijack_netrw = true,
Expand Down Expand Up @@ -290,10 +291,11 @@ Subsequent calls to setup will replace the previous configuration.
diagnostics = {
enable = false,
show_on_dirs = false,
show_on_open_dirs = true,
debounce_delay = 50,
severity = {
min = vim.diagnostic.severity.HINT,
max = vim.diagnostic.severity.ERROR
max = vim.diagnostic.severity.ERROR,
},
icons = {
hint = "",
Expand All @@ -304,6 +306,8 @@ Subsequent calls to setup will replace the previous configuration.
},
filters = {
dotfiles = false,
git_clean = false,
no_buffer = false,
custom = {},
exclude = {},
},
Expand All @@ -316,6 +320,7 @@ Subsequent calls to setup will replace the previous configuration.
enable = true,
ignore = true,
show_on_dirs = true,
show_on_open_dirs = true,
timeout = 400,
},
actions = {
Expand Down Expand Up @@ -430,11 +435,6 @@ in some scenarios (eg using vim startify).
Reloads the explorer every time a buffer is written to.
Type: `boolean`, Default: `true`

*nvim-tree.create_in_closed_folder*
Creating a file when the cursor is on a closed folder will set the
path to be inside the closed folder, otherwise the parent folder.
Type: `boolean`, Default: `false`

*nvim-tree.sort_by*
Changes how files within the same directory are sorted.
Can be one of `name`, `case_sensitive`, `modification_time`, `extension` or a
Expand Down Expand Up @@ -555,6 +555,11 @@ Show LSP and COC diagnostics in the signcolumn
Show diagnostic icons on parent directories.
Type: `boolean`, Default: `false`

*nvim-tree.diagnostics.show_on_open_dirs*
Show diagnostics icons on directories that are open.
Only relevant when `diagnostics.show_on_dirs` is `true`.
Type: `boolean`, Default: `true`

*nvim-tree.diagnostics.icons*
Icons for diagnostic severity.
Type: `table`, Default: `{ hint = "", info = "", warning = "", error = "" }`
Expand Down Expand Up @@ -586,6 +591,11 @@ Git integration with icons and colors.
Show status icons of children when directory itself has no status icon.
Type: `boolean`, Default: `true`

*nvim-tree.git.show_on_open_dirs*
Show status icons on directories that are open.
Only relevant when `git.show_on_dirs` is `true`.
Type: `boolean`, Default: `true`

*nvim-tree.git.timeout*
Kills the git process after some time if it takes too long.
Type: `number`, Default: `400` (ms)
Expand Down Expand Up @@ -627,16 +637,14 @@ Function ran when creating the nvim-tree buffer.
This can be used to attach keybindings to the tree buffer.
When on_attach is not a function, |nvim-tree.view.mappings| will be used.
Type: `function(bufnr)`, Default: `"disable"`
e.g. >
local api = require('nvim-tree.api')

Example: >
local Api = require('nvim-tree.api')
local Lib = require('nvim-tree.lib')

local my_on_attach = function(bufnr)
vim.keymap.set('n', '?', Api.tree.toggle_help, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = 'Help' })
vim.keymap.set('n', 'h', Api.tree.toggle_help, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = 'Help' })
local function on_attach(bufnr)
vim.keymap.set('n', '?', api.tree.toggle_help, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = 'Help' })
vim.keymap.set('n', 'h', api.tree.toggle_help, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = 'Help' })
vim.keymap.set("n", "<C-P>", function()
local node = Lib.get_node_at_cursor()
local node = api.tree.get_node_under_cursor()
print(node.absolute_path)
end, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = "my description" })
end
Expand Down Expand Up @@ -704,6 +712,7 @@ Window / buffer setup.
*nvim-tree.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.
Overrides |nvim-tree.remove_keymaps|
Type: `boolean`, Default: `false`

*nvim-tree.view.mappings.list*
Expand Down Expand Up @@ -888,6 +897,19 @@ Filtering options.
Toggle via the `toggle_dotfiles` action, default mapping `H`.
Type: `boolean`, Default: `false`

*nvim-tree.filters.git_clean*
Do not show files with no git status. This will show ignored files when
|nvim-tree.git.ignore| is set, as they are effectively dirty.
Toggle via the `toggle_git_clean` action, default mapping `C`.
Type: `boolean`, Default: `false`

*nvim-tree.filters.no_buffer*
Do not show files that have no listed buffer.
Toggle via the `toggle_no_buffer` action, default mapping `B`.
For performance reasons this may not immediately update on buffer
delete/wipe. A reload or filesystem event will result in an update.
Type: `boolean`, Default: `false`

*nvim-tree.filters.custom*
Custom list of vim regex for file/directory names that will not be shown.
Backslashes must be escaped e.g. "^\\.git". See |string-match|.
Expand Down Expand Up @@ -1142,15 +1164,15 @@ A good functionality to enable is |nvim-tree.hijack_directories|.

Nvim-tree's public API can be used to access features.
>
local nt_api = require("nvim-tree.api")

nt_api.tree.toggle()
e.g. >
local api = require("nvim-tree.api")
api.tree.toggle()
<
This module exposes stable functionalities, it is advised to use this in order
to avoid breaking configurations due to internal breaking changes.

The api is separated in multiple modules, which can be accessed with
`require("nvim-tree.api").moduleName.functionality`.
`api.<module>.<function>`

Functions that needs a tree node parameter are exposed with an abstraction
that injects the node from the cursor position in the tree when calling
Expand All @@ -1173,6 +1195,8 @@ exists.
- collapse_all `(keep_buffers?: bool)`
- expand_all
- toggle_gitignore_filter
- toggle_git_clean_filter
- toggle_no_buffer_filter
- toggle_custom_filter
- toggle_hidden_filter
- toggle_help
Expand Down Expand Up @@ -1294,7 +1318,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings
`O` Open: No Window Picker Open file with no window picker.
`<C-]>` CD cd in the directory under the cursor.
`<2-RightMouse>`
`<ctrL-v>` Open: Vertical Split Open file in a vertical split.
`<C-v>` Open: Vertical Split Open file in a vertical split.
`<C-x>` Open: Horizontal Split Open file in a horizontal split.
`<C-t>` Open: New Tab Open file in a new tab.
`<` Previous Sibling Navigate to the previous sibling.
Expand Down Expand Up @@ -1348,7 +1372,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings
vim.keymap.set('n', 'O', Api.node.open.no_window_picker, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = 'Open: No Window Picker', })
vim.keymap.set('n', '<C-]>', Api.tree.change_root_to_node, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = 'CD', })
vim.keymap.set('n', '<2-RightMouse>', Api.tree.change_root_to_node, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = 'CD', })
vim.keymap.set('n', '<ctrL-v>', Api.node.open.vertical, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = 'Open: Vertical Split', })
vim.keymap.set('n', '<C-v>', Api.node.open.vertical, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = 'Open: Vertical Split', })
vim.keymap.set('n', '<C-x>', Api.node.open.horizontal, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = 'Open: Horizontal Split', })
vim.keymap.set('n', '<C-t>', Api.node.open.tab, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = 'Open: New Tab', })
vim.keymap.set('n', '<', Api.node.navigate.sibling.prev, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = 'Previous Sibling', })
Expand Down Expand Up @@ -1416,6 +1440,8 @@ NvimTreeSymlink
NvimTreeFolderName (Directory)
NvimTreeRootFolder
NvimTreeFolderIcon
NvimTreeOpenedFolderIcon (NvimTreeFolderIcon)
NvimTreeClosedFolderIcon (NvimTreeFolderIcon)
NvimTreeFileIcon
NvimTreeEmptyFolderName (Directory)
NvimTreeOpenedFolderName (Directory)
Expand Down Expand Up @@ -1487,27 +1513,19 @@ to |nvim_tree_registering_handlers| for more information.

|nvim_tree_registering_handlers|

Handlers are registered by calling the `events.subscribe` function available in the
`require("nvim-tree.api")` module.
Handlers are registered by calling |nvim-tree-api| `events.subscribe`
function with an `events.Event` kind.

For example, registering a handler for when a node is renamed is done like this:
>
local api = require('nvim-tree.api')
e.g. handler for node renamed: >
local api = require("nvim-tree.api")
local Event = api.events.Event

api.events.subscribe(Event.NodeRenamed, function(data)
print("Node renamed from " .. data.old_name .. " to " .. data.new_name)
end)
<

|nvim_tree_events_kind|

You can access the event enum with:
>
local Event = require('nvim-tree.api').events.Event
<
Here is the list of available variant of this enum:

- Event.Ready
When NvimTree has been initialized
• Note: Handler takes no parameter.
Expand Down
24 changes: 22 additions & 2 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local reloaders = require "nvim-tree.actions.reloaders.reloaders"
local copy_paste = require "nvim-tree.actions.fs.copy-paste"
local collapse_all = require "nvim-tree.actions.tree-modifiers.collapse-all"
local git = require "nvim-tree.git"
local filters = require "nvim-tree.explorer.filters"

local _config = {}

Expand Down Expand Up @@ -351,6 +352,22 @@ local function setup_autocommands(opts)
create_nvim_tree_autocmd("BufWritePost", { callback = reloaders.reload_explorer })
end

create_nvim_tree_autocmd("BufReadPost", {
callback = function()
if filters.config.filter_no_buffer then
reloaders.reload_explorer()
end
end,
})

create_nvim_tree_autocmd("BufUnload", {
callback = function(data)
if filters.config.filter_no_buffer then
reloaders.reload_explorer(nil, data.buf)
end
end,
})

if not has_watchers and opts.git.enable then
create_nvim_tree_autocmd("User", {
pattern = { "FugitiveChanged", "NeogitStatusRefreshed" },
Expand Down Expand Up @@ -445,7 +462,6 @@ end

local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
auto_reload_on_write = true,
create_in_closed_folder = false,
disable_netrw = false,
hijack_cursor = false,
hijack_netrw = true,
Expand Down Expand Up @@ -566,6 +582,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
diagnostics = {
enable = false,
show_on_dirs = false,
show_on_open_dirs = true,
debounce_delay = 50,
severity = {
min = vim.diagnostic.severity.HINT,
Expand All @@ -580,6 +597,8 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
},
filters = {
dotfiles = false,
git_clean = false,
no_buffer = false,
custom = {},
exclude = {},
},
Expand All @@ -592,6 +611,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
enable = true,
ignore = true,
show_on_dirs = true,
show_on_open_dirs = true,
timeout = 400,
},
actions = {
Expand Down Expand Up @@ -757,7 +777,7 @@ function M.setup(conf)
log.line("config", "default config + user")
log.raw("config", "%s\n", vim.inspect(opts))

legacy.move_mappings_to_keymap(opts)
legacy.generate_legacy_on_attach(opts)

require("nvim-tree.actions").setup(opts)
require("nvim-tree.keymap").setup(opts)
Expand Down
4 changes: 3 additions & 1 deletion lua/nvim-tree/actions/finders/search-node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ local function search(search_dir, input_path)
local function iter(dir)
local realpath, path, name, stat, handle, _

local filter_status = filters.prepare()

handle, _ = vim.loop.fs_scandir(dir)
if not handle then
return
Expand All @@ -34,7 +36,7 @@ local function search(search_dir, input_path)
break
end

if not filters.should_ignore(path) then
if not filters.should_filter(path, filter_status) then
if string.find(path, "/" .. input_path .. "$") then
return path
end
Expand Down
5 changes: 2 additions & 3 deletions lua/nvim-tree/actions/fs/copy-paste.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local lib = require "nvim-tree.lib"
local log = require "nvim-tree.log"
local utils = require "nvim-tree.utils"
local core = require "nvim-tree.core"
local events = require "nvim-tree.events"
local notify = require "nvim-tree.notify"

local M = {}
Expand Down Expand Up @@ -160,11 +161,8 @@ local function do_paste(node, action_type, action_fn)
return
end
local is_dir = stats and stats.type == "directory"

if not is_dir then
destination = vim.fn.fnamemodify(destination, ":p:h")
elseif not node.open then
destination = vim.fn.fnamemodify(destination, ":p:h:h")
end

for _, _node in ipairs(clip) do
Expand Down Expand Up @@ -192,6 +190,7 @@ local function do_cut(source, destination)
return false, errmsg
end
utils.rename_loaded_buffers(source, destination)
events._dispatch_node_renamed(source, destination)
return true
end

Expand Down
4 changes: 1 addition & 3 deletions lua/nvim-tree/actions/fs/create-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ local function get_num_nodes(iter)
end

local function get_containing_folder(node)
local is_open = M.create_in_closed_folder or node.open
if node.nodes ~= nil and is_open then
if node.nodes ~= nil then
return utils.path_add_trailing(node.absolute_path)
end
local node_name_size = #(node.name or "")
Expand Down Expand Up @@ -113,7 +112,6 @@ function M.fn(node)
end

function M.setup(opts)
M.create_in_closed_folder = opts.create_in_closed_folder
M.enable_reload = not opts.filesystem_watchers.enable
end

Expand Down
3 changes: 2 additions & 1 deletion lua/nvim-tree/actions/moves/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local utils = require "nvim-tree.utils"
local view = require "nvim-tree.view"
local core = require "nvim-tree.core"
local lib = require "nvim-tree.lib"
local explorer_common = require "nvim-tree.explorer.common"

local M = {}

Expand All @@ -14,7 +15,7 @@ function M.fn(where, what)
for line, node in pairs(nodes_by_line) do
local valid = false
if what == "git" then
valid = node.git_status ~= nil
valid = explorer_common.shows_git_status(node)
elseif what == "diag" then
valid = node.diag_status ~= nil
end
Expand Down
Loading