0

When I open a directory in netrw, the .. directory at the top is selected by default

enter image description here

How can I make netrw always select the first listing that is not .. or . by default instead?


Thanks to a comment, I tried changing the sort order to put .. and . at the bottom of the list. So I've tried setting

:let g:netrw_sort_sequence='[\/]$,,\.bak$,\.o$,\.h$,\.info$,\.swp$,\.obj$,^\(?!\.|\.\.\)$'

But my netrw looks exactly the same after doing this.

I thought the extra pattern ^\(?!\.|\.\.\)$ would match any name that is NOT . or .. exactly, and then sort those before sorting .. and ..

3
  • 1
    Some lateral thinking: a different sort, or hiding hidden files?
    – D. Ben Knoble
    Commented Feb 17 at 15:34
  • @D.BenKnoble oh thanks! Good idea, so I just checked and found g:netrw_sort_sequence, and I tried setting it to the default one with an extra ^\(?!\.|\.\.\)$, but it didn't do what I thought it would
    – user9024
    Commented Feb 17 at 16:29
  • It’s worth editing in rather than leaving in the comments
    – D. Ben Knoble
    Commented Feb 17 at 20:21

1 Answer 1

0

I wanted the same thing and came up with the following:

augroup NetrwSetup
  autocmd!
  autocmd FileType netrw call s:netrw_select_first_non_dot()

  function! s:netrw_select_first_non_dot()
    if &filetype == 'netrw'
      " Move cursor down until a non-dot item is selected
      call cursor(1, 1)
      normal j
      while getline('.') =~ '^\.'
        normal j
      endwhile
    endif
  endfunction
augroup END

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.