0

I am trying to use Vim as my main IDE. For that, I installed vim-plug, and COC.

This allows me to call those two commands :

:CoCCommand tsserver.organizeImports
:CoCCommand prettier.formatCode

I nnorremap them both to some leader binding and everything works wells.

What is not working is trying to run them one after the other with one mapping. Everytime I try it, only the last one runs.

I tried chaining them with <CR>, |, <bar>, but none of them work.

What I am understanding from that is that the first command gets canceled by the second one, because they run without waiting for the first one to end.

Is there a way to make this work ? Or I am cursed with two bindings only ?

Thank you in advance for your time

romainl
  • 186,200
  • 21
  • 280
  • 313
  • Also, please keep in mind that I am just starting using Vim, so if you could be explicit in your explanations that would be awesome ! –  Sep 17 '22 at 12:11
  • `` requires `<` not to be in 'cpoptions'; to see the value execute `:set cpoptions?` Try `\|`, it requires `b` not to be in 'cpoptions'. See http://vimdoc.sourceforge.net/htmldoc/map.html#map_bar – phd Sep 17 '22 at 12:50
  • You forgot to show us your mappings and your attempted solutions. Besides, coc.nvim is a pretty heavy layer of abstraction that may require the kind of specific domain knowledge you can find in its dedicated support channels. Also, Vim or Neovim? And, because someone has to say it, if you want an IDE, use one. – romainl Sep 17 '22 at 16:05
  • @romainl `o` and `i`, not sure it's useful though. Also, the question is about waiting for a command to run, not about coc. And Vim. And I use vscode, I wanted to switch to Vim for productivity. But that should be none of your concern, I am asking for help, not for an opinion. –  Sep 17 '22 at 21:12
  • @phd I don't think that's the issue, in itself `` works as expected, but as explained the second command cancels the first command, whether I use bar or cr –  Sep 17 '22 at 21:15
  • You are too new to all this to decide what is relevant and what is not. You are asking us to help you with failing mappings without providing them so all we can do is shoot in the dark. If you really want help, answer our requests for clarification, included a link to where `:CoCCommand` is implemented. For all we know, that `:CoCCommand foo.bar` runs some external command asynchronously, in which case it makes no sense to even think about running them synchronously. Anyway, use their dedicated support channels. – romainl Sep 17 '22 at 22:02
  • @DoktorOSwaldo unfortunately not, running multiple commands works, the issue is that the first command (that takes like 1s) gets cancelled by the second one because the second one gets called way before the 1s has passed –  Sep 19 '22 at 12:35
  • well you see, romainl is right, you are asking for a car to be repaired, but don't have the car with you. This seems to be a call to an asynchronous function, so you need a callback for it to call the second function. Without the exact implementation, this is unsolvable – Doktor OSwaldo Sep 19 '22 at 13:29
  • @DoktorOSwaldo see, this is actually helpful. Now I have something to look for (and learn too). And you didn't even need to see my car ! Thank you for this piece of information ! –  Sep 19 '22 at 15:30
  • (If you care to make an actual answer, I'd be able to mark it as resolved, up to you) –  Sep 19 '22 at 15:31

0 Answers0