TransWikia.com

Concatenate mapping with zt mapping

Vi and Vim Asked by Xxxo on January 21, 2021

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!

2 Answers

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

Correct answer by filbranden on January 21, 2021

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.

Answered by Maxim Kim on January 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP