lambdalisue / vim-fern

🌿 General purpose asynchronous tree viewer written in Pure Vim script
MIT License
1.29k stars 49 forks source link

Vim search (next / previous, i.e. n / Shift-N) not working in fern.vim drawer #307

Closed victoriastuart closed 3 years ago

victoriastuart commented 3 years ago

Hello: I just (yesterday) started using fern.vim, as NERDtree was too slow opening large directories.

[netrw opened those large directories efficiently; however, while I appreciate the native simplicity of netrw, it lacks polish and features, e.g. decent bookmarking; other issues, e.g. navigation.]

In NERDtree, with a open directory I was able to [edit: using /-search in Vim] search a term, using the standard Vim mappings n | Shift-N to navigate through those matches.

How can I regain that search functionality in fern.vim?

My ~/.vimrc entries:

let g:fern#disable_default_mappings   =  1
let g:fern#disable_drawer_auto_quit   = 1
let g:fern#disable_viewer_hide_cursor = 1

noremap <silent> <C-n> :Fern . -drawer -width=75 -toggle<CR><C-w>=
noremap <silent> <Leader>f :Fern . -drawer -reveal=% -width=75<CR><C-w>=
noremap <silent> <Leader>. :Fern %:h -drawer -width=75<CR><C-w>=

function! FernInit() abort
  nmap <buffer><expr>
        \ <Plug>(fern-my-open-expand-collapse)
        \ fern#smart#leaf(
        \   "\<Plug>(fern-action-open:select)<ESC><BAR>:FernDo close<CR>",
        \   "\<Plug>(fern-action-expand)",
        \   "\<Plug>(fern-action-collapse)",
        \ )
  nmap <buffer> <CR> <Plug>(fern-my-open-expand-collapse)
  nmap <buffer> <2-LeftMouse> <Plug>(fern-my-open-expand-collapse)
  nmap <buffer> m <Plug>(fern-action-mark:toggle)j
  nmap <buffer> N <Plug>(fern-action-new-file)
  nmap <buffer> K <Plug>(fern-action-new-dir)
  nmap <buffer> B <Plug>(fern-action-save-as-bookmark)
  nmap <buffer> T <Plug>(fern-action-trash)
  nmap <buffer> V <Plug>(fern-action-move)
  nmap <buffer> R <Plug>(fern-action-rename)
  nmap <buffer> s <Plug>(fern-action-open:split)
  nmap <buffer> v <Plug>(fern-action-open:vsplit)
  nmap <buffer> r <Plug>(fern-action-reload)
  nmap <buffer> <nowait> d <Plug>(fern-action-hidden:toggle)
  nmap <buffer> <nowait> < <Plug>(fern-action-leave)
  nmap <buffer> <nowait> > <Plug>(fern-action-enter)
endfunction

augroup FernEvents
  autocmd!
  autocmd FileType fern call FernInit()
augroup END

" NerdTREE-like presentation:
let g:fern#mark_symbol                       = '●'
let g:fern#renderer#default#collapsed_symbol = '▷ '
let g:fern#renderer#default#expanded_symbol  = '▼ '
let g:fern#renderer#default#leading          = ' '
let g:fern#renderer#default#leaf_symbol      = ' '
let g:fern#renderer#default#root_symbol      = '~ '

" Bookmarks:
let g:fern#mapping#bookmark#disable_default_mappings = 0
let g:fern#scheme#bookmark#store#file = "~/.vim/fern-bookmark.json"
lambdalisue commented 3 years ago

I'm sorry but I've no idea about

In NERDtree, with a open directory I was able to search a term, and use n | Shift-N to navigate through those matches.

Could you explain the feature with some screencast or screenshots?

Or do you just talking about Vim's search feature by hitting / or ??

victoriastuart commented 3 years ago

The latter: open the fern.vim drawer, then search (Vim: /) for a string. In a document, n/N will find the next/previous match. I'm not seeing that in the fern drawer.

lambdalisue commented 3 years ago

Kapture 2021-03-04 at 12 02 20

It seems search works as expect in my environment. Note that N is mapped to "New file" in default thus N does not work unless you disable the mapping.

Please make a minimal vimrc and minimal steps to reproduce. Starts from the following vimrc

if exists('+compatible') && &compatible
  set nocompatible
endif

if has('nvim')
  set runtimepath^=~/.vim
  set runtimepath+=~/.vim/after
  set packpath^=~/.vim
endif

" Specify fern.vim directory here
set runtimepath+=~/fern.vim

packloadall

filetype plugin indent on
syntax on

echomsg "Custom vimrc has loaded"
victoriastuart commented 3 years ago

Hi again - thank you for your response, appreciated. I commented out the nmap <buffer> N <Plug>(fern-action-new-file) line and looked around my .vimrc but didn't see anything of note.

With that change, in the fern.vim drawer I can do a / search as in a regular buffer (and the NERDtree buffer) and when I press n to find the next match, it goes to that line and stays there, even if there are more matches in following lines.

If there are gaps (non-matched lines) between search results, I can navigate (j) below the current match, then n again takes me to (only) the next match and stays there (even if more matches, below) - unless I repeat the preceding steps at each stall.

The reverse search, N, works normally.

Again, this is only in the fern.vim buffer / drawer.

I also tried your minimal .vimrc with the fern.vim settings but it wouldn't work properly -- missing other things apparently to make this work. Frankly, I'm not interested in pursuing that approach, as if needed I'll return to NERDtree and use netrw for opening directories with large (100s / 1000s) files.

Screencast (me >> Youtube): https://youtu.be/LeBZaMl_MNU

lambdalisue commented 3 years ago

Well, "I" need minimal vimrc and steps to reproduce your situation. Otherwise I cannot fix or help. That's why I'm asking you to start from that minimal vimrc.

Anyway, it's fine if you go back to NERDTree or netrw or whatever. It's up to you. Please close this issue then.

Shougo commented 3 years ago

You can use any other file manager plugins. They are free to use and no warranty.

lambdalisue commented 3 years ago

Maybe the following helps?

let g:fern#disable_viewer_smart_cursor = 1
victoriastuart commented 3 years ago

Adding

let g:fern#disable_viewer_smart_cursor = 1

to the minimal .vimrc" (comments below) PARTIALLY solved the /-search issue:

HOWEVER, adding

let g:fern#disable_viewer_smart_cursor = 1

to my full ~/.vimrc restored a properly working Vim /-search (n: forward | N: reverse).


Here is the issue / frustration I had with the "minimal" .vimrc (note the number of paths to identically-named, yet different, fern.vim files).

if exists('+compatible') && &compatible
  set nocompatible
endif

if has('nvim')
  set runtimepath^=~/.vim
  set runtimepath+=~/.vim/after
  set packpath^=~/.vim
endif

" Specify fern.vim directory here
" set runtimepath+=~/fern.vim

" In sequential order
"   (re: `find` command, `fern.vim`, `fern` installed via `vim-plug):
"   Restart Vim to reload.

" YES:
set runtimepath+=/home/victoria/.vim/plugged/fern.vim
"   ... BUT no Vim /-search `n' only finds / stalls at first match,
"   and `N` calls 'New file: '.

" NOPE ('E492: Not an editor command: Fern .'):
" set runtimepath+=/home/victoria/.vim/plugged/fern.vim/autoload/fern.vim
" set runtimepath+=/home/victoria/.vim/plugged/fern.vim/ftplugin/fern.vim
" set runtimepath+=/home/victoria/.vim/plugged/fern.vim/plugin/fern.vim
" set runtimepath+=/home/victoria/.vim/plugged/fern.vim/autoload/fern/internal/command/fern.vim
" set runtimepath+=/home/victoria/.vim/plugged/fern.vim/autoload/fern.vim
" set runtimepath+=/home/victoria/.vim/plugged/fern.vim/autoload/vital/fern.vim
" set runtimepath+=/home/victoria/.vim/plugged/fern.vim/autoload/vital/_fern.vim

packloadall

filetype plugin indent on
syntax on

echomsg "Custom vimrc has loaded"

" TEST:
" :Fern .

" `:buffers` to list buffers

" [victoria@victoria ~]$ pwd
"   /home/victoria
" [victoria@victoria ~]$ find . -iname  '*fern.vim'
"   ./.vim/plugged/fern.vim
"   ./.vim/plugged/fern.vim/ftplugin/fern.vim
"   ./.vim/plugged/fern.vim/plugin/fern.vim
"   ./.vim/plugged/fern.vim/autoload/fern/internal/command/fern.vim
"   ./.vim/plugged/fern.vim/autoload/fern.vim
"   ./.vim/plugged/fern.vim/autoload/vital/fern.vim
"   ./.vim/plugged/fern.vim/autoload/vital/_fern.vim
" [victoria@victoria ~]$

[victoria@victoria .vim]$ rg . -i -e smart_cursor

./plugged/fern.vim/doc/fern.txt
333:*g:fern#smart_cursor*
421:    See |g:fern#smart_cursor| for detail.
423:*g:fern#disable_viewer_smart_cursor*
425:    See |g:fern#smart_cursor| for detail.

./plugged/fern.vim/autoload/fern.vim
27:      \ 'smart_cursor': 'stick',
35:      \ 'disable_viewer_smart_cursor': 0,

./plugged/fern.vim/autoload/fern/helper/async.vim
20:  let prefix = !g:fern#disable_viewer_smart_cursor && g:fern#smart_cursor ==# 'stick' ? ' ' : ''

./plugged/fern.vim/autoload/fern/renderer/default.vim
41:  let prefix = !g:fern#disable_viewer_smart_cursor && g:fern#smart_cursor ==# 'stick' ? ' ' : ''

./plugged/fern.vim/autoload/fern/internal/viewer/smart_cursor.vim
1:function! fern#internal#viewer#smart_cursor#init() abort
2:  if g:fern#disable_viewer_smart_cursor
5:  if g:fern#smart_cursor ==# 'stick'
7:  elseif g:fern#smart_cursor ==# 'hide'
11:          \ '"%s" is not valid g:fern#smart_cursor. Use "stick" instead.',
12:          \ g:fern#smart_cursor,
19:  augroup fern_internal_viewer_smart_cursor_init
35:  augroup fern_internal_viewer_smart_cursor_init

./plugged/fern.vim/autoload/fern/internal/viewer.vim
60:  call fern#internal#viewer#smart_cursor#init()

[victoria@victoria .vim]$ rg . -i -e disable_viewer_smart_cursor

./plugged/fern.vim/doc/fern.txt
423:*g:fern#disable_viewer_smart_cursor*

./plugged/fern.vim/autoload/fern.vim
35:      \ 'disable_viewer_smart_cursor': 0,

./plugged/fern.vim/autoload/fern/internal/viewer/smart_cursor.vim
2:  if g:fern#disable_viewer_smart_cursor

./plugged/fern.vim/autoload/fern/helper/async.vim
20:  let prefix = !g:fern#disable_viewer_smart_cursor && g:fern#smart_cursor ==# 'stick' ? ' ' : ''

./plugged/fern.vim/autoload/fern/renderer/default.vim
41:  let prefix = !g:fern#disable_viewer_smart_cursor && g:fern#smart_cursor ==# 'stick' ? ' ' : ''

[victoria@victoria .vim]$

/home/victoria/.vim/plugged/fern.vim/doc/fern.txt

g:fern#smart_cursor*
    A type |String| of the smart cursor. Available values are

    "stick"     Stick the cursor to the first column to visualize the
            cursor node. In this mode, single whitespace is
            prefixed as a padding for better looks.

    "hide"      Hide the cursor and forcedly enable |cursorline| to
            visualize the cursor node. In this mode, |cursorline|
            is automatically enabled when the focus is on the
            buffer and automatically disabled when the cursor is
            out of the buffer.
            Note that Neovim prior to 0.5.0 cannot hide the cursor
            thus faint vertical bar is used instead.

    Default: "stick"
lambdalisue commented 3 years ago

N (reverse search) brought up the New file: dialog (rather than searching).

N is mapped to new-file in default though.

Anyway, it seems that setting solved the issue. Good.

victoriastuart commented 3 years ago

Thank you for your help, earlier. I did not intend to appear ungrateful. The program looks quite useful. :-) Sincerely, ...