Oil

Jan 22, 2025

So for reasons of plugins having breaking changes and the fact that my previous setup relied on a few plugins working together, I decided now was the time to leave my comfort zone of using vifm inside neovim.

To be clear I do still love vifm and use it as my primary file browser outside of neovim.

I looked at a few neotree style plugins but really loved the look and feel I was used to coming from vifm and was easily able to emulate that in Oil.

Oil is a vim-vinegar like file explorer, personally that means not a lot to me having not used vinegar but apparently that is a good thing to those in the know.

When running Oil you are presented with a list of your files in a buffer, this buffer is editable and allows you to change file names, delete files, etc. Just like you would edit a file normally in Neovim. It feels very natural and very fitting.

The Defaults

The out of the box look, also what you get by entering Neovim with:

nvim .

Default Oil

Activating the preview will display it to the left, in my opinion looks wrong on the left but it can be changed.

Ctrl+p or <C-p>

Default Oil

My Cofigs

I much prefer the floating style and this can be easily achieved by adding "--float" to the end of the command:

:Oil --float

Default Oil

As you saw above; the preview will normally appear to the left, however if you wish like me for the preview to be to the right then add the following to your init file:

require('oil').setup {
  -- Configuration for the floating window in oil.open_float                                              
float = {                                                                                               
  -- optionally override the oil buffers window title with custom function: fun(winid: integer): string 
  get_win_title = nil,                                                                                  
  -- preview_split: Split direction: "auto", "left", "right", "above", "below".                         
  preview_split = 'right',                                                                              
  -- This is the config that will be passed to nvim_open_win.                                           
  -- Change values here to customize the layout                                                         
  override = function(conf)                                                                             
    return conf                                                                                         
  end,                                                                                                  
},                                                                                                      
}

Default Oil

By default hidden files are hidden, if you wish to see them temporarily then use the keybind to view them:

g.

If instead you wish to have them shown by default then add the following to your init file:

require('oil').setup {                                                               
  view_options = {                                                                   
    -- Show files and directories that start with "."                                
    show_hidden = true,                                                              
    -- This function defines what is considered a "hidden" file                      
    is_hidden_file = function(name, bufnr)                                           
      local m = name:match '^%.'                                                     
      return m ~= nil                                                                
    end,                                                                             
    -- This function defines what will never be shown, even when `show_hidden` is set
    is_always_hidden = function(name, bufnr)                                         
      return false                                                                   
    end,                                                                             
    -- Sort file names with numbers in a more intuitive order for humans.            
    -- Can be "fast", true, or false. "fast" will turn it off for large directories. 
    natural_order = 'fast',                                                          
    -- Sort file and directory names case insensitive                                
    case_insensitive = false,                                                        
    sort = {                                                                         
      -- sort order can be "asc" or "desc"                                           
      -- see :help oil-columns to see which columns are sortable                     
      { 'type', 'asc' },                                                             
      { 'name', 'asc' },                                                             
    },                                                                               
  },                                                                                 
}

To set a keybind your preferred keybind to invoke Oil:

vim.keymap.set('n', '<leader>e', ':Oil --float<CR>')

Finally if you wish to copy my setup in full:

vim.keymap.set('n', '<space>e', ':Oil --float<CR>')                                                      
                                                                                                         
require('oil').setup {                                                                                   
  view_options = {                                                                                       
    -- Show files and directories that start with "."                                                    
    show_hidden = true,                                                                                  
    -- This function defines what is considered a "hidden" file                                          
    is_hidden_file = function(name, bufnr)                                                               
      local m = name:match '^%.'                                                                         
      return m ~= nil                                                                                    
    end,                                                                                                 
    -- This function defines what will never be shown, even when `show_hidden` is set                    
    is_always_hidden = function(name, bufnr)                                                             
      return false                                                                                       
    end,                                                                                                 
    -- Sort file names with numbers in a more intuitive order for humans.                                
    -- Can be "fast", true, or false. "fast" will turn it off for large directories.                     
    natural_order = 'fast',                                                                              
    -- Sort file and directory names case insensitive                                                    
    case_insensitive = false,                                                                            
    sort = {                                                                                             
      -- sort order can be "asc" or "desc"                                                               
      -- see :help oil-columns to see which columns are sortable                                         
      { 'type', 'asc' },                                                                                 
      { 'name', 'asc' },                                                                                 
    },                                                                                                   
  },                                                                                                     
  -- Configuration for the floating window in oil.open_float                                             
  float = {                                                                                              
    -- optionally override the oil buffers window title with custom function: fun(winid: integer): string
    get_win_title = nil,                                                                                 
    -- preview_split: Split direction: "auto", "left", "right", "above", "below".                        
    preview_split = 'right',                                                                             
    -- This is the config that will be passed to nvim_open_win.                                          
    -- Change values here to customize the layout                                                        
    override = function(conf)                                                                            
      return conf                                                                                        
    end,                                                                                                 
  },                                                                                                     
}                                                                                                        

Get Oil

https://github.com/stevearc/oil.nvim