doc: default mappings

This commit is contained in:
Alexander Courtis 2022-05-30 12:53:28 +10:00 committed by GitHub
parent 5e900c2f29
commit 8198fa01fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 567 additions and 266 deletions

View File

@ -15,10 +15,11 @@ cargo install stylua
## Adding new actions
To add a new action, add a file in `actions/name-of-the-action.lua`. You should export a `setup` function if some configuration is needed.
Once you did, you should run the `scripts/update-default-opts.sh` which will update the default documentation in the README and the help file.
## Documentation
When adding new options, you should declare the defaults in the main `nvim-tree.lua` file.
Once you did, you should run the `update-default-opts.sh` script which will update the default documentation in the README and the help file.
Once you did, you should run the `scripts/update-default-opts.sh` which will update the default documentation in the README and the help file.
Documentation for options should also be added, see how this is done after `nvim-tree.disable_netrw` in the `nvim-tree-lua.txt` file.

182
README.md
View File

@ -232,48 +232,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
} -- END_DEFAULT_OPTS
```
## Key Bindings
### Default actions
- `<CR>` or `o` on the root folder will cd in the above directory
- `<C-]>` will cd in the directory under the cursor
- `<BS>` will close current opened directory or parent
- type `a` to add a file. Adding a directory requires leaving a leading `/` at the end of the path.
> you can add multiple directories by doing foo/bar/baz/f and it will add foo bar and baz directories and f as a file
- type `r` to rename a file
- type `<C-r>` to rename a file and omit the filename on input
- type `x` to add/remove file/directory to cut clipboard
- type `c` to add/remove file/directory to copy clipboard
- type `y` will copy name to system clipboard
- type `Y` will copy relative path to system clipboard
- type `gy` will copy absolute path to system clipboard
- type `p` to paste from clipboard. Cut clipboard has precedence over copy (will prompt for confirmation)
- type `d` to delete a file (will prompt for confirmation)
- type `D` to trash a file (configured in setup())
- type `]c` to go to next git item
- type `[c` to go to prev git item
- type `-` to navigate up to the parent directory of the current file/directory
- type `s` to open a file with default system application or a folder with default file manager (if you want to change the command used to do it see `:h nvim-tree.setup` under `system_open`)
- if the file is a directory, `<CR>` will open the directory 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 target is a file)
- `<C-v>` will open the file in a vertical split
- `<C-x>` will open the file in a horizontal split
- `<C-t>` will open the file in a new tab
- `<Tab>` will open the file as a preview (keeps the cursor in the tree)
- `I` will toggle visibility of hidden folders / files
- `H` will toggle visibility of dotfiles (files/folders starting with a `.`)
- `R` will refresh the tree
- Double left click acts like `<CR>`
- Double right click acts like `<C-]>`
- `W` will collapse the whole tree
- `E` will expand the whole tree. Be aware this might hang neovim for a while if running on a big folder (see `:help nvim-tree.actions.expand_all.max_folder_discovery`).
- `S` will prompt the user to enter a path and then expands the tree to match the path
- `.` will enter vim command mode with the file the cursor is on
- `C-k` will toggle a popup with file infos about the file under the cursor
- `f` will allow you to filter nodes dynamically based on regex matching.
### Settings
## Mappings
The `list` option in `view.mappings.list` is a table of
```lua
@ -296,57 +255,102 @@ local list = {
}
```
These are the default bindings:
### Defaults
<!-- BEGIN_DEFAULT_MAPPINGS_TABLE -->
| Default Keys | Action | Description |
| - | - | - |
| \<CR> <br /> o <br /> \<2-LeftMouse> | edit | open a file or folder; root will cd to the above directory |
| \<C-e> | edit_in_place | edit the file in place, effectively replacing the tree explorer |
| O | edit_no_picker | same as (edit) with no window picker |
| \<C-]> <br /> \<2-RightMouse> | cd | cd in the directory under the cursor |
| \<C-v> | vsplit | open the file in a vertical split |
| \<C-x> | split | open the file in a horizontal split |
| \<C-t> | tabnew | open the file in a new tab |
| \< | prev_sibling | navigate to the previous sibling of current file/directory |
| > | next_sibling | navigate to the next sibling of current file/directory |
| P | parent_node | move cursor to the parent directory |
| \<BS> | close_node | close current opened directory or parent |
| \<Tab> | preview | open the file as a preview (keeps the cursor in the tree) |
| K | first_sibling | navigate to the first sibling of current file/directory |
| J | last_sibling | navigate to the last sibling of current file/directory |
| I | toggle_git_ignored | toggle visibility of files/folders hidden via `git.ignore` option |
| H | toggle_dotfiles | toggle visibility of dotfiles via `filters.dotfiles` option |
| U | toggle_custom | toggle visibility of files/folders hidden via `filters.custom` option |
| R | refresh | refresh the tree |
| a | create | add a file; leaving a trailing `/` will add a directory |
| d | remove | delete a file (will prompt for confirmation) |
| D | trash | trash a file via `trash` option |
| r | rename | rename a file |
| \<C-r> | full_rename | rename a file and omit the filename on input |
| x | cut | add/remove file/directory to cut clipboard |
| c | copy | add/remove file/directory to copy clipboard |
| p | paste | paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation |
| y | copy_name | copy name to system clipboard |
| Y | copy_path | copy relative path to system clipboard |
| gy | copy_absolute_path | copy absolute path to system clipboard |
| [c | prev_git_item | go to next git item |
| ]c | next_git_item | go to prev git item |
| - | dir_up | navigate up to the parent directory of the current file/directory |
| s | system_open | open a file with default system application or a folder with default file manager, using `system_open` option |
| f | live_filter | live filter nodes dynamically based on regex matching. |
| F | clear_live_filter | clear live filter |
| q | close | close tree window |
| W | collapse_all | collapse the whole tree |
| 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 |
| S | search_node | prompt the user to enter a path and then expands the tree to match the path |
| . | run_file_command | enter vim command mode with the file the cursor is on |
| \<C-k> | toggle_file_info | toggle a popup with file infos about the file under the cursor |
| g? | toggle_help | toggle help |
<!-- END_DEFAULT_MAPPINGS_TABLE -->
```lua
-- default mappings
local list = {
{ key = {"<CR>", "o", "<2-LeftMouse>"}, action = "edit" },
{ key = "<C-e>", action = "edit_in_place" },
{ key = {"O"}, action = "edit_no_picker" },
{ key = {"<2-RightMouse>", "<C-]>"}, action = "cd" },
{ key = "<C-v>", action = "vsplit" },
{ key = "<C-x>", action = "split" },
{ key = "<C-t>", action = "tabnew" },
{ key = "<", action = "prev_sibling" },
{ key = ">", action = "next_sibling" },
{ key = "P", action = "parent_node" },
{ key = "<BS>", action = "close_node" },
{ key = "<Tab>", action = "preview" },
{ key = "K", action = "first_sibling" },
{ key = "J", action = "last_sibling" },
{ key = "I", action = "toggle_git_ignored" },
{ key = "H", action = "toggle_dotfiles" },
{ key = "R", action = "refresh" },
{ key = "a", action = "create" },
{ key = "d", action = "remove" },
{ key = "D", action = "trash" },
{ key = "r", action = "rename" },
{ key = "<C-r>", action = "full_rename" },
{ key = "x", action = "cut" },
{ key = "c", action = "copy" },
{ key = "p", action = "paste" },
{ key = "y", action = "copy_name" },
{ key = "Y", action = "copy_path" },
{ key = "gy", action = "copy_absolute_path" },
{ key = "[c", action = "prev_git_item" },
{ key = "]c", action = "next_git_item" },
{ key = "-", action = "dir_up" },
{ key = "s", action = "system_open" },
{ key = "f", action = "live_filter" },
{ key = "F", action = "clear_live_filter" },
{ key = "q", action = "close" },
{ key = "g?", action = "toggle_help" },
{ key = "W", action = "collapse_all" },
{ key = "E", action = "expand_all" },
{ key = "S", action = "search_node" },
{ key = "<C-k>", action = "toggle_file_info" },
view.mappings.list = { -- BEGIN_DEFAULT_MAPPINGS
{ key = { "<CR>", "o", "<2-LeftMouse>" }, action = "edit" }
{ key = "<C-e>", action = "edit_in_place" }
{ key = "O", action = "edit_no_picker" }
{ key = { "<C-]>", "<2-RightMouse>" }, action = "cd" }
{ key = "<C-v>", action = "vsplit" }
{ key = "<C-x>", action = "split" }
{ key = "<C-t>", action = "tabnew" }
{ key = "<", action = "prev_sibling" }
{ key = ">", action = "next_sibling" }
{ key = "P", action = "parent_node" }
{ key = "<BS>", action = "close_node" }
{ key = "<Tab>", action = "preview" }
{ key = "K", action = "first_sibling" }
{ key = "J", action = "last_sibling" }
{ key = "I", action = "toggle_git_ignored" }
{ key = "H", action = "toggle_dotfiles" }
{ key = "U", action = "toggle_custom" }
{ key = "R", action = "refresh" }
{ key = "a", action = "create" }
{ key = "d", action = "remove" }
{ key = "D", action = "trash" }
{ key = "r", action = "rename" }
{ key = "<C-r>", action = "full_rename" }
{ key = "x", action = "cut" }
{ key = "c", action = "copy" }
{ key = "p", action = "paste" }
{ key = "y", action = "copy_name" }
{ key = "Y", action = "copy_path" }
{ key = "gy", action = "copy_absolute_path" }
{ key = "[c", action = "prev_git_item" }
{ key = "]c", action = "next_git_item" }
{ key = "-", action = "dir_up" }
{ key = "s", action = "system_open" }
{ key = "f", action = "live_filter" }
{ key = "F", action = "clear_live_filter" }
{ key = "q", action = "close" }
{ key = "W", action = "collapse_all" }
{ key = "E", action = "expand_all" }
{ key = "S", action = "search_node" }
{ key = ".", action = "run_file_command" }
}
{ key = "<C-k>", action = "toggle_file_info" }
{ key = "g?", action = "toggle_help" }
} -- END_DEFAULT_MAPPINGS
```
You can toggle the help UI by pressing `g?`.
## 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.

View File

@ -468,7 +468,7 @@ Window / buffer setup.
A list of keymaps that will extend or override the default keymaps,
see |nvim-tree-mappings|.
Type: `table`
Default: `{}`
Default: see |nvim-tree-default-mappings|
*nvim-tree.renderer*
UI rendering setup
@ -737,109 +737,15 @@ Configuration for diagnostic logging.
==============================================================================
INFORMATIONS *nvim-tree-info*
|Mappings| *nvim-tree-mappings*
- type `g?` to see the help UI with keybindings
- move around like in any vim buffer
- `<CR>` on the root folder will cd in the above directory
- typing <C-]> will cd in the directory under the cursor
- typing <BS> will close current opened directory or parent
- typing `P` will move cursor to the parent directory
- type `a` to add a file
- type `r` to rename a file
- type `<C-r>` to rename a file and omit the filename on input
- type `x` to add/remove file/directory to cut clipboard
- type `c` to add/remove file/directory to copy clipboard
- type `p` to paste from clipboard. Cut clipboard has precedence over copy
(will prompt for confirmation)
- type `d` to delete a file (will prompt for confirmation)
- type `]c` to go to next git item
- type `[c` to go to prev git item
- type `-` to navigate up one directory
- type `s` to open a file with default system application or a folder with default file manager
- type `<` to navigate to the previous 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 `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
- otherwise it will open the file in the buffer near the tree
- if the file is a symlink, <CR> will follow the symlink
- <C-v> will open the file in a vertical split
- <C-x> will open the file in a horizontal split
- <C-t> will open the file in a new tab
- <Tab> will open the file as a preview (keeps the cursor in the tree)
- `I` will toggle visibility of files/folders hidden via |git.ignore| option
- `H` will toggle visibility of dotfiles (files/folders starting with a `.`)
- U will toggle visibility of files/folders hidden via |filters.custom| option
- `R` will refresh the tree
- Double left click acts like <CR>
- Double right click acts like <C-]>
- `W` will collapse the whole tree
- `E` will expand the whole tree. Be aware this might hang neovim for a while
if running on a big folder (such as home dir or root dir).
- `S` will prompt the user to enter a path and then expands the tree to match the path
- `.` will enter vim command mode with the file the cursor is on
- `C-k` will toggle a popup with file infos about the file under the cursor
Defaults to:
>
lua <<EOF
local list = {
{ key = {"<CR>", "o", "<2-LeftMouse>"}, action = "edit" },
{ key = "<C-e>", action = "edit_in_place" },
{ key = {"O"}, action = "edit_no_picker" },
{ key = {"<2-RightMouse>", "<C-]>"}, action = "cd" },
{ key = "<C-v>", action = "vsplit" },
{ key = "<C-x>", action = "split" },
{ key = "<C-t>", action = "tabnew" },
{ key = "<", action = "prev_sibling" },
{ key = ">", action = "next_sibling" },
{ key = "P", action = "parent_node" },
{ key = "<BS>", action = "close_node" },
{ key = "<Tab>", action = "preview" },
{ key = "K", action = "first_sibling" },
{ key = "J", action = "last_sibling" },
{ key = "I", action = "toggle_git_ignored" },
{ key = "H", action = "toggle_dotfiles" },
{ key = "R", action = "refresh" },
{ key = "a", action = "create" },
{ key = "d", action = "remove" },
{ key = "D", action = "trash" },
{ key = "r", action = "rename" },
{ key = "<C-r>", action = "full_rename" },
{ key = "x", action = "cut" },
{ key = "c", action = "copy" },
{ key = "p", action = "paste" },
{ key = "y", action = "copy_name" },
{ key = "Y", action = "copy_path" },
{ key = "gy", action = "copy_absolute_path" },
{ key = "[c", action = "prev_git_item" },
{ key = "]c", action = "next_git_item" },
{ key = "-", action = "dir_up" },
{ key = "s", action = "system_open" },
{ key = "f", action = "live_filter" },
{ key = "F", action = "clear_live_filter" },
{ key = "q", action = "close" },
{ key = "g?", action = "toggle_help" },
{ key = 'W', action = "collapse_all" },
{ key = 'E', action = "expand_all" },
{ key = "S", action = "search_node" },
{ key = ".", action = "run_file_command" },
{ key = "<C-k>", action = "toggle_file_info" }
{ key = "U", action = "toggle_custom" },
}
<
MAPPINGS *nvim-tree-mappings*
The `list` option in `view.mappings.list` is a table of
- key can be either a string or a table of string (lhs)
- action is the name of the action, set to `""` to remove default action
- action_cb is the function that will be called, it receives the node as a parameter. Optional for default actions
- mode is normal by default
- `key` can be either a string or a table of string (lhs)
- `action` is the name of the action, set to `""` to remove default action
- `action_cb` is the function that will be called, it receives the node as a parameter. Optional for default actions
- `mode` is normal by default
>
lua <<EOF
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
local function print_node_path(node) {
@ -852,9 +758,102 @@ The `list` option in `view.mappings.list` is a table of
{ key = "s", cb = tree_cb("vsplit") }, --tree_cb and the cb property are deprecated
{ key = "<2-RightMouse>", action = "" }, -- will remove default cd action
}
<
DEFAULT MAPPINGS *nvim-tree-default-mappings*
`<CR>` edit open a file or folder; root will cd to the above directory
`o`
`<2-LeftMouse>`
`<C-e>` edit_in_place edit the file in place, effectively replacing the tree explorer
`O` edit_no_picker same as (edit) with no window picker
`<C-]>` cd cd in the directory under the cursor
`<2-RightMouse>`
`<C-v>` vsplit open the file in a vertical split
`<C-x>` split open the file in a horizontal split
`<C-t>` tabnew open the file in a new tab
`<` prev_sibling navigate to the previous sibling of current file/directory
`>` next_sibling navigate to the next sibling of current file/directory
`P` parent_node move cursor to the parent directory
`<BS>` close_node close current opened directory or parent
`<Tab>` preview open the file as a preview (keeps the cursor in the tree)
`K` first_sibling navigate to the first sibling of current file/directory
`J` last_sibling navigate to the last sibling of current file/directory
`I` toggle_git_ignored toggle visibility of files/folders hidden via |git.ignore| option
`H` toggle_dotfiles toggle visibility of dotfiles via |filters.dotfiles| option
`U` toggle_custom toggle visibility of files/folders hidden via |filters.custom| option
`R` refresh refresh the tree
`a` create add a file; leaving a trailing `/` will add a directory
`d` remove delete a file (will prompt for confirmation)
`D` trash trash a file via |trash| option
`r` rename rename a file
`<C-r>` full_rename rename a file and omit the filename on input
`x` cut add/remove file/directory to cut clipboard
`c` copy add/remove file/directory to copy clipboard
`p` paste paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation
`y` copy_name copy name to system clipboard
`Y` copy_path copy relative path to system clipboard
`gy` copy_absolute_path copy absolute path to system clipboard
`[c` prev_git_item go to next git item
`]c` next_git_item go to prev git item
`-` dir_up navigate up to the parent directory of the current file/directory
`s` system_open open a file with default system application or a folder with default file manager, using |system_open| option
`f` live_filter live filter nodes dynamically based on regex matching.
`F` clear_live_filter clear live filter
`q` close close tree window
`W` collapse_all collapse the whole tree
`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
`S` search_node prompt the user to enter a path and then expands the tree to match the path
`.` run_file_command enter vim command mode with the file the cursor is on
`<C-k>` toggle_file_info toggle a popup with file infos about the file under the cursor
`g?` toggle_help toggle help
|Features| *nvim-tree-features*
>
view.mappings.list = { -- BEGIN_DEFAULT_MAPPINGS
{ key = { "<CR>", "o", "<2-LeftMouse>" }, action = "edit" }
{ key = "<C-e>", action = "edit_in_place" }
{ key = "O", action = "edit_no_picker" }
{ key = { "<C-]>", "<2-RightMouse>" }, action = "cd" }
{ key = "<C-v>", action = "vsplit" }
{ key = "<C-x>", action = "split" }
{ key = "<C-t>", action = "tabnew" }
{ key = "<", action = "prev_sibling" }
{ key = ">", action = "next_sibling" }
{ key = "P", action = "parent_node" }
{ key = "<BS>", action = "close_node" }
{ key = "<Tab>", action = "preview" }
{ key = "K", action = "first_sibling" }
{ key = "J", action = "last_sibling" }
{ key = "I", action = "toggle_git_ignored" }
{ key = "H", action = "toggle_dotfiles" }
{ key = "U", action = "toggle_custom" }
{ key = "R", action = "refresh" }
{ key = "a", action = "create" }
{ key = "d", action = "remove" }
{ key = "D", action = "trash" }
{ key = "r", action = "rename" }
{ key = "<C-r>", action = "full_rename" }
{ key = "x", action = "cut" }
{ key = "c", action = "copy" }
{ key = "p", action = "paste" }
{ key = "y", action = "copy_name" }
{ key = "Y", action = "copy_path" }
{ key = "gy", action = "copy_absolute_path" }
{ key = "[c", action = "prev_git_item" }
{ key = "]c", action = "next_git_item" }
{ key = "-", action = "dir_up" }
{ key = "s", action = "system_open" }
{ key = "f", action = "live_filter" }
{ key = "F", action = "clear_live_filter" }
{ key = "q", action = "close" }
{ key = "W", action = "collapse_all" }
{ key = "E", action = "expand_all" }
{ key = "S", action = "search_node" }
{ key = ".", action = "run_file_command" }
{ key = "<C-k>", action = "toggle_file_info" }
{ key = "g?", action = "toggle_help" }
} -- END_DEFAULT_MAPPINGS
<
FEATURES *nvim-tree-features*
File icons with vim-devicons.

View File

@ -6,53 +6,223 @@ local view = require "nvim-tree.view"
local util = require "nvim-tree.utils"
local nvim_tree_callback = require("nvim-tree.config").nvim_tree_callback
-- BEGIN_DEFAULT_MAPPINGS
local M = {
mappings = {
{ key = { "<CR>", "o", "<2-LeftMouse>" }, action = "edit" },
{ key = "<C-e>", action = "edit_in_place" },
{ key = "O", action = "edit_no_picker" },
{ key = { "<2-RightMouse>", "<C-]>" }, action = "cd" },
{ key = "<C-v>", action = "vsplit" },
{ key = "<C-x>", action = "split" },
{ key = "<C-t>", action = "tabnew" },
{ key = "<", action = "prev_sibling" },
{ key = ">", action = "next_sibling" },
{ key = "P", action = "parent_node" },
{ key = "<BS>", action = "close_node" },
{ key = "<Tab>", action = "preview" },
{ key = "K", action = "first_sibling" },
{ key = "J", action = "last_sibling" },
{ key = "I", action = "toggle_git_ignored" },
{ key = "H", action = "toggle_dotfiles" },
{ key = "R", action = "refresh" },
{ key = "a", action = "create" },
{ key = "d", action = "remove" },
{ key = "D", action = "trash" },
{ key = "r", action = "rename" },
{ key = "<C-r>", action = "full_rename" },
{ key = "x", action = "cut" },
{ key = "c", action = "copy" },
{ key = "p", action = "paste" },
{ key = "y", action = "copy_name" },
{ key = "Y", action = "copy_path" },
{ key = "gy", action = "copy_absolute_path" },
{ key = "[c", action = "prev_git_item" },
{ key = "]c", action = "next_git_item" },
{ key = "-", action = "dir_up" },
{ key = "s", action = "system_open" },
{ key = "f", action = "live_filter" },
{ key = "F", action = "clear_live_filter" },
{ key = "q", action = "close" },
{ key = "g?", action = "toggle_help" },
{ key = "W", action = "collapse_all" },
{ key = "E", action = "expand_all" },
{ key = "S", action = "search_node" },
{ key = ".", action = "run_file_command" },
{ key = "<C-k>", action = "toggle_file_info" },
{ key = "U", action = "toggle_custom" },
{
key = { "<CR>", "o", "<2-LeftMouse>" },
action = "edit",
desc = "open a file or folder; root will cd to the above directory",
},
{
key = "<C-e>",
action = "edit_in_place",
desc = "edit the file in place, effectively replacing the tree explorer",
},
{
key = "O",
action = "edit_no_picker",
desc = "same as (edit) with no window picker",
},
{
key = { "<C-]>", "<2-RightMouse>" },
action = "cd",
desc = "cd in the directory under the cursor",
},
{
key = "<C-v>",
action = "vsplit",
desc = "open the file in a vertical split",
},
{
key = "<C-x>",
action = "split",
desc = "open the file in a horizontal split",
},
{
key = "<C-t>",
action = "tabnew",
desc = "open the file in a new tab",
},
{
key = "<",
action = "prev_sibling",
desc = "navigate to the previous sibling of current file/directory",
},
{
key = ">",
action = "next_sibling",
desc = "navigate to the next sibling of current file/directory",
},
{
key = "P",
action = "parent_node",
desc = "move cursor to the parent directory",
},
{
key = "<BS>",
action = "close_node",
desc = "close current opened directory or parent",
},
{
key = "<Tab>",
action = "preview",
desc = "open the file as a preview (keeps the cursor in the tree)",
},
{
key = "K",
action = "first_sibling",
desc = "navigate to the first sibling of current file/directory",
},
{
key = "J",
action = "last_sibling",
desc = "navigate to the last sibling of current file/directory",
},
{
key = "I",
action = "toggle_git_ignored",
desc = "toggle visibility of files/folders hidden via |git.ignore| option",
},
{
key = "H",
action = "toggle_dotfiles",
desc = "toggle visibility of dotfiles via |filters.dotfiles| option",
},
{
key = "U",
action = "toggle_custom",
desc = "toggle visibility of files/folders hidden via |filters.custom| option",
},
{
key = "R",
action = "refresh",
desc = "refresh the tree",
},
{
key = "a",
action = "create",
desc = "add a file; leaving a trailing `/` will add a directory",
},
{
key = "d",
action = "remove",
desc = "delete a file (will prompt for confirmation)",
},
{
key = "D",
action = "trash",
desc = "trash a file via |trash| option",
},
{
key = "r",
action = "rename",
desc = "rename a file",
},
{
key = "<C-r>",
action = "full_rename",
desc = "rename a file and omit the filename on input",
},
{
key = "x",
action = "cut",
desc = "add/remove file/directory to cut clipboard",
},
{
key = "c",
action = "copy",
desc = "add/remove file/directory to copy clipboard",
},
{
key = "p",
action = "paste",
desc = "paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation",
},
{
key = "y",
action = "copy_name",
desc = "copy name to system clipboard",
},
{
key = "Y",
action = "copy_path",
desc = "copy relative path to system clipboard",
},
{
key = "gy",
action = "copy_absolute_path",
desc = "copy absolute path to system clipboard",
},
{
key = "[c",
action = "prev_git_item",
desc = "go to next git item",
},
{
key = "]c",
action = "next_git_item",
desc = "go to prev git item",
},
{
key = "-",
action = "dir_up",
desc = "navigate up to the parent directory of the current file/directory",
},
{
key = "s",
action = "system_open",
desc = "open a file with default system application or a folder with default file manager, using |system_open| option",
},
{
key = "f",
action = "live_filter",
desc = "live filter nodes dynamically based on regex matching.",
},
{
key = "F",
action = "clear_live_filter",
desc = "clear live filter",
},
{
key = "q",
action = "close",
desc = "close tree window",
},
{
key = "W",
action = "collapse_all",
desc = "collapse the whole tree",
},
{
key = "E",
action = "expand_all",
desc = "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",
},
{
key = "S",
action = "search_node",
desc = "prompt the user to enter a path and then expands the tree to match the path",
},
{
key = ".",
action = "run_file_command",
desc = "enter vim command mode with the file the cursor is on",
},
{
key = "<C-k>",
action = "toggle_file_info",
desc = "toggle a popup with file infos about the file under the cursor",
},
{
key = "g?",
action = "toggle_help",
desc = "toggle help",
},
},
custom_keypress_funcs = {},
}
-- END_DEFAULT_MAPPINGS
local keypress_funcs = {
close = view.close,

View File

@ -0,0 +1,104 @@
-- luacheck:ignore 113
---@diagnostic disable: undefined-global
-- write DEFAULT_MAPPINGS in various formats
local max_key_help = 0
local max_key_lua = 0
local max_action_help = 0
local outs_help = {}
local outs_lua = {}
for _, m in pairs(M.mappings) do
local out
if type(m.key) == "table" then
local first = true
local keys_lua = "key = {"
for _, sub_key in pairs(m.key) do
-- lua
keys_lua = string.format('%s%s "%s"', keys_lua, first and "" or ",", sub_key)
-- help
out = {}
if first then
out.action = m.action
out.desc = m.desc
first = false
else
out.action = ""
out.desc = ""
end
out.key = string.format("`%s`", sub_key)
max_action_help = math.max(#out.action, max_action_help)
max_key_help = math.max(#out.key, max_key_help)
table.insert(outs_help, out)
end
-- lua
out = {}
out.key = string.format("%s },", keys_lua)
table.insert(outs_lua, out)
else
-- help
out = {}
out.action = m.action
out.desc = m.desc
out.key = string.format("`%s`", m.key)
table.insert(outs_help, out)
max_action_help = math.max(#out.action, max_action_help)
max_key_help = math.max(#out.key, max_key_help)
-- lua
out = {}
out.key = string.format('key = "%s",', m.key)
table.insert(outs_lua, out)
end
--lua
out.action = string.format('action = "%s"', m.action)
max_key_lua = math.max(#out.key, max_key_lua)
end
-- help
local file = io.open("/tmp/DEFAULT_MAPPINGS.help", "w")
io.output(file)
io.write "\n"
local fmt = string.format("%%-%d.%ds %%-%d.%ds %%s\n", max_key_help, max_key_help, max_action_help, max_action_help)
for _, m in pairs(outs_help) do
if m.action == "" then
io.write(string.format("%s\n", m.key))
else
io.write(string.format(fmt, m.key, m.action, m.desc))
end
end
io.write "\n"
io.close(file)
-- lua
file = io.open("/tmp/DEFAULT_MAPPINGS.lua", "w")
io.output(file)
fmt = string.format(" { %%-%d.%ds %%s }\n", max_key_lua, max_key_lua)
for _, m in pairs(outs_lua) do
io.write(string.format(fmt, m.key, m.action))
end
io.close(file)
-- md
file = io.open("/tmp/DEFAULT_MAPPINGS.md", "w")
io.output(file)
io.write "| Default Keys | Action | Description |\n"
io.write "| - | - | - |\n"
for _, m in pairs(M.mappings) do
local keys = ""
if type(m.key) == "table" then
local first = true
for _, sub_key in pairs(m.key) do
keys = keys .. (first and "" or " <br /> ") .. sub_key:gsub("<", "\\<")
first = false
end
else
keys = m.key:gsub("<", "\\<")
end
io.write(string.format("| %s | %s | %s |\n", keys, m.action, m.desc:gsub("|", "`")))
end
io.close(file)

