Skip to content

Commit

Permalink
rfc!: mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
fdschmidt93 committed Jan 13, 2022
1 parent 0ea5512 commit f8e91ab
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 45 deletions.
97 changes: 65 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,47 +119,80 @@ Note: `path` corresponds to the folder the `file_browser` is currently in.

`telescope-file-browser.nvim` comes with a lot of default mappings for discoverability. You can use `telescope`'s `which_key` (insert mode: `<C-/>`, normal mode: `?`) to list mappings attached to your picker.

| Insert / Normal | Action |
|-----------------|-------------------------------------------------------------------------------|
| `<A-c>/c` | Create file/folder at current `path` (trailing path separator creates folder) |
| `<A-r>/r` | Rename multi-selected files/folders |
| `<A-m>/m` | Move multi-selected files/folders to current `path` |
| `<A-y>/y` | Copy (multi-)selected files/folders to current `path` |
| `<A-d>/d` | Delete (multi-)selected files/folders |
| `<C-o>/o` | Open file/folder with default system application |
| `<C-b>/b` | Go to parent directory |
| `<C-e>/e` | Go to home directory |
| `<C-w>/w` | Go to current working directory (cwd) |
| `<C-t>/t` | Change nvim's cwd to selected folder/file(parent) |
| `<C-f>/f` | Toggle between file and folder browser |
| `<C-h>/h` | Toggle hidden files/folders |
| `<C-s>/s` | Toggle all entries ignoring `./` and `../` |

`path` denotes the folder the `file_browser` is currently in.

#### Remappings

As part of the [setup](#setup-and-configuration), you can remap actions as you like. The default mappings can also be found in this [file](https://github.com/nvim-telescope/telescope-file-browser.nvim/blob/master/lua/telescope/_extensions/file_browser.lua).
The code snippet below highlights how can customize your own mappings. It is not required to map the `telescope-file-browser`-specific defaults (telescope [defaults](https://github.com/nvim-telescope/telescope.nvim#default-mappings) not shown)! They are merely provided to simplify remapping.

```lua
local fb_actions = require "telescope".extensions.file_browser.actions
-- mappings in file_browser extension of telescope.setup
...
local actions = require "telescope.actions"

require("telescope").setup {
extensions = {
file_browser = {
mappings = {
["i"] = {
-- remap to going to home directory
["<C-h>"] = fb_actions.goto_home_dir
["<C-x>"] = function(prompt_bufnr)
-- your custom function
end
-- default insert mode mappings -- NOT NEEDED TO CONFIGURE
["<A-c>"] = fb_actions.create, -- create file/dir at `path` (trailing separator creates dir)
["<A-r>"] = fb_actions.rename, -- rename multi-selected files/folders
["<A-m>"] = fb_actions.move, -- move multi-selected files/folders to current `path`
["<A-y>"] = fb_actions.copy, -- copy multi-selected files/folders to current `path`
["<A-d>"] = fb_actions.remove, -- remove multi-selected files/folders to current `path`
["<A-o>"] = fb_actions.open, -- open file/folder with default system application

["<C-f>"] = fb_actions.toggle_browser, -- toggle between file and folder browser
["<C-h>"] = fb_actions.goto_parent_dir, -- goto parent directory; alias to normal-mode

["="] = fb_actions.change_cwd, -- change nvim cwd to selected file (parent) or folder
["~"] = fb_actions.goto_home_dir, -- go to home directory
["`"] = fb_actions.goto_cwd, -- go to cwd
["+"] = fb_actions.toggle_all, -- toggle selection of all shown entries ignoring `.` and `..`
[";"] = fb_actions.toggle_hidden, -- toggle showing hidden files and folders

-- remove a mapping
["KEY"] = false,

-- your custom function
["KEY"] = function(prompt_bufnr)
print("Implement your custom function; see actions.lua for inspiration")
end,

},
["n"] = {
-- unmap toggling `fb_actions.toggle_browser`
f = false,
-- default normal mode mappings -- NOT NEEDED TO CONFIGURE
["c"] = fb_actions.create, -- create file/dir at `path` (trailing separator creates dir)
["r"] = fb_actions.rename, -- rename multi-selected files/folders
["m"] = fb_actions.move, -- move multi-selected files/folders to current `path`
["y"] = fb_actions.copy, -- copy multi-selected files/folders to current `path`
["d"] = fb_actions.remove, -- remove multi-selected files/folders to current `path`
["o"] = fb_actions.open, -- open file/folder with default system application


-- normal mode movement
["h"] = actions.goto_parent_dir, -- goto parent directory
["j"] = actions.move_selection_next, -- next entry
["k"] = actions.move_selection_previous, -- previous entry
["l"] = actions.select_default, -- confirm selection

["f"] = fb_actions.toggle_browser, -- toggle between file and folder browser
["="] = fb_actions.change_cwd, -- change nvim cwd to selected file (parent) or folder
["~"] = fb_actions.goto_home_dir, -- go to home directory
["`"] = fb_actions.goto_cwd, -- go to home directory
["-"] = fb_actions.goto_parent_dir, -- change nvim cwd to selected file (parent) or folder
["+"] = fb_actions.toggle_all, -- toggle selection of all shown entries ignoring `.` and `..`
[";"] = fb_actions.toggle_hidden, -- toggle showing hidden files and folders

-- your custom normal mode mappings
...
},
...
},
},
},
}

