netrw has a gh command that toggles dotfile hiding. It is off by default. I would like it to be on by default. How do I do that?
2 Answers
gh works by modifying netrw_list_hide, rather than by toggling a separate flag. It appends or removes the regex \(^\|\s\s\)\zs\.\S\+. As far as I can tell, said regex matches "a dot followed by any number of non-whitespace characters, starting either at the beginning of the string or after two spaces." I'm not sure why the two spaces, but would be interested to know.
Adding it yourself is straightforward enough:
" If you don't have a hide list and just want to use gh's:
let ghregex='\(^\|\s\s\)\zs\.\S\+'
let g:netrw_list_hide=ghregex
" Or, if you already have a usual hide list, append it
let g:netrw_list_hide='yourhidelist'
let g:netrw_list_hide.=',' . ghregex
In both cases vim will then recognize that gh is toggled on, and typing gh will turn it off.
The regex is hardcoded and not available as a variable (unless your make one yourself, as above), so in principle this will break if it changes. That line hasn't been touched in eleven years, though. It's probably pretty safe to rely on.
(credit to this answer for pointing me in the right direction)
- 393
- 2
- 10
You can try this on your .vimrc:
let g:netrw_list_hide = '^\..*' " or anything you like
let g:netrw_hide = 1 " hide by default
help netrw-a can give you more information.
HTH
- 773
- 5
- 11
-
This isn't quite what I asked for, but it was close enough for me to figure it out. Upvoted. – Andrew Jan 23 '19 at 18:15
-
Here's a one line saving : The documentation says that
g:netrw_hide = 1is the default, so no need for that – cassepipe May 19 '22 at 16:08
ghcommand is what I needed to know, lovely. – helvete Dec 22 '22 at 17:06