Skip to content

Commit 87181e1

Browse files
committed
rfc!: mappings
1 parent 0ea5512 commit 87181e1

File tree

3 files changed

+91
-55
lines changed

3 files changed

+91
-55
lines changed

README.md

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -119,47 +119,79 @@ Note: `path` corresponds to the folder the `file_browser` is currently in.
119119

120120
`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.
121121

122-
| Insert / Normal | Action |
123-
|-----------------|-------------------------------------------------------------------------------|
124-
| `<A-c>/c` | Create file/folder at current `path` (trailing path separator creates folder) |
125-
| `<A-r>/r` | Rename multi-selected files/folders |
126-
| `<A-m>/m` | Move multi-selected files/folders to current `path` |
127-
| `<A-y>/y` | Copy (multi-)selected files/folders to current `path` |
128-
| `<A-d>/d` | Delete (multi-)selected files/folders |
129-
| `<C-o>/o` | Open file/folder with default system application |
130-
| `<C-b>/b` | Go to parent directory |
131-
| `<C-e>/e` | Go to home directory |
132-
| `<C-w>/w` | Go to current working directory (cwd) |
133-
| `<C-t>/t` | Change nvim's cwd to selected folder/file(parent) |
134-
| `<C-f>/f` | Toggle between file and folder browser |
135-
| `<C-h>/h` | Toggle hidden files/folders |
136-
| `<C-s>/s` | Toggle all entries ignoring `./` and `../` |
137-
138-
`path` denotes the folder the `file_browser` is currently in.
139-
140-
#### Remappings
141-
142-
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).
122+
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.
143123

144124
```lua
145125
local fb_actions = require "telescope".extensions.file_browser.actions
146-
-- mappings in file_browser extension of telescope.setup
147-
...
126+
local actions = require "telescope.actions"
127+
128+
require("telescope").setup {
129+
extensions = {
130+
file_browser = {
148131
mappings = {
149132
["i"] = {
150-
-- remap to going to home directory
151-
["<C-h>"] = fb_actions.goto_home_dir
152-
["<C-x>"] = function(prompt_bufnr)
153-
-- your custom function
154-
end
133+
-- default insert mode mappings -- NOT NEEDED TO CONFIGURE
134+
["<A-a>"] = fb_actions.create, -- add file/dir at `path` (trailing separator creates dir)
135+
["<A-r>"] = fb_actions.rename, -- rename multi-selected files/folders
136+
["<A-m>"] = fb_actions.move, -- move multi-selected files/folders to current `path`
137+
["<A-y>"] = fb_actions.copy, -- copy multi-selected files/folders to current `path`
138+
["<A-d>"] = fb_actions.remove, -- remove multi-selected files/folders to current `path`
139+
["<A-o>"] = fb_actions.open, -- open file/folder with default system application
140+
141+
["<C-f>"] = fb_actions.toggle_browser, -- toggle between file and folder browser
142+
["<C-h>"] = fb_actions.goto_parent_dir, -- goto parent directory; alias to normal-mode
143+
144+
["="] = fb_actions.change_cwd, -- change nvim cwd to selected file (parent) or folder
145+
["~"] = fb_actions.goto_home_dir, -- go to home directory
146+
["`"] = fb_actions.goto_cwd, -- go to cwd
147+
["+"] = fb_actions.toggle_all, -- toggle selection of all shown entries ignoring `.` and `..`
148+
[";"] = fb_actions.toggle_hidden, -- toggle showing hidden files and folders
149+
150+
-- remove a mapping
151+
["KEY"] = false,
152+
153+
-- your custom function
154+
["KEY"] = function(prompt_bufnr)
155+
print("Implement your custom function; see actions.lua for inspiration")
156+
end,
157+
155158
},
156159
["n"] = {
157-
-- unmap toggling `fb_actions.toggle_browser`
158-
f = false,
160+
-- default normal mode mappings -- NOT NEEDED TO CONFIGURE
161+
["a"] = fb_actions.create, -- add file/dir at `path` (trailing separator creates dir)
162+
["r"] = fb_actions.rename, -- rename multi-selected files/folders
163+
["m"] = fb_actions.move, -- move multi-selected files/folders to current `path`
164+
["y"] = fb_actions.copy, -- copy multi-selected files/folders to current `path`
165+
["d"] = fb_actions.remove, -- remove multi-selected files/folders to current `path`
166+
["o"] = fb_actions.open, -- open file/folder with default system application
167+
168+
169+
-- normal mode movement
170+
["h"] = actions.goto_parent_dir, -- goto parent directory
171+
["j"] = actions.move_selection_next, -- next entry
172+
["k"] = actions.move_selection_previous, -- previous entry
173+
["l"] = actions.select_default, -- confirm selection
174+
175+
["f"] = fb_actions.toggle_browser, -- toggle between file and folder browser
176+
["="] = fb_actions.change_cwd, -- change nvim cwd to selected file (parent) or folder
177+
["~"] = fb_actions.goto_home_dir, -- go to home directory
178+
["`"] = fb_actions.goto_cwd, -- go to home directory
179+
["+"] = fb_actions.toggle_all, -- toggle selection of all shown entries ignoring `.` and `..`
180+
[";"] = fb_actions.toggle_hidden, -- toggle showing hidden files and folders
181+
182+
-- your custom normal mode mappings
183+
...
159184
},
160-
...
185+
},
186+
},
187+
},
188+
}
189+
161190
```
162-
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.
191+
192+
Once more, `path` denotes the folder the `file_browser` is currently in.
193+
194+
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.
163195

164196
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`.
165197