```
See [fb_actions](https://github.com/nvim-telescope/telescope-file-browser.nvim/blob/master/lua/telescope/_extensions/file_browser/actions.lua) for a list of native actions and inspiration on how to write your own custom action. As additional reference, `plenary`'s [Path](https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/path.lua) library powers a lot of the built-in actions.

Once more, `path` denotes the folder the `file_browser` is currently in.

Furthermore, see [fb_actions](https://github.com/nvim-telescope/telescope-file-browser.nvim/blob/master/lua/telescope/_extensions/file_browser/actions.lua) for a list of native actions and inspiration on how to write your own custom action. As additional reference, `plenary`'s [Path](https://github.com/nvim-lua/plenary.nvim/blob/master/lua/plenary/path.lua) library powers a lot of the built-in actions.

For more information on `telescope` actions and remappings, see also the [upstream documentation](https://github.com/nvim-telescope/telescope.nvim#default-mappings) and associated vimdocs at `:h telescope.defaults.mappings`.

Expand Down
30 changes: 17 additions & 13 deletions lua/telescope/_extensions/file_browser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ local fb_actions = require "telescope._extensions.file_browser.actions"
local fb_finders = require "telescope._extensions.file_browser.finders"
local fb_picker = require "telescope._extensions.file_browser.picker"

local actions = require "telescope.actions"
local action_state = require "telescope.actions.state"
local action_set = require "telescope.actions.set"
local Path = require "plenary.path"
Expand All @@ -66,14 +67,14 @@ local pconf = {
["<A-m>"] = fb_actions.move,
["<A-y>"] = fb_actions.copy,
["<A-d>"] = fb_actions.remove,
["<C-o>"] = fb_actions.open,
["<C-e>"] = fb_actions.goto_home_dir,
["<C-w>"] = fb_actions.goto_cwd,
["<C-t>"] = fb_actions.change_cwd,
["<A-o>"] = fb_actions.open,
["<C-f>"] = fb_actions.toggle_browser,
["<C-h>"] = fb_actions.toggle_hidden,
["<C-s>"] = fb_actions.toggle_all,
["<C-b>"] = fb_actions.goto_parent_dir,
["<C-h>"] = fb_actions.goto_parent_dir,
["="] = fb_actions.change_cwd,
["~"] = fb_actions.goto_home_dir,
["`"] = fb_actions.goto_cwd,
["+"] = fb_actions.toggle_all,
[";"] = fb_actions.toggle_hidden,
},
["n"] = {
["c"] = fb_actions.create,
Expand All @@ -82,13 +83,16 @@ local pconf = {
["y"] = fb_actions.copy,
["d"] = fb_actions.remove,
["o"] = fb_actions.open,
["b"] = fb_actions.goto_parent_dir,
["e"] = fb_actions.goto_home_dir,
["w"] = fb_actions.goto_cwd,
["t"] = fb_actions.change_cwd,
["f"] = fb_actions.toggle_browser,
["h"] = fb_actions.toggle_hidden,
["s"] = fb_actions.toggle_all,
["h"] = fb_actions.goto_parent_dir,
["j"] = actions.move_selection_next,
["k"] = actions.move_selection_previous,
["l"] = actions.select_default,
["="] = fb_actions.change_cwd,
["~"] = fb_actions.goto_home_dir,
["`"] = fb_actions.goto_cwd,
["+"] = fb_actions.toggle_all,
[";"] = fb_actions.toggle_hidden,
},
},
attach_mappings = function(prompt_bufnr, _)
Expand Down

0 comments on commit f8e91ab

Please sign in to comment.