DEV Community

Pratham Sharma
Pratham Sharma

Posted on

Discovering Vim : Netrw

Do you use a file explorer in vim ? I guess it probably is something like this, this or maybe this. 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

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
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

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.

" 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

Enter fullscreen mode Exit fullscreen mode

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 :

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.

Top comments (4)

ps173 profile image
Pratham Sharma

Thanks a lot for taking time to read. I have already listened to this talk, perhaps I should have linked in intro.
I don't really use terminal for creating files but I can see why people use it. I just don't like to quit out of vim in most of the cases. So I just use shell commands from vim if I like to move lot of files

ps173 profile image
Pratham Sharma

Oh yeah now you don't need to quit to use terminal. When I started vim didn't have the term feature. I often forget about it haha