How do I set up oil.nvim to manage files using Vim's full editing power including macros and visual selections?
Answer
stevearc/oil.nvim
Explanation
oil.nvim presents the filesystem as a regular Neovim buffer. Files and directories appear as text lines you can edit using the full power of Vim — visual selections, macros, substitute, and dot-repeat — to rename, move, create, and delete files. Changes only apply when you save the buffer with :w.
How it works
Install with lazy.nvim:
{
'stevearc/oil.nvim',
opts = {
default_file_explorer = true, -- replace netrw
columns = { 'icon', 'permissions', 'size', 'mtime' },
keymaps = {
['<CR>'] = 'actions.select',
['-'] = 'actions.parent',
['_'] = 'actions.open_cwd',
},
view_options = { show_hidden = true },
},
keys = { { '-', '<CMD>Oil<CR>', desc = 'Open parent directory' } },
}
In the oil buffer:
- Edit a filename then
:wto rename it on disk dda line then:wto delete the fileyy+pto duplicate a file, then rename the copyo+ type filename to create a new file
Example
Bulk-rename all .txt files to .md using substitute:
:s/\.txt$/.md/g " edit all visible .txt entries
:w " apply renames to disk
Or use a macro to prefix each filename with draft-.
Tips
:Oil --floatopens a floating directory window for quick edits without leaving the current buffer- Press
-from any buffer to instantly open oil in its parent directory - Use
g?inside oil to see all available keymaps - Setting
default_file_explorer = truereplaces netrw sovim .opens oil automatically