Discovering Vim : Netrw 
Tags: vim, neovim, productivity, linux
Published: 2021-10-02 10:09:05

Do you use a file explorer in vim ? I guess it probably is something like [this](https://github.com/preservim/nerdtree), [this](https://github.com/kyazdani42/nvim-tree.lua) or maybe [this](https://github.com/ms-jpq/chadtree). While all these are fancy looking with icons and stuff there is a file tree and explorer in vim already. It is not the best file-explorer honestly but it works and is faster than most of these. Yes I am talking about the good ol' netrw. 

Now the stuff I am talking here is very limited to basic needs only and you can obviously see `:h netrw` if you want to know more. 

So anyway here's a breif guide. Firstly let's talk what should I be able to do with any file explorer. 

1. add file and directory 
2. delete file and directory 

So well let's start with opening some new directory called `tmp`. Now in this `tmp` directory suppose I want to add a file. So In vim I do `:Explore`. Now explore opens netrw for the file-directory ( also try doing explore in any help menu it opens all the files linked to that help article). After Opening Explore you will see a empty directory like this. 
![Empty Directory](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93vjw8xvp495sridtuzc.png)

Now I wan't to add a file to this directory. I can press `%` key in netrw and that will show this prompt. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/738hrud09iz6zicc31gt.png)
Add the file name press enter and bam! Netrw will open the file in new buffer. Now u can add text to same file and save it. After Saving the file Try doing `:Explore` again and now you will see the new file. 
To remove this file you can press `D` key that will bring up another prompt looking like this. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09mlwpok0tq3rbytja66.png)

You can add a directory by doing `d` and delete it too with `D`. This enough for most of the work I need to do with file explorer. I do rest with normal `mv` or `cp`. Now let's say you want this netrw to be displayed while editing file and you don't like how netrw looks. Well netrw can be configured with global vim variables. Here's my netrw settings. 

```viml
" This get's rif of that stupid banner
let g:netrw_banner = 0

" netrw has liststyle types which you can search in \:help netrw
let g:netrw_liststyle = 2 

" If you have wildignore set
let g:netrw_list_hide = &wildignore

" size of window
let g:netrw_winsize = 25

```  
Again Look at `:help netrw` to see what do these do. Some other good commands are `:Lex` for opening Lexplore which a split view of netrw. Do `:Lex!` to get a funky right side view like me. There is also `:Hexplore`, `:Rexplore`, `:Sexplore` and `:Texplore`. Most of these are for opening netrw in different directions which again is really cool. 

## Further Reading
For further reading check out these articles : 
- [netrw.vim](https://www.vim.org/scripts/script.php?script_id=1075#:~:text=Netrw%20supports%20reading%20and%20writing,using%20a%20variety%20of%20methods.)
- [You don't need a nerd tree maybe !](https://shapeshed.com/vim-netrw/)
- [What's wrong with netrw](https://www.reddit.com/r/vim/comments/22ztqp/why_does_nerdtree_exist_whats_wrong_with_netrw/)
- [netrw docs](http://vimdoc.sourceforge.net/htmldoc/pi_netrw.html#netrw)
- [good vimcast on project drawers](http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/)
- [tpope plugin to improve netrw](https://github.com/tpope/vim-vinegar)

Yup that's all for today. I wrote this cause sometimes we don't really need some external plugins. There are some issues with netrw. But most of the time it works without any problems. Again I just wanted people to acknowledge netrw a bit more and then decide to choose for other file explorers.