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

How do I rename, move, and delete files by editing the filesystem like a buffer with oil.nvim?

Answer

:Oil

Explanation

oil.nvim reimagines file management by presenting a directory as an ordinary Vim buffer. Every entry is just text, so you rename by editing words, delete by removing lines, and create files by adding them — then :w commits all changes atomically to disk. It is especially powerful because it means every Vim motion, operator, and macro you already know can be used for file management.

How it works

  • :Oil opens the current file's parent directory as an editable buffer
  • :Oil /path/to/dir opens any specific directory
  • Each line represents a file or subdirectory — edit the name to rename it
  • Delete a line with dd to stage that file for deletion
  • Add a new line (e.g., o + type a name) to create a new file
  • :w applies all staged changes: renames, deletions, and creations happen together
  • Press <CR> to enter a subdirectory or open a file

Example

After :Oil, the buffer might show:

../
README.md
build.sh
config.json
old_notes.txt

Rename build.sh to deploy.sh using ciw on that word. Delete old_notes.txt with dd. Press :w — oil.nvim applies both changes atomically.

Tips

  • The default keybinding - opens oil in the current file's directory (if configured with require('oil').setup())
  • Use g? inside the oil buffer to see all available mappings
  • oil.nvim supports SSH via oil-ssh://user@host/path for remote file management
  • Unlike netrw, oil buffers are real Vim buffers so you can yank filenames with yy or use / to search

Next

How do I incrementally expand or shrink a selection based on syntax tree nodes using nvim-treesitter?