Skip to content
Open
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
96 changes: 64 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,47 +119,79 @@ 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-g>/g` | 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-a>"] = fb_actions.create, -- add 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
["a"] = fb_actions.create, -- add 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.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
16 changes: 8 additions & 8 deletions doc/telescope-file-browser.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ fb_picker.file_browser({opts}) *fb_picker.file_browser()*
Default keymaps in insert/normal mode:
- `<cr>`: opens the currently selected file, or navigates to the
currently selected directory
- `<A-c>/c`: Create file/folder at current `path` (trailing path
- `<A-a>/a`: 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-g>/g`: 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)
- `<A-o>/o`: Open file/folder with default system application
- `<C-h>/h`: Go to parent directory
- `~/~`: Go to home directory
- ``/``: Go to current working directory (cwd)
- `=/=`: 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 `../`
- `;/;`: Toggle hidden files/folders
- `+/+`: Toggle all entries ignoring `./` and `../`


Parameters: ~
Expand Down
34 changes: 19 additions & 15 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 @@ -61,34 +62,37 @@ local os_sep = Path.path.sep
local pconf = {
mappings = {
["i"] = {
["<A-c>"] = fb_actions.create,
["<A-a>"] = fb_actions.create,
["<A-r>"] = fb_actions.rename,
["<A-m>"] = fb_actions.move,
["<A-y>"] = fb_actions.copy,
["<A-d>"] = fb_actions.remove,
["<C-o>"] = fb_actions.open,
["<C-g>"] = fb_actions.goto_parent_dir,
["<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-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,
["a"] = fb_actions.create,
["r"] = fb_actions.rename,
["m"] = fb_actions.move,
["y"] = fb_actions.copy,
["d"] = fb_actions.remove,
["o"] = fb_actions.open,
["g"] = 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
16 changes: 8 additions & 8 deletions lua/telescope/_extensions/file_browser/picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ local fb_picker = {}
--- List, create, delete, rename, or move files and folders of your cwd.
--- Default keymaps in insert/normal mode:
--- - `<cr>`: opens the currently selected file, or navigates to the currently selected directory
--- - `<A-c>/c`: Create file/folder at current `path` (trailing path separator creates folder)
--- - `<A-a>/a`: 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-g>/g`: 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)
--- - `<A-o>/o`: Open file/folder with default system application
--- - `<C-h>/h`: Go to parent directory
--- - `~/~`: Go to home directory
--- - ``/``: Go to current working directory (cwd)
--- - `=/=`: 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 `../`
--- - `;/;`: Toggle hidden files/folders
--- - `+/+`: Toggle all entries ignoring `./` and `../`
---@param opts table: options to pass to the picker
---@field path string: dir to browse files from from (default: vim.loop.cwd())
---@field cwd string: dir to browse folders from, anchored by default to cwd (default: vim.loop.cwd())
Expand Down