Search code examples
vimnetrw

How to do easier filesystem navigation in Vim - Netrw


I like Netrw . Its pretty good/poweful and it comes in stock Vim .

However I have a small productivity issue entering into Netrw with the normal Cursor Navigation Mode . The most important activity I do is / instaed of using the navigable cursor as I know what I would be looking for .

  1. Is it possible to enter into Netrw in / i.e search Mode ? I.e Any Netrw buffer defaults to / and hitting Enter should bring it to the simple Cursor Navigation Mode ?
  2. How to make another '/' should just enter the directory currently under the first search highlight ?
  3. Fuzzy Search would be even more brilliant but any idea on how can be achieved ?

Any ideas how to do this ? Vim is pretty composible and hence this should be possible . Any ideas how to achieve this ? Ofcourse I use CtrlP etc and Netrw has become redundant however its sometimes required to navigate the FS . If you think about its a bit like ido-mode in Emacs , however I was thinking how can I add a layer that uses Netrw but deals with it differently what are the challenges adding that layer and what are some pointers out there to understand these special buffers ?


Solution

  • autocmd FileType netrw call feedkeys("/\<c-u>", 'n') makes it persistent to the netrw buffer .

    Use a mapping like this :

    map <silent> <C-E> :call ToggleVExplorer()<CR>
    cmap <C-E> <C-\><C-N>:call ToggleVExplorer()<CR>
    

    If you have a toggle function that opens and closes like ToggleVExplorer :

    "Toggle Vexplore with Ctrl-E
    function! ToggleVExplorer()
      if exists("t:expl_buf_num")
          let expl_win_num = bufwinnr(t:expl_buf_num)
          if expl_win_num != -1
              let cur_win_nr = winnr()
              exec expl_win_num . 'wincmd w'
              close
              exec cur_win_nr . 'wincmd w'
              unlet t:expl_buf_num
          else
              unlet t:expl_buf_num
          endif
      else
          exec '1wincmd w'
          Vexplore
          let t:expl_buf_num = bufnr("%")
      endif
    endfunction