2

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?

3

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)

2

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

  • This isn't quite what I asked for, but it was close enough for me to figure it out. Upvoted. – Andrew Jan 23 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.