lua/telescope/_extensions/file_browser.lua

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ local fb_actions = require "telescope._extensions.file_browser.actions"
5353
local fb_finders = require "telescope._extensions.file_browser.finders"
5454
local fb_picker = require "telescope._extensions.file_browser.picker"
5555

56+
local actions = require "telescope.actions"
5657
local action_state = require "telescope.actions.state"
5758
local action_set = require "telescope.actions.set"
5859
local Path = require "plenary.path"
@@ -61,34 +62,37 @@ local os_sep = Path.path.sep
6162
local pconf = {
6263
mappings = {
6364
["i"] = {
64-
["<A-c>"] = fb_actions.create,
65+
["<A-a>"] = fb_actions.create,
6566
["<A-r>"] = fb_actions.rename,
6667
["<A-m>"] = fb_actions.move,
6768
["<A-y>"] = fb_actions.copy,
6869
["<A-d>"] = fb_actions.remove,
69-
["<C-o>"] = fb_actions.open,
70-
["<C-e>"] = fb_actions.goto_home_dir,
71-
["<C-w>"] = fb_actions.goto_cwd,
72-
["<C-t>"] = fb_actions.change_cwd,
70+
["<A-o>"] = fb_actions.open,
7371
["<C-f>"] = fb_actions.toggle_browser,
74-
["<C-h>"] = fb_actions.toggle_hidden,
75-
["<C-s>"] = fb_actions.toggle_all,
76-
["<C-b>"] = fb_actions.goto_parent_dir,
72+
["<C-h>"] = fb_actions.goto_parent_dir,
73+
["="] = fb_actions.change_cwd,
74+
["~"] = fb_actions.goto_home_dir,
75+
["`"] = fb_actions.goto_cwd,
76+
["+"] = fb_actions.toggle_all,
77+
[";"] = fb_actions.toggle_hidden,
7778
},
7879
["n"] = {
79-
["c"] = fb_actions.create,
80+
["a"] = fb_actions.create,
8081
["r"] = fb_actions.rename,
8182
["m"] = fb_actions.move,
8283
["y"] = fb_actions.copy,
8384
["d"] = fb_actions.remove,
8485
["o"] = fb_actions.open,
85-
["b"] = fb_actions.goto_parent_dir,
86-
["e"] = fb_actions.goto_home_dir,
87-
["w"] = fb_actions.goto_cwd,
88-
["t"] = fb_actions.change_cwd,
8986
["f"] = fb_actions.toggle_browser,
90-
["h"] = fb_actions.toggle_hidden,
91-
["s"] = fb_actions.toggle_all,
87+
["h"] = fb_actions.goto_parent_dir,
88+
["j"] = actions.move_selection_next,
89+
["k"] = actions.move_selection_previous,
90+
["l"] = actions.select_default,
91+
["="] = fb_actions.change_cwd,
92+
["~"] = fb_actions.goto_home_dir,
93+
["`"] = fb_actions.goto_cwd,
94+
["+"] = fb_actions.toggle_all,
95+
[";"] = fb_actions.toggle_hidden,
9296
},
9397
},
9498
attach_mappings = function(prompt_bufnr, _)

lua/telescope/_extensions/file_browser/picker.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ local fb_picker = {}
2828
--- List, create, delete, rename, or move files and folders of your cwd.
2929
--- Default keymaps in insert/normal mode:
3030
--- - `<cr>`: opens the currently selected file, or navigates to the currently selected directory
31-
--- - `<A-c>/c`: Create file/folder at current `path` (trailing path separator creates folder)
31+
--- - `<A-a>/a`: Create file/folder at current `path` (trailing path separator creates folder)
3232
--- - `<A-r>/r`: Rename multi-selected files/folders
3333
--- - `<A-m>/m`: Move multi-selected files/folders to current `path`
3434
--- - `<A-y>/y`: Copy (multi-)selected files/folders to current `path`
3535
--- - `<A-d>/d`: Delete (multi-)selected files/folders
36-
--- - `<C-o>/o`: Open file/folder with default system application
37-
--- - `<C-b>/b`: Go to parent directory
38-
--- - `<C-e>/e`: Go to home directory
39-
--- - `<C-w>/w`: Go to current working directory (cwd)
40-
--- - `<C-t>/t`: Change nvim's cwd to selected folder/file(parent)
36+
--- - `<A-o>/o`: Open file/folder with default system application
37+
--- - `<C-h>/h`: Go to parent directory
38+
--- - `~/~`: Go to home directory
39+
--- - ``/``: Go to current working directory (cwd)
40+
--- - `=/=`: Change nvim's cwd to selected folder/file(parent)
4141
--- - `<C-f>/f`: Toggle between file and folder browser
42-
--- - `<C-h>/h`: Toggle hidden files/folders
43-
--- - `<C-s>/s`: Toggle all entries ignoring `./` and `../`
42+
--- - `;/;`: Toggle hidden files/folders
43+
--- - `+/+`: Toggle all entries ignoring `./` and `../`
4444
---@param opts table: options to pass to the picker
4545
---@field path string: dir to browse files from from (default: vim.loop.cwd())
4646
---@field cwd string: dir to browse folders from, anchored by default to cwd (default: vim.loop.cwd())

0 commit comments

Comments
 (0)