feat: automated migration from view.mappings.list to on_attach, see https://github.com/nvim-tree/nvim-tree.lua/wiki/Migrating-To-on_attach (#1579)
* chore(mappings): migrate legacy mappings under the hood
* chore(mappings): POC for help and :help on_attach keymaps
* chore(mappings): POC for help and :help on_attach keymaps
* chore(mappings): add desc to all mappings, show in help, reformat help
* chore(mappings): add desc to all mappings
* chore(mappings): add desc to all mappings
* chore(mappings): escape help keys
* chore(mappings): migrate legacy mappings under the hood: map keymap to legacy mappings
* chore(mappings): migrate legacy mappings under the hood: remove dispatch
* Revert "chore(mappings): migrate legacy mappings under the hood: remove dispatch"
This reverts commit f6f439ba59.
* chore(mappings): migrate legacy mappings under the hood: pass node to action_cb
* chore(mappings): migrate legacy mappings under the hood: remove dispatch
* chore(mappings): migrate legacy mappings under the hood: replace mappigns with keymaps in help
* chore(mappings): generate on_attach from user's legacy mappings
* chore(mappings): generate on_attach from user's legacy mappings
* chore(mappings): merge cleanup
* chore(mappings): use default mappings when on_attach not present, log legacy migration
* on_attach is default or user only, legacy and generation includes defaults (#1777)
* chore(mappings): remove mappings via vim.keymap.del instead of filtering mappings, to allow for multiple ways of specifying a key
* doc: specify that the terminal emulator must be configured to use the patched font
* feat(renderer): add NvimTreeOpenedFolderIcon NvimTreeClosedFolderIcon (#1768)
* feat: Add highlight group for opened folder
closes #1674
* docs: Add NvimTreeOpenedFolderIcon default
* feat: Add NvimTreeClosedFolderIcon highlight group
Defaults to NvimTreeFolderIcon
* feat: add diagnostics.show_on_open_dirs git.show_on_open_dirs (#1778)
* feat(diagnostics): only show diagnostic on closed folder
* feat(git): only show git icon on closed folder
* docs: Update feature_request.md (#1788)
* Update feature_request.md
Closes #1654
* Update feature_request.md
Co-authored-by: Alexander Courtis <alex@courtis.org>
* 1786 git next prev land on dirs (#1787)
* Filtered dir with git status that are open when show_on_open_dir is false
* refactored for single source of truth of existence of git status on a node
Putting `has_git_status()` in `explorer.common` because that's where node.status is constructed
Or at least I think that's where it's constructed
* 1786 semantic nit
Co-authored-by: Alexander Courtis <alex@courtis.org>
* fix(git): git rename not showing up for the renamed file (#1783)
* fixed git rename not showing up for the renamed file
* considered " -> " being a part of the filename
Fixed -> pattern to escape -
Fixed "\"" and "\\" in filename
* using string.find(, , true) to match plain ->
* Using -z and removed unnecessary logic
* feat(view): always enable cursorline, users may change this behaviour via Event.TreeOpen (#1814)
* Update view.lua
* set cursorline to true
* feat(event): dispatch Event.NodeRenamed on cut-paste (#1817)
* feat(view): add filters.git_clean, filters.no_buffer (#1784)
* feat(view): add filters.git_clean
* feat(view): add filters.git_clean
* feat(view): add filters.no_buffer
* feat(view): filters.no_buffer misses unloaded, handles buffer in/out
* feat(view): filters.no_buffer matches directories specifically
* feat(view): filters.no_buffer clarify targets
* feat: add placeholder filters.diagnostics_ok, refactor filters
* feat(view): remove placeholder filters.diagnostics_ok
* doc: consolidate and clarify :help examples
* doc: format help
* feat: paste and create always target closed folder, remove create_in_closed_folder (#1802)
* Fix default for file creation in closed directories
* Make paste in closed directories consistent with create
* doc: clarify create_in_closed_folder
* Remove create_in_closed_folder option
* doc: clarify create_in_closed_folder removal message (whoops)
Co-authored-by: Alexander Courtis <alex@courtis.org>
* on_attach is user's or default, nothing else; legacy generated on_attach includes defaults
Co-authored-by: baahrens <bahrens@compeon.de>
Co-authored-by: Richard Li <38484873+chomosuke@users.noreply.github.com>
Co-authored-by: gegoune <69750637+gegoune@users.noreply.github.com>
Co-authored-by: rishabhjain9191 <rishabh.jain9191@gmail.com>
Co-authored-by: Anton <14187674+antosha417@users.noreply.github.com>
Co-authored-by: Eric Haynes <ehaynes99@gmail.com>
* on_attach_default hardcoded
* format default_on_attach
* source default on_attach directly
* remove human mappings help
* simplified on_attach generation
* simplified on_attach generation
* generate default on_attach
* generate default on_attach
* split out keymap_legacy
* add recently introduced mappings
* legacy api.config.mappings.active and default
* legacy api.config.mappings.active and default
* on_attach help and readme
* legacy generate handles action = ""
* legacy generate handles action =
* legacy generate gives defaults when no user mappings
* legacy generate handles action = ""
* legacy generate api handles overrides
* legacy generate handles subsequent setup, on_attach retains deep copies of legacy config
* add wiki link to generated on_attach
* add opts helper function for on_attach, prefixing 'nvim-tree: '
---------
Co-authored-by: kiyan <yazdani.kiyan@protonmail.com>
Co-authored-by: baahrens <bahrens@compeon.de>
Co-authored-by: Richard Li <38484873+chomosuke@users.noreply.github.com>
Co-authored-by: gegoune <69750637+gegoune@users.noreply.github.com>
Co-authored-by: rishabhjain9191 <rishabh.jain9191@gmail.com>
Co-authored-by: Anton <14187674+antosha417@users.noreply.github.com>
Co-authored-by: Eric Haynes <ehaynes99@gmail.com>
This commit is contained in:
committed by
GitHub
parent
9c97e6449b
commit
74959750f7
@@ -1,290 +1,76 @@
|
||||
local Api = require "nvim-tree.api"
|
||||
local api = require "nvim-tree.api"
|
||||
|
||||
local M = {}
|
||||
|
||||
local DEFAULT_KEYMAPS = {
|
||||
{
|
||||
key = { "<CR>", "o", "<2-LeftMouse>" },
|
||||
callback = Api.node.open.edit,
|
||||
desc = "open a file or folder; root will cd to the above directory",
|
||||
},
|
||||
{
|
||||
key = "<C-e>",
|
||||
callback = Api.node.open.replace_tree_buffer,
|
||||
desc = "edit the file in place, effectively replacing the tree explorer",
|
||||
},
|
||||
{
|
||||
key = "O",
|
||||
callback = Api.node.open.no_window_picker,
|
||||
desc = "same as (edit) with no window picker",
|
||||
},
|
||||
{
|
||||
key = { "<C-]>", "<2-RightMouse>" },
|
||||
callback = Api.tree.change_root_to_node,
|
||||
desc = "cd in the directory under the cursor",
|
||||
},
|
||||
{
|
||||
key = "<C-v>",
|
||||
callback = Api.node.open.vertical,
|
||||
desc = "open the file in a vertical split",
|
||||
},
|
||||
{
|
||||
key = "<C-x>",
|
||||
callback = Api.node.open.horizontal,
|
||||
desc = "open the file in a horizontal split",
|
||||
},
|
||||
{
|
||||
key = "<C-t>",
|
||||
callback = Api.node.open.tab,
|
||||
desc = "open the file in a new tab",
|
||||
},
|
||||
{
|
||||
key = "<",
|
||||
callback = Api.node.navigate.sibling.prev,
|
||||
desc = "navigate to the previous sibling of current file/directory",
|
||||
},
|
||||
{
|
||||
key = ">",
|
||||
callback = Api.node.navigate.sibling.next,
|
||||
desc = "navigate to the next sibling of current file/directory",
|
||||
},
|
||||
{
|
||||
key = "P",
|
||||
callback = Api.node.navigate.parent,
|
||||
desc = "move cursor to the parent directory",
|
||||
},
|
||||
{
|
||||
key = "<BS>",
|
||||
callback = Api.node.navigate.parent_close,
|
||||
desc = "close current opened directory or parent",
|
||||
},
|
||||
{
|
||||
key = "<Tab>",
|
||||
callback = Api.node.open.preview,
|
||||
desc = "open the file as a preview (keeps the cursor in the tree)",
|
||||
},
|
||||
{
|
||||
key = "K",
|
||||
callback = Api.node.navigate.sibling.first,
|
||||
desc = "navigate to the first sibling of current file/directory",
|
||||
},
|
||||
{
|
||||
key = "J",
|
||||
callback = Api.node.navigate.sibling.last,
|
||||
desc = "navigate to the last sibling of current file/directory",
|
||||
},
|
||||
{
|
||||
key = "I",
|
||||
callback = Api.tree.toggle_gitignore_filter,
|
||||
desc = "toggle visibility of files/folders hidden via |git.ignore| option",
|
||||
},
|
||||
{
|
||||
key = "H",
|
||||
callback = Api.tree.toggle_hidden_filter,
|
||||
desc = "toggle visibility of dotfiles via |filters.dotfiles| option",
|
||||
},
|
||||
{
|
||||
key = "U",
|
||||
callback = Api.tree.toggle_custom_filter,
|
||||
desc = "toggle visibility of files/folders hidden via |filters.custom| option",
|
||||
},
|
||||
{
|
||||
key = "R",
|
||||
callback = Api.tree.reload,
|
||||
desc = "refresh the tree",
|
||||
},
|
||||
{
|
||||
key = "a",
|
||||
callback = Api.fs.create,
|
||||
desc = "add a file; leaving a trailing `/` will add a directory",
|
||||
},
|
||||
{
|
||||
key = "d",
|
||||
callback = Api.fs.remove,
|
||||
desc = "delete a file (will prompt for confirmation)",
|
||||
},
|
||||
{
|
||||
key = "D",
|
||||
callback = Api.fs.trash,
|
||||
desc = "trash a file via |trash| option",
|
||||
},
|
||||
{
|
||||
key = "r",
|
||||
callback = Api.fs.rename,
|
||||
desc = "rename a file",
|
||||
},
|
||||
{
|
||||
key = "<C-r>",
|
||||
callback = Api.fs.rename_sub,
|
||||
desc = "rename a file and omit the filename on input",
|
||||
},
|
||||
{
|
||||
key = "x",
|
||||
callback = Api.fs.cut,
|
||||
desc = "add/remove file/directory to cut clipboard",
|
||||
},
|
||||
{
|
||||
key = "c",
|
||||
callback = Api.fs.copy.node,
|
||||
desc = "add/remove file/directory to copy clipboard",
|
||||
},
|
||||
{
|
||||
key = "p",
|
||||
callback = Api.fs.paste,
|
||||
desc = "paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation",
|
||||
},
|
||||
{
|
||||
key = "y",
|
||||
callback = Api.fs.copy.filename,
|
||||
desc = "copy name to system clipboard",
|
||||
},
|
||||
{
|
||||
key = "Y",
|
||||
callback = Api.fs.copy.relative_path,
|
||||
desc = "copy relative path to system clipboard",
|
||||
},
|
||||
{
|
||||
key = "gy",
|
||||
callback = Api.fs.copy.absolute_path,
|
||||
desc = "copy absolute path to system clipboard",
|
||||
},
|
||||
{
|
||||
key = "]e",
|
||||
callback = Api.node.navigate.diagnostics.next,
|
||||
desc = "go to next diagnostic item",
|
||||
},
|
||||
{
|
||||
key = "]c",
|
||||
callback = Api.node.navigate.git.next,
|
||||
desc = "go to next git item",
|
||||
},
|
||||
{
|
||||
key = "[e",
|
||||
callback = Api.node.navigate.diagnostics.prev,
|
||||
desc = "go to prev diagnostic item",
|
||||
},
|
||||
{
|
||||
key = "[c",
|
||||
callback = Api.node.navigate.git.prev,
|
||||
desc = "go to prev git item",
|
||||
},
|
||||
{
|
||||
key = "-",
|
||||
callback = Api.tree.change_root_to_parent,
|
||||
desc = "navigate up to the parent directory of the current file/directory",
|
||||
},
|
||||
{
|
||||
key = "s",
|
||||
callback = Api.node.run.system,
|
||||
desc = "open a file with default system application or a folder with default file manager, using |system_open| option",
|
||||
},
|
||||
{
|
||||
key = "f",
|
||||
callback = Api.live_filter.start,
|
||||
desc = "live filter nodes dynamically based on regex matching.",
|
||||
},
|
||||
{
|
||||
key = "F",
|
||||
callback = Api.live_filter.clear,
|
||||
desc = "clear live filter",
|
||||
},
|
||||
{
|
||||
key = "q",
|
||||
callback = Api.tree.close,
|
||||
desc = "close tree window",
|
||||
},
|
||||
{
|
||||
key = "W",
|
||||
callback = Api.tree.collapse_all,
|
||||
desc = "collapse the whole tree",
|
||||
},
|
||||
{
|
||||
key = "E",
|
||||
callback = Api.tree.expand_all,
|
||||
desc = "expand the whole tree, stopping after expanding |callbacks.expand_all.max_folder_discovery| folders; this might hang neovim for a while if running on a big folder",
|
||||
},
|
||||
{
|
||||
key = "S",
|
||||
callback = Api.tree.search_node,
|
||||
desc = "prompt the user to enter a path and then expands the tree to match the path",
|
||||
},
|
||||
{
|
||||
key = ".",
|
||||
callback = Api.node.run.cmd,
|
||||
desc = "enter vim command mode with the file the cursor is on",
|
||||
},
|
||||
{
|
||||
key = "<C-k>",
|
||||
callback = Api.node.show_info_popup,
|
||||
desc = "toggle a popup with file infos about the file under the cursor",
|
||||
},
|
||||
{
|
||||
key = "g?",
|
||||
callback = Api.tree.toggle_help,
|
||||
desc = "toggle help",
|
||||
},
|
||||
{
|
||||
key = "m",
|
||||
callback = Api.marks.toggle,
|
||||
desc = "Toggle node in bookmarks",
|
||||
},
|
||||
{
|
||||
key = "bmv",
|
||||
callback = Api.marks.bulk.move,
|
||||
desc = "Move all bookmarked nodes into specified location",
|
||||
},
|
||||
}
|
||||
|
||||
function M.set_keymaps(bufnr)
|
||||
local opts = { noremap = true, silent = true, nowait = true, buffer = bufnr }
|
||||
for _, km in ipairs(M.keymaps) do
|
||||
local keys = type(km.key) == "table" and km.key or { km.key }
|
||||
for _, key in ipairs(keys) do
|
||||
vim.keymap.set("n", key, km.callback, opts)
|
||||
end
|
||||
-- stylua: ignore start
|
||||
function M.default_on_attach(bufnr)
|
||||
-- BEGIN_DEFAULT_ON_ATTACH
|
||||
local opts = function(desc)
|
||||
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
|
||||
end
|
||||
|
||||
vim.keymap.set('n', '<C-]>', api.tree.change_root_to_node, opts('CD'))
|
||||
vim.keymap.set('n', '<C-e>', api.node.open.replace_tree_buffer, opts('Open: In Place'))
|
||||
vim.keymap.set('n', '<C-k>', api.node.show_info_popup, opts('Info'))
|
||||
vim.keymap.set('n', '<C-r>', api.fs.rename_sub, opts('Rename: Omit Filename'))
|
||||
vim.keymap.set('n', '<C-t>', api.node.open.tab, opts('Open: New Tab'))
|
||||
vim.keymap.set('n', '<C-v>', api.node.open.vertical, opts('Open: Vertical Split'))
|
||||
vim.keymap.set('n', '<C-x>', api.node.open.horizontal, opts('Open: Horizontal Split'))
|
||||
vim.keymap.set('n', '<BS>', api.node.navigate.parent_close, opts('Close Directory'))
|
||||
vim.keymap.set('n', '<CR>', api.node.open.edit, opts('Open'))
|
||||
vim.keymap.set('n', '<Tab>', api.node.open.preview, opts('Open Preview'))
|
||||
vim.keymap.set('n', '>', api.node.navigate.sibling.next, opts('Next Sibling'))
|
||||
vim.keymap.set('n', '<', api.node.navigate.sibling.prev, opts('Previous Sibling'))
|
||||
vim.keymap.set('n', '.', api.node.run.cmd, opts('Run Command'))
|
||||
vim.keymap.set('n', '-', api.tree.change_root_to_parent, opts('Up'))
|
||||
vim.keymap.set('n', 'a', api.fs.create, opts('Create'))
|
||||
vim.keymap.set('n', 'bmv', api.marks.bulk.move, opts('Move Bookmarked'))
|
||||
vim.keymap.set('n', 'B', api.tree.toggle_no_buffer_filter, opts('Toggle No Buffer'))
|
||||
vim.keymap.set('n', 'c', api.fs.copy.node, opts('Copy'))
|
||||
vim.keymap.set('n', 'C', api.tree.toggle_git_clean_filter, opts('Toggle Git Clean'))
|
||||
vim.keymap.set('n', '[c', api.node.navigate.git.prev, opts('Prev Git'))
|
||||
vim.keymap.set('n', ']c', api.node.navigate.git.next, opts('Next Git'))
|
||||
vim.keymap.set('n', 'd', api.fs.remove, opts('Delete'))
|
||||
vim.keymap.set('n', 'D', api.fs.trash, opts('Trash'))
|
||||
vim.keymap.set('n', 'E', api.tree.expand_all, opts('Expand All'))
|
||||
vim.keymap.set('n', 'e', api.fs.rename_basename, opts('Rename: Basename'))
|
||||
vim.keymap.set('n', ']e', api.node.navigate.diagnostics.next, opts('Next Diagnostic'))
|
||||
vim.keymap.set('n', '[e', api.node.navigate.diagnostics.prev, opts('Prev Diagnostic'))
|
||||
vim.keymap.set('n', 'F', api.live_filter.clear, opts('Clean Filter'))
|
||||
vim.keymap.set('n', 'f', api.live_filter.start, opts('Filter'))
|
||||
vim.keymap.set('n', 'g?', api.tree.toggle_help, opts('Help'))
|
||||
vim.keymap.set('n', 'gy', api.fs.copy.absolute_path, opts('Copy Absolute Path'))
|
||||
vim.keymap.set('n', 'H', api.tree.toggle_hidden_filter, opts('Toggle Dotfiles'))
|
||||
vim.keymap.set('n', 'I', api.tree.toggle_gitignore_filter, opts('Toggle Git Ignore'))
|
||||
vim.keymap.set('n', 'J', api.node.navigate.sibling.last, opts('Last Sibling'))
|
||||
vim.keymap.set('n', 'K', api.node.navigate.sibling.first, opts('First Sibling'))
|
||||
vim.keymap.set('n', 'm', api.marks.toggle, opts('Toggle Bookmark'))
|
||||
vim.keymap.set('n', 'o', api.node.open.edit, opts('Open'))
|
||||
vim.keymap.set('n', 'O', api.node.open.no_window_picker, opts('Open: No Window Picker'))
|
||||
vim.keymap.set('n', 'p', api.fs.paste, opts('Paste'))
|
||||
vim.keymap.set('n', 'P', api.node.navigate.parent, opts('Parent Directory'))
|
||||
vim.keymap.set('n', 'q', api.tree.close, opts('Close'))
|
||||
vim.keymap.set('n', 'r', api.fs.rename, opts('Rename'))
|
||||
vim.keymap.set('n', 'R', api.tree.reload, opts('Refresh'))
|
||||
vim.keymap.set('n', 's', api.node.run.system, opts('Run System'))
|
||||
vim.keymap.set('n', 'S', api.tree.search_node, opts('Search'))
|
||||
vim.keymap.set('n', 'U', api.tree.toggle_custom_filter, opts('Toggle Hidden'))
|
||||
vim.keymap.set('n', 'W', api.tree.collapse_all, opts('Collapse'))
|
||||
vim.keymap.set('n', 'x', api.fs.cut, opts('Cut'))
|
||||
vim.keymap.set('n', 'y', api.fs.copy.filename, opts('Copy Name'))
|
||||
vim.keymap.set('n', 'Y', api.fs.copy.relative_path, opts('Copy Relative Path'))
|
||||
vim.keymap.set('n', '<2-LeftMouse>', api.node.open.edit, opts('Open'))
|
||||
vim.keymap.set('n', '<2-RightMouse>', api.tree.change_root_to_node, opts('CD'))
|
||||
-- END_DEFAULT_ON_ATTACH
|
||||
end
|
||||
|
||||
local function filter_default_mappings(keys_to_disable)
|
||||
local new_map = {}
|
||||
for _, m in pairs(DEFAULT_KEYMAPS) do
|
||||
local keys = type(m.key) == "table" and m.key or { m.key }
|
||||
local reminding_keys = {}
|
||||
for _, key in pairs(keys) do
|
||||
local found = false
|
||||
for _, key_to_disable in pairs(keys_to_disable) do
|
||||
if key_to_disable == key then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not found then
|
||||
table.insert(reminding_keys, key)
|
||||
end
|
||||
end
|
||||
if #reminding_keys > 0 then
|
||||
local map = vim.deepcopy(m)
|
||||
map.key = reminding_keys
|
||||
table.insert(new_map, map)
|
||||
end
|
||||
end
|
||||
return new_map
|
||||
end
|
||||
|
||||
local function get_keymaps(keys_to_disable)
|
||||
if keys_to_disable == true then
|
||||
return {}
|
||||
end
|
||||
|
||||
if type(keys_to_disable) == "table" and #keys_to_disable > 0 then
|
||||
return filter_default_mappings(keys_to_disable)
|
||||
end
|
||||
|
||||
return DEFAULT_KEYMAPS
|
||||
end
|
||||
-- stylua: ignore end
|
||||
|
||||
function M.setup(opts)
|
||||
M.keymaps = get_keymaps(opts.remove_keymaps)
|
||||
if type(opts.on_attach) ~= "function" then
|
||||
M.on_attach = M.default_on_attach
|
||||
else
|
||||
M.on_attach = opts.on_attach
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user