2

I'm using CoC and coc-python, and there is the gd mapping, which goes to the definition of a symbol. The mapping is defined as:

nmap <silent> gd <Plug>(doc-definition)

Now, I want to first do a vsplit of the current buffer, then use the gd, and then use the zt mapping.

I'm using the:

nmap <silent> <leader>gd :vsplit<cr><Plug>(coc-definition)<cr>zt

but the zt is never executed.

I have tried using:

nmap <silent> <leader>gd :vsplit<cr><Plug>(coc-definition)zt

(i.w. removing the <cr> after the (coc-definition)) but it still does not work.

Also, there is already the definition:

nmap <silent> gd <Plug>(coc-definition)

and I just want to add the variation with the <leader>.

Where is my error here and how will it work?

Thnx!

1

It seems the problem is that CoC is using an asynchronous action that doesn't take affect right at the point where the mapping is executed.

Looking at the CoC sources, I see there's a CocAction() counterpart to CocActionAsync(), so maybe you can use that to run the gd action synchronously.

Try the following:

nnoremap <silent> <leader>gd :vsplit<CR>:call CocAction('jumpDefinition')<CR>zt
1
  • 1
    Yes! It worked! Thank you! – Xxxo Dec 18 '20 at 17:24
0

What about

nmap <silent> <leader>gd :vsplit<cr><Plug>(coc-definition)zt

?

You start in normal mode, with :vsplit<cr> you start and end command-line mode. Then just just continue with <Plug>(coc-definition) and zt as normal mode mappings, no need for additional <cr>.

<Plug>Something or <Plug>(Something) is a special mapping for plugin authors to provide convenient way of remapping without introducing default maps that might clash with what users have.

5
  • 1
    Indeed, and the parentheses are to avoid having <Plug>Somethingzt, which would not work (vim would see the zt as part of Something). It's the same idea in :help using-<Plug>, except there they use <Plug>Something; – D. Ben Knoble Dec 16 '20 at 18:02
  • Still doesn’t work. I have tried what you are mentioning, I have also tried to use normal zt (with and without ! and <cr>), but still they don’t work. – Xxxo Dec 17 '20 at 6:34
  • 1
    It should work and it probably "works". The issue might be the coc-definition is async, thus zt is possibly run before definition was found. – Maxim Kim Dec 17 '20 at 6:45
  • I forgot to mention that there is already a mapping of nmap <silent> gd <Plug>(coc-definition) – Xxxo Dec 17 '20 at 9:48
  • 1
    Also, the solution that you proposed is not working. Might be that the coc-definition is async (as you say). If this is the case, then what would it take to make it work? – Xxxo Dec 17 '20 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.