Nishant
Nishant

Reputation: 21914

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 ?

Upvotes: 0

Views: 896

Answers (2)

Nishant
Nishant

Reputation: 21914

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

Upvotes: 0

romainl
romainl

Reputation: 196456

I would use a crude mapping to deal with your first requirement:

:nnoremap <key> :Explore<CR>/

and see if it really needs more sophistication.

Your second requirement sounds unlikely as that would mean / is used for two vastly different actions in the same mode which sounds very un-vim-like. <CR> is clearer and much more intuitive in my opinion.

Vim doesn't do fuzzy search so you'll need to write your own algorithm or lift it from someone else's plugin. set incsearch might be a good enough interim solution (it sure is, for me).

Upvotes: 1

Related Questions