vimtricks.wiki Concise Vim tricks, one at a time.

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

  1. Press - to open the current file's directory
  2. The directory listing appears as a normal buffer:
  handlers/
  models/
  main.go
  config.yaml
  README.md
  1. 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
  2. Press <CR> on a directory to enter it
  3. Press - to go up one level
  4. 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, ciw to rename part of a filename, etc.
  • Changes aren't applied until you save — u undoes changes before saving
  • Works with nvim-web-devicons for file type icons
  • Use :Oil --float for a floating window variant
  • With 4k+ stars, oil.nvim is rapidly becoming the standard Neovim file manager

Next

How do I run the same command across all windows, buffers, or tabs?