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.
- add file and directory
- 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.
Now I wan't to add a file to this directory. I can press
% key in netrw and that will show this prompt.
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.
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
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
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
:Texplore. Most of these are for opening netrw in different directions which again is really cool.
For further reading check out these articles :
- You don't need a nerd tree maybe !
- What's wrong with netrw
- netrw docs
- good vimcast on project drawers
- tpope plugin to improve netrw
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.