How do I manage files and directories as a regular Vim buffer?
Answer
oil.nvim: edit directory listing like a buffer
Explanation
oil.nvim presents directories as editable Vim buffers. You rename files by editing text, delete files by deleting lines, and create files by adding lines. It treats file management as a text editing problem — the most Vim-like file manager.
Setup
require('oil').setup()
vim.keymap.set('n', '-', '<CMD>Oil<CR>', { desc = 'Open parent directory' })
How it works
- Press
-to open the current file's directory - The directory listing appears as a normal buffer:
handlers/
models/
main.go
config.yaml
README.md
- Edit the buffer to manage files:
- Rename: change the filename text
- Delete: delete the line (
dd) - Create: add a new line with a filename
- Move: cut and paste lines between directories
- Press
<CR>on a directory to enter it - Press
-to go up one level - Save (
:w) to apply all changes
Example: Rename a file
" Change this line:
old-name.go
" To this:
new-name.go
" Then :w to apply
Example: Create a new file
" Add a line:
new-component.tsx
" Then :w to create it
Key features
- Preview: Press
<C-p>to preview files without opening - Hidden files: Press
g.to toggle hidden files - Trash: Deleted files go to trash (configurable)
- Cross-directory moves: Open two oil buffers in splits, cut/paste between them
Tips
- oil.nvim replaces netrw for most users — it's more intuitive and Vim-native
- All Vim motions work:
/search,ciwto rename part of a filename, etc. - Changes aren't applied until you save —
uundoes changes before saving - Works with
nvim-web-deviconsfor file type icons - Use
:Oil --floatfor a floating window variant - With 4k+ stars, oil.nvim is rapidly becoming the standard Neovim file manager