Home > Software design >  How to execute an asynchronous command in vim from bash and quit vim after the command has completed
How to execute an asynchronous command in vim from bash and quit vim after the command has completed

Time:06-18

I could come up with a bash script that installs an LSP server plugin:

if [ ! -d $HOME/.local/share/nvim/lsp_servers/jdtls/ ]; then    
  printf "\nInstalling the Java LSP server"    
  mkdir -p ~/.local/share/nvim/lsp-servers/    
  nvim -c "LspInstall jdtls"
fi

But then the script never returns and the vim editor stays open.

I tried adding the quit commands but then it quits before installing the LSP server, as the installation is asynchronous:

nvim -c "LspInstall jdtls | q | q"

CodePudding user response:

Run the installation in blocking mode using the --sync option, which is there for exactly this purpose, scripting:

nvim -c "LspInstall --sync jdtls | q"
#                   ^^^^^^

Perhaps you need the extra | q at the end and : before LspInstall. Unfortunately, I can't test it myself.

  • Related