Shougo / denite.nvim

:dragon: Dark powered asynchronous unite all interfaces for Neovim/Vim8
Other
2.06k stars 215 forks source link

Broken compatibility with custom mappings #646

Closed rkiyanchuk closed 5 years ago

rkiyanchuk commented 5 years ago

Problems summary

Previously I was able to define Denite mappings using the following syntax:

    call denite#custom#map('insert', '<C-n>', '<denite:move_to_next_line>', 'noremap')
    call denite#custom#map('insert', '<C-p>', '<denite:move_to_previous_line>', 'noremap')
    call denite#custom#map('insert', '<C-j>', '<denite:assign_next_text>', 'noremap')
    call denite#custom#map('insert', '<C-k>', '<denite:assign_previous_text>', 'noremap')

    call denite#custom#var('file/rec', 'command',
        \ ['rg', '--files', '-g', '!.tox', '-g', '!.git', '-g', '!.venv'])

    call denite#custom#var('grep', 'command', ['rg'])
    call denite#custom#var('grep', 'default_opts', ['--vimgrep', '--smart-case', '--no-heading'])
    call denite#custom#var('grep', 'recursive_opts', [])
    call denite#custom#var('grep', 'pattern_opt', ['--regexp'])
    call denite#custom#var('grep', 'separator', ['--'])
    call denite#custom#var('grep', 'final_opts', [])

This allowed me to get insert mode enabled to match keywords immediately after triggering Denite and then choose matching files with <C-n> / <C-p and then <CR>

Apparently the plugin has been changed recently in a backwards incompatible manner and such setup is now broken. I couldn't figure out from the updated documentation how to replicate the setup.

Can such configuration be achieved with the updated Denite? If yes, would it be possible for you to provide hints on what actions to use, or better yet (even though that might be to much to ask :)) add an example?

Thanks for the plugin!

Expected

Insert mode is enabled automatically after triggering Denite to immediately start matching files according to input. No switching of modes is required to match and select an entry.

Environment Information (Required!)

health#denite#check
========================================================================
## denite.nvim
  - OK: has("python3") was successful
  - OK: Python3.6.1+ was successful

Provide a minimal init.vim with less than 50 lines


let $VIMHOME=fnamemodify($MYVIMRC, ':h')
let $VIMSITE=$HOME . "/.local/share/nvim/site"
let $VIMPLUGINS=$VIMSITE . "/plugins"

call plug#begin($VIMPLUGINS)
Plug 'junegunn/vim-plug'  " Generate :help for vim-plug itself.
Plug 'Shougo/denite.nvim'  " Fuzzy search for files, buffers and other sources.
call plug#end()

let g:python3_host_skip_check = 0
let g:python_host_skip_check = 0

if has("mac")
    let g:python_host_prog  = '/usr/local/bin/python'
    let g:python3_host_prog = '/usr/local/bin/python3'
else
    let g:python_host_prog  = '/usr/bin/python'
    let g:python3_host_prog = '/usr/bin/python3'
endif

nnoremap <silent> <leader>ff :Denite file/rec<CR>
nnoremap <silent> <leader>fb :Denite buffer<CR>
nnoremap <silent> <leader>fg :Denite grep<CR>
nnoremap <silent> <leader>fr :Denite register<CR>
nnoremap <silent> <leader>fw :DeniteCursorWord file/rec buffer grep<CR>

call denite#custom#map('insert', '<C-n>', '<denite:move_to_next_line>', 'noremap')
call denite#custom#map('insert', '<C-p>', '<denite:move_to_previous_line>', 'noremap')
call denite#custom#map('insert', '<C-j>', '<denite:assign_next_text>', 'noremap')
call denite#custom#map('insert', '<C-k>', '<denite:assign_previous_text>', 'noremap')

call denite#custom#var('file/rec', 'command',
    \ ['rg', '--files', '-g', '!.tox', '-g', '!.git', '-g', '!.venv'])

