SidOfc / mkdx

A vim plugin that adds some nice extra's for working with markdown documents
https://www.vim.org/scripts/script.php?script_id=5620
MIT License
484 stars 13 forks source link

enter function appears weird when the completion menu showing up #161

Closed lee-shun closed 2 years ago

lee-shun commented 2 years ago

Thank you for your excellent plugin!

OS type:

Vim:

Vim version:

  1. i have the following in my vimrc to use deoplete.nvim
    inoremap <expr> <cr> ((pumvisible())?("\<C-y>"):("\<cr>"))
    inoremap <expr> <TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
    inoremap <expr> <S-TAB> pumvisible() ? "\<C-p>" : "\<TAB>"
  2. and for mkdx:
    " ===
    " === mkdx
    " ===
    let g:mkdx#settings = {
            \'highlight': { 'enable': 0 },
            \'map': { 'prefix': '=' }
            \}

Reproduce steps:

  1. when I try to input with complete menu powered by deoplete.nvim, enter will not change a new line: 屏幕截图_1 to 屏幕截图_2

  2. if there is no complete menu, (for example, a space after), it works well: 屏幕截图_3 to 屏幕截图_4

What happened????

lee-shun commented 2 years ago

got one possible solution:

It seems the popup menu take in the "cr" to confirm rather than actually insert a "\n" by deoplete.nvim

So I put the following code in "after/ftplugin/markdown.vim"

" === patch mkdx
function! s:cr_close_pop()
  return pumvisible() ? "\<C-y>" : ""
endfunction
inoremap <silent> <Plug>(mkdx-enter-modify) <C-R>=<SID>cr_close_pop()<CR><C-R>=mkdx#EnterHandler()<Cr>:setlocal autoindent<Cr>
imap <buffer><silent> <CR> <Plug>(mkdx-enter-modify)

Then it works well...

SidOfc commented 2 years ago

Hello @lee-shun!

Would you mind forking mkdx and submitting a PR with the change you made? I'll have a look at it today and if all is well I'll merge it. Cheers for your efforts 👍

EDIT:

Ah I see that this is actually a pretty minimal snippet now and indeed would need some additional work. I'm thinking I'll add a setting to "close popup on enter" which will cause mkdx to behave like the patched code you've shown.

By default it will be disabled as to maintain identical behaviour when users update. In your case you would enable this setting.

I'll try to work on this tonight, thank you for the feedback!

lee-shun commented 2 years ago

Thank you and this excellent plug! Cheers!

SidOfc commented 2 years ago

@lee-shun you should now be able to enable the behaviour by setting :let g:mkdx#settings.enter.close_pum = 1 (in vimrc this must be written like let g:mkdx#settings = {'enter': {'close_pum': 1}}).

Leaving this open for you to confirm whether it works 👍

lee-shun commented 2 years ago

Just tested this neeeeew feature, Perfect!

By the way, I think every vimer should have the following line in their .vimrc to make life easier! And they should make this plugin default.

Plug 'SidOfc/mkdx'

Lol :)

SidOfc commented 2 years ago

Haha thanks!

Also cheers for reporting and doing the actual work, implementation was easy thanks to your efforts and may prove useful to people using other completion plugins as well 👍

Enjoy :)