Why I Switched from NetRW to Oil.nvim
Being able to edit your directories in a buffer is a game changer.
I was using NetRW since beginning to use Neovim so that I could be familiar with a vanilla Vim experience.
I had used Neotree in the past but after better understanding how buffers, windows and tabs work, I didn’t want to clutter my viewport with a directory structure.
NetRW has served me well but it wasn’t incredibly seamless and I still don’t know a great way of moving files and directories around. I would usually drop into the terminal to perform those operations.
I needed a better tool and I wanted something besides another file tree.
Don’t get me wrong, Neotree is a great plugin and I use it to have context on where I am at in large applications but I don’t use it to find files to open and to navigate around.
In my opinion, Telescope, Harpoon and Ctrl-o, Ctrl-i allow me to quickly get to different files and stay in a flow state.
I also use it when pairing with non-vim users so they have a better idea of where we are and can keep track of jumping around different files.
This is when I discovered oil.nvim and loved the way it allowed you to edit your directories and files just like any other bufffer. I think this is a great companion for using fuzzy file finders and
gives you the ability to move files and directories across repos or directories with ease.
Let’s walk through the setup so you can start using oil.nvim as well.
Setting Up Oil.nvim
Install using lazy.nvim:
{
‘stevearc/oil.nvim’,
opts = {},
— Optional dependencies
dependencies = { “nvim-tree/nvim-web-devicons” },
config = function()
require(“oil”).setup()
end,
}
This will install and configure your plugin if you are using lazy.nvim. Make sure to call require(“oil”).setup()
if you are not using lazy.
If you want to mimc vim-vinegar
functionality then add this keymap into your config as well.
vim.keymap.set(“n”, “-”, “<CMD>Oil<CR>”, { desc = “Open parent directory” })
Let’s restart Neovim, then jump back into a file.
If you hit —
then you should see all the files in the directory. If you hit —
again you should go up a directory.
That’s the simplicity of navigating using oil.nvim.
Default Keymaps
If you want to toggle hidden files, use g.
If you want to open a preview, C-p
If you want to close the buffer C-c
If you want to open a vertical split C-s
Show help using g?
Now the fun part, you can rename files, move them around and delete them just like you would text in a buffer.
ciw
to change a filename, then write the buffer and you will be prompted to confirm your changesdiw
to delete a file, then write the buffer and you will be prompted to confirm your changesadd a new line and write to create a new file (you can even create a directory and file at the same time)
The real magic is in moving files, simply delete and go into another directory and paste that folder or file and see that it gets moved after writing
— this is the most seamless part of oil.nvim for me and why I have really grown to love it
gx gotcha
- for me gx stopped working because oil.nvim takes over for NetRW and gx comes from NetRW; which will open a URL in your browser
- to fix, simply install gx.nvim
Another feature of oil.nvim is you can copy files across SSH. I haven’t personally experimented with this but it’s cool to know it is a feature.
Conclusion
I hope this has given you some context on why oil.nvim is different from your typical directory explorer and how it integrates so well with
the editing experience in Vim to get you even more productive. What file explorer or directory viewer do you use? Let me know in the comments.
Here are other Neovim articles you should check out: