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

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 :w to rename it on disk
  • dd a line then :w to delete the file
  • yy + p to duplicate a file, then rename the copy
  • o + 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 --float opens 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 = true replaces netrw so vim . opens oil automatically

Next

What is the difference between the inner word (iw) and inner WORD (iW) text objects in Vim?