4.8 KiB
🍿 explorer
A file explorer for snacks. This is actually a picker in disguise.
This module provide a shortcut to open the explorer picker and a setup function to replace netrw with the explorer.
When the explorer and replace_netrw is enabled, the explorer will be opened:
- when you start
nvimwith a directory - when you open a directory in vim
Configuring the explorer picker is done with the picker options.
-- lazy.nvim
{
"folke/snacks.nvim",
---@type snacks.Config
opts = {
explorer = {
-- your explorer configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
},
picker = {
sources = {
explorer = {
-- your explorer picker configuration comes here
-- or leave it empty to use the default settings
}
}
}
}
}
🚀 Usage
File Operations
The explorer provides powerful file operations with an intuitive selection-based workflow.
Moving and Copying Files
The most efficient way to move or copy multiple files:
- Select files with
<Tab>(works on multiple files) - Navigate to the target directory
- Execute the operation:
- Press
mto move selected files to the current directory - Press
cto copy selected files to the current directory
- Press
Example workflow:
1. Navigate to source files
2. Press <Tab> on file1.txt
3. Press <Tab> on file2.txt (both now selected)
4. Navigate to target directory
5. Press 'm' → files are moved!
Single file operations:
mon a single file (no selection) → renames the filecon a single file (no selection) → prompts for new name to copy tor→ rename current filed→ delete current/selected files
Copy/Paste with Registers
Alternative workflow using yank and paste:
- Select files with
<Tab>or visual mode - Press
yto yank file paths to register - Navigate to target directory
- Press
pto paste (copies files from register)
This works across different explorer instances and even after closing/reopening!
Other File Operations
a→ Add new file or directory (directories end with/)d→ Delete files (uses system trash if available, see:checkhealth snacks)o→ Open file with system applicationu→ Update/refresh the file tree
Navigation
<CR>orl→ Open file or toggle directoryh→ Close directory<BS>→ Go up one directory.→ Focus on current directory (set as cwd)H→ Toggle hidden filesI→ Toggle ignored files (from gitignore)Z→ Close all directories
Quick Actions
<leader>/→ Grep in current directory<c-t>→ Open terminal in current directory<c-c>→ Change tab directory to current directoryP→ Toggle preview
Git Integration
When git_status = true (default), files show git status indicators:
]g/[g→ Jump to next/previous git change- Directories show aggregate status of contained files
Diagnostics
When diagnostics = true (default), files show diagnostic indicators:
]d/[d→ Jump to next/previous diagnostic]e/[e→ Jump to next/previous error]w/[w→ Jump to next/previous warning
Visual Mode
You can use visual mode (v or V) to select multiple files, then:
y→ Yank selected file paths- Any other operation works on visual selection
📦 Setup
-- lazy.nvim
{
"folke/snacks.nvim",
---@type snacks.Config
opts = {
explorer = {
-- your explorer configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
}
}
}
⚙️ Config
These are just the general explorer settings.
To configure the explorer picker, see snacks.picker.explorer.Config
---@class snacks.explorer.Config
{
replace_netrw = true, -- Replace netrw with the snacks explorer
trash = true, -- Use the system trash when deleting files
}
📦 Module
Snacks.explorer()
---@type fun(opts?: snacks.picker.explorer.Config): snacks.Picker
Snacks.explorer()
Snacks.explorer.health()
Snacks.explorer.health()
Snacks.explorer.open()
Shortcut to open the explorer picker
---@param opts? snacks.picker.explorer.Config|{}
Snacks.explorer.open(opts)
Snacks.explorer.reveal()
Reveals the given file/buffer or the current buffer in the explorer
---@param opts? {file?:string, buf?:number}
Snacks.explorer.reveal(opts)