I would like to make a file list of all my coc-extensions and afterwards install them in another vim environment.
I am not able to save the output of the vim command :CocList extensions
to a text file.
In the default directory of the coc-extension a json list saves all the extensions. I wrote a little script which will save all extensions ready to install within vim.
First of all you have to install jq
to parse the json file. On Debian based systems e.g.
sudo apt install jq
Afterwards save this script as e.g. install-coc-extensions.bash
#!/usr/bin/env bash
#
# script that creates a file `install-coc-extensions.vim`
# Use this command to install it (coc.nvim plugin required):
# vim -c 'source install-coc-extensions.vim'
echo "let g:coc_global_extensions = " > install-coc-extensions.vim
jq '.dependencies | keys' ~/.config/coc/extensions/package.json |
sed "s/\"/'/g" | sed 's/^/ \\/g' >> install-coc-extensions.vim
or as a one-line command type this command in your bash/zsh:
cat << EOF > install-coc-extensions.vim
let g:coc_global_extensions =
$(jq '.dependencies | keys' ~/.config/coc/extensions/package.json |
sed 's/"/'"'"'/g;s/^/ \\/g')
EOF
Don't forget to make this script executable
chmod +x install-coc-extensions.bash
./install-coc-extensions.bash
This will create a vim file install-coc-extensions.vim
To install the extensions all you have to do is to run the following command (coc.nvim plugin has to be installed)
vim -c 'source install-coc-extensions.vim'
or use it as session file:
vim -S install-coc-extensions.vim
vim -S install-coc-extensions.vim
. The script could be written as { echo 'let …'; jq … | sed -e s/\"/\'/g -e 's/^/ \\/g'; } > install-coc-extensions.vim