1

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.

1 Answer 1

1

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
2
  • or 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
    – D. Ben Knoble
    Commented Nov 30, 2022 at 13:57
  • That's a nice idea ! Didn't know that. Thanks for the hint.
    – abu_bua
    Commented Nov 30, 2022 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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