Skip to content

Instantly share code, notes, and snippets.

@gjazali
Created March 2, 2024 19:47
Show Gist options
  • Save gjazali/eed3c324dc720e573a314710de4f4f2a to your computer and use it in GitHub Desktop.
Save gjazali/eed3c324dc720e573a314710de4f4f2a to your computer and use it in GitHub Desktop.

Install Neovim Plugins after Importing Dotfiles

Oftentimes, after importing your .dotfiles (including your Neovim configuration files) to a new machine, installing your Neovim plugins using :PlugInstall (if you're on vim-plug) isn't ideal. This is mainly because of all the error messages that you would have to skip through before you're even able to run the install command.

This can be circumvented by doing the following:

nvim -u .dotfiles/.config/nvim/plugins.vim --headless +"PlugInstall" +"qall"

Here, .dotfiles/.config/nvim/plugins.vim is the file where you define your plugins within the set of function calls provided by your plugin manager (plug#begin() and plug#end() on vim-plug). Running nvim with the --headless flag will prevent the error messages that you would otherwise get.

If you have plugins with some post-installation hooks, you can continue by specifying them with the + flag, like below:

nvim -u .dotfiles/.config/nvim/plugins.vim --headless +"TSUpdate" +"call nvim_ghost#installer#install()" +"qall"
(cd ~/.vim/plugged/telescope-fzf-native.nvim && make)
(sudo pacman -S go) # For Arch; Go is needed to compile Hexokinase
(cd ~/.vim/plugged/vim-hexokinase && make hexokinase)

For example, in here, since I use nvim-treesitter, I'd want to install all its available parsers. I also use telescope-fzf-native.nvim and vim-hexokinase, both of which needs some extra post-installation steps to make them work. In the above code, I put some commands in a subshell so that the cd commands doesn't get carried over to the next commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment