https://github.com/grecodavide/file_browser.nvim
A file browser for neovim
https://github.com/grecodavide/file_browser.nvim
lua neovim neovim-plugin nvim
Last synced: 11 months ago
JSON representation
A file browser for neovim
- Host: GitHub
- URL: https://github.com/grecodavide/file_browser.nvim
- Owner: grecodavide
- Created: 2024-12-31T11:32:42.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-03T13:52:20.000Z (about 1 year ago)
- Last Synced: 2025-01-12T15:15:21.833Z (about 1 year ago)
- Topics: lua, neovim, neovim-plugin, nvim
- Language: Lua
- Homepage:
- Size: 110 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# file_browser.nvim
This plugin aims to provide a file browser similar to the one provided by [telescope file browser extension](https://github.com/nvim-telescope/telescope-file-browser.nvim)
without necessarily using telescope.
# TOC
- [External Dependencies](#external-dependencies)
- [Features](#features)
- [Showcase](#showcase)
- [Available Actions](#available-actions)
- [Default Mappings](#default-mappings)
- [Custom Types](#custom-types)
- [Configuration](#configuration)
- [Setup](#setup)
- [Usage](#usage)
- [WIP](#wip)
## External dependencies
- `fzf`
- `fd`
## Features
- Treesitter preview
- Preview debouncing
- Basic file actions (move, rename, creation, deletion...)
- Bulk rename
## Showcase

## Available Actions
| Action | Argument | Description |
| --------------- | --------------- | ---------- |
|`scroll_preview_up` | `{}` | Scrolls the preview up |
|`scroll_preview_down` | `{}` | Scrolls the preview down |
|`default` | `{cd: boolean?}` | If current entry is a directory, go to it, else open the file. If `cd` is true, updates neovim cwd |
|`move_to_cwd` | `{delete_selection: boolean?}` | Moves selection to cwd. By default, after a successful move, it will also remove from the marked list. Passing `false` to this call will avoid that |
|`copy_to_cwd` | `{delete_selection: boolean?}` | Copies selection to cwd. By default, after a successful move, it will also remove from the marked list. Passing `false` to this call will avoid that |
|`cd` | `{}` | Changes nvim CWD to this plugin's |
|`rename` | `{}` | Renames current entry |
|`mark_current` | `{}` | Marks current entry as selected |
|`delete` | `{force: boolean?, ask_confirmation: boolean?}` | Deletes a file/folder. `force` is false by default, and `ask_confirmation` true by default |
|`close` | `{}` | Closes all this plugin's windows |
|`create` | `{jump: boolean?}` | Creates a file/folder. Can be nested. Unless `jump` is set to `false`, also cd to directory/open file created |
|`goto_parent` | `{start_insert: boolean?}` | Goes to parent directory. Unless `start_insert` is set to false, puts in insert mode |
|`goto_parent_or_delete` | `{}` | If prompt is empty, go to parent directory. Otherwise, behave like a regular `` |
|`jump_to` | `{index: number, absolute: boolean?}` | Jump to given entry (considered relative unless `absolute` is set to true |
|`open_split` | `{vertical: boolean?}` | If current entry is a file, opens it in a split. Defaults to vsplit |
|`bulk_rename` | `{ask_override: boolean?, delete_selection: boolean?}` | Bulk rename selection. If `ask_override` is set to true it will ask the user whether to override already existing file, otherwise will simply not override it. Unless `delete_selection` is set to `false`, it will also delete selection |
## Default mappings
| Mode | Mapping | Action | Arguments |
| --------------- | --------------- | ---------- | ---------- |
| `n` | `` | `close` | `{}` |
| `{n, i}` | `` | `mark_current` | `{}` |
| `{n, i}` | `` | `move_to_cwd` | `{}` |
| `{n, i}` | `` | `copy_to_cwd` | `{}` |
| `i` | `` | `cd` | `{}` |
| `n` | `.` | `cd` | `{}` |
| `n` | `r` | `rename` | `{}` |
| `n` | `R` | `bulk_rename` | `{}` |
| `{n, i}` | `` | `scroll_preview_down` | `{}` |
| `{n, i}` | `` | `scroll_preview_up` | `{}` |
| `{n, i}` | `` | `jump` | `{1}` |
| `n` | `j` | `jump` | `{1}` |
| `{n, i}` | `` | `jump` | `{-1}` |
| `n` | `k` | `jump` | `{-1}` |
| `{n, i}` | `` | `default` | `{}` |
| `{n, i}` | `` | `default` | `{true}` |
| `{n, i}` | `` | `open_split` | `{}` |
| `{n, i}` | `` | `create` | `{}` |
| `n` | `e` | `create` | `{}` |
| `{n, i}` | `` | `delete` | `{true}` |
| `n` | `d` | `delete` | `{true}` |
| `{n, i}` | `` | `goto_parent_or_delete` | `{}` |
## Custom Types
| Option | Type |
| --------------- | --------------- |
| `file_browser.Mapping` | `{mode: string\|string[], lhs: string, callback:string\|function, args: table?}` |
| `file_browser.Icon` | `{text: string, hl: string}` |
## Configuration
| Option | Type | Description |
| --------------- | --------------- | ---------- |
| `start_insert` | `boolean` | Whether we should start in insert mode. Defaults to true |
| `display_symlinks` | `boolean` | Wehter we should show symlinks or not. Defaults to true |
| `width_scale` | `number` | Defaults to 0.92 |
| `height_scale` | `number` | Defaults to 0.92 |
| `show_hidden` | `boolean` | Defaults to true |
| `show_links` | `boolean` | Defaults to true |
| `marked_icon` | `file_browser.Icon` | Icons used for marks |
| `debounce` | `number` | debounce for preview (in ms) |
| `preview_width` | `number` | percentage of floating win to be used for preview |
| `max_prompt_size` | `number` | max size (percentage) of prompt prefix |
| `use_treesitter` | `boolean` | Defaults to true |
| `mappings` | `file_browser.Mapping[]?` | Mappings |
| `use_default_mappings` | `boolean?` | Use a default set of mappings. Defaults to true |
| `group_dirs` | `boolean?` | Whether directories should be grouped at the top |
| `respect_ignore` | `boolean?` | Whether `.gitignore` and similar should be respected. Defaults to true |
| `segments` | `number?` | How many segments of path to show at most in promot. If left empty, it will display as many of them as possible |
## Setup
Example using lazy:
```lua
return {
"grecodavide/file_browser.nvim",
dependencies = {
"echasnovski/mini.icons" -- to display file icons
},
lazy = true,
config = function()
require("file_browser").setup({
width_scale = 0.9,
height_scale = 0.8,
mappings = {
{
mode = "i",
lhs = "",
callback = "rename"
}
}
})
end,
-- I like to have fe to open file browser in the same path as current file, and fE in the CWD
keys = {
{
"fe",
function()
require("file_browser").open(vim.fn.expand("%:p:h"))
end,
desc = "[F]ile [E]xplorer current file",
},
{
"fE",
function()
require("file_browser").open()
end,
desc = "[F]ile [E]xplorer CWD",
},
}
}
```
## Usage
Open the plugin window by calling `require("file_browser").open(cwd?)`, and navigate with your mappings (default is `` and ``).
You can mark the currently selected entry with ``
> [!WARNING]
> functions that modify a buffer's text must be called synchronously, so
> be careful hovering too big of a file, as it could lock you for a while
## WIP
- [ ] Preview timeout
# Credits
Layout and behavior is inspired by [telescope file browser](https://github.com/nvim-telescope/telescope-file-browser.nvim)