44
scripts/update-default-opts.sh Executable file
View File

@ -0,0 +1,44 @@
#!/bin/sh
# run after changing nvim-tree.lua DEFAULT_OPTS or nvim-tree/actions/init.lua M.mappings
# scrapes and updates README.md, nvim-tree-lua.txt
# run from repositry root: scripts/update-default-opts.sh
begin="BEGIN_DEFAULT_OPTS"
end="END_DEFAULT_OPTS"
# scrape DEFAULT_OPTS, indented at 2
sed -n -e "/${begin}/,/${end}/{ /${begin}/d; /${end}/d; p; }" lua/nvim-tree.lua > /tmp/DEFAULT_OPTS.2.lua
# indent some more
sed -e "s/^ / /" /tmp/DEFAULT_OPTS.2.lua > /tmp/DEFAULT_OPTS.6.lua
# README.md indented at 2
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_OPTS.2.lua
}; /${end}/p; d }" README.md
# help, indented at 6
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_OPTS.6.lua
}; /${end}/p; d }" doc/nvim-tree-lua.txt
begin="BEGIN_DEFAULT_MAPPINGS"
end="END_DEFAULT_MAPPINGS"
# generate various DEFAULT_MAPPINGS
sed -n -e "/${begin}/,/${end}/{ /${begin}/d; /${end}/d; p; }" lua/nvim-tree/actions/init.lua > /tmp/DEFAULT_MAPPINGS.M.lua
lua <(cat /tmp/DEFAULT_MAPPINGS.M.lua scripts/generate_default_mappings.lua)
# README.md
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_MAPPINGS.lua
}; /${end}/p; d }" README.md
sed -i -e "/BEGIN_DEFAULT_MAPPINGS_TABLE/,/END_DEFAULT_MAPPINGS_TABLE/{ /BEGIN_DEFAULT_MAPPINGS_TABLE/{p; r /tmp/DEFAULT_MAPPINGS.md
}; /END_DEFAULT_MAPPINGS_TABLE/p; d }" README.md
# help
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_MAPPINGS.lua
}; /${end}/p; d }" doc/nvim-tree-lua.txt
sed -i -e "/^DEFAULT MAPPINGS/,/^>$/{ /^DEFAULT MAPPINGS/{p; r /tmp/DEFAULT_MAPPINGS.help
}; /^>$/p; d }" doc/nvim-tree-lua.txt

View File

@ -1,21 +0,0 @@
#!/bin/sh
# run after changing nvim-tree.lua DEFAULT_OPTS: scrapes and updates README.md, nvim-tree-lua.txt
begin="BEGIN_DEFAULT_OPTS"
end="END_DEFAULT_OPTS"
# scrape, indented at 2
sed -n -e "/${begin}/,/${end}/{ /${begin}/d; /${end}/d; p; }" lua/nvim-tree.lua > /tmp/DEFAULT_OPTS.2.lua
# indent some more
sed -e "s/^ / /" /tmp/DEFAULT_OPTS.2.lua > /tmp/DEFAULT_OPTS.6.lua
# README.md indented at 2
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_OPTS.2.lua
}; /${end}/p; d }" README.md
# help, indented at 6
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_OPTS.6.lua
}; /${end}/p; d }" doc/nvim-tree-lua.txt