call denite#custom#var('grep', 'command', ['rg'])
call denite#custom#var('grep', 'default_opts', ['--vimgrep', '--smart-case', '--no-heading'])
call denite#custom#var('grep', 'recursive_opts', [])
call denite#custom#var('grep', 'pattern_opt', ['--regexp'])
call denite#custom#var('grep', 'separator', ['--'])
call denite#custom#var('grep', 'final_opts', [])

How to reproduce problems from neovim startup

  1. Trigger Denite (\ff in my setup).
  2. Start typing text to match.
nwkj86 commented 5 years ago

You can start with filter buffer enabled:

call denite#custom#option('_', {
            \ 'start_filter': v:true
            \ })

or just for file/rec

call denite#custom#option('file/rec', {
            \ 'start_filter': v:true
            \ })
Shougo commented 5 years ago

Insert mode is enabled automatically after triggering Denite to immediately start matching files according to input.

Please read the above comment.

denite#custom#map() is removed. Yes it is not backward compatibility. You need to define own mappings. Please read the documentation.

Shougo commented 5 years ago

This is the hint

Q: I want to move the cursor in denite filter window.

A: Really?  It is not recommended. >

    autocmd FileType denite-filter call s:denite_filter_my_settings()
    function! s:denite_filter_my_settings() abort
      inoremap <silent><buffer> <C-j>
      \ <Esc><C-w>p:call cursor(line('.')+1,0)<CR><C-w>pA
      inoremap <silent><buffer> <C-k>
      \ <Esc><C-w>p:call cursor(line('.')-1,0)<CR><C-w>pA
    endfunction

Note: This is very slow in Vim8 environment.
Shougo commented 5 years ago

No switching of modes is required to match and select an entry.

Hm. I don't recommend it.

rkiyanchuk commented 5 years ago

@nwkj86 @Shougo Thanks for the replies!

start_filter partly solves it and allows start typing right away after triggering Denite.

I'm not sure why switching modes is necessary now as Denite used to work just fine without it until recent changes. Switching modes requires more keystrokes, so in my opinion it makes navigation slower and less intuitive.

But it is your plugin after all, of course, thanks for your help anyway!

Shougo commented 5 years ago

It may be slower navigation. But I have decided to use Vim way. You should not move the cursor in insert mode.

Shougo commented 5 years ago

It means why switching mode is necessary in Vim

rkiyanchuk commented 5 years ago

@Shougo I played a bit more with Denite and I now understand what you meant. Yeah, I agree — kudos for choosing the Vim way.

In case it might be useful for someone else, I ended up with the following compromise settings:


try
    call denite#custom#var('file/rec', 'command', ['rg', '--files', '--glob', '!.git'])
    call denite#custom#var('grep', 'command', ['rg'])
    call denite#custom#var('grep', 'default_opts', ['-i', '--vimgrep', '--no-heading'])
    call denite#custom#var('grep', 'recursive_opts', [])
    call denite#custom#var('grep', 'pattern_opt', ['--regexp'])
    call denite#custom#var('grep', 'separator', ['--'])
    call denite#custom#var('grep', 'final_opts', [])
    call denite#custom#option('_', 'statusline', v:false)
catch
    echomsg "Denite plugin missing"
endtry

function! s:denite_my_settings() abort
    nnoremap <silent><buffer><expr> <CR> denite#do_map('do_action')
    nnoremap <silent><buffer><expr> p denite#do_map('do_action', 'preview')
    nnoremap <silent><buffer><expr> <C-c> denite#do_map('quit')
    nnoremap <silent><buffer><expr> i denite#do_map('open_filter_buffer')
    nnoremap <silent><buffer><expr> <Space> denite#do_map('toggle_select').'j'
endfunction

augroup DENITE
    autocmd!
    autocmd FileType denite call s:denite_my_settings()
augroup end

nnoremap <silent> <leader>ff :Denite file/rec -auto-resize -smartcase -start-filter<CR>
nnoremap <silent> <leader>fb :Denite buffer -auto-resize<CR>
nnoremap <silent> <leader>fg :Denite grep -auto-resize<CR>
nnoremap <silent> <leader>fr :Denite register -auto-resize<CR>
nnoremap <silent> <leader>fw :DeniteCursorWord file/rec buffer grep<CR>