3 Both Neovim and Vim can be configured to include your favorite plugins
4 and additional libraries.
6 Loading can be deferred; see examples.
8 At the moment we support two different methods for managing plugins:
10 - Vim packages (*recommended*)
13 Right now two Vim packages are available: `vim` which has most features that require extra
14 dependencies disabled and `vim-full` which has them configurable and enabled by default.
17 `vim_configurable` is a deprecated alias for `vim-full` and refers to the fact that its
18 build-time features are configurable. It has nothing to do with user configuration,
19 and both the `vim` and `vim-full` packages can be customized as explained in the next section.
22 ## Custom configuration {#custom-configuration}
24 Adding custom .vimrc lines can be done using the following code:
28 # `name` optionally specifies the name of the executable and package
29 name = "vim-with-plugins";
31 vimrcConfig.customRC = ''
37 This configuration is used when Vim is invoked with the command specified as name, in this case `vim-with-plugins`.
38 You can also omit `name` to customize Vim itself. See the
39 [definition of `vimUtils.makeCustomizable`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/vim-utils.nix#L408)
40 for all supported options.
42 For Neovim the `configure` argument can be overridden to achieve the same:
48 # here your custom configuration goes!
54 If you want to use `neovim-qt` as a graphical editor, you can configure it by overriding Neovim in an overlay
55 or passing it an overridden Neovim:
59 neovim = neovim.override {
62 # your custom configuration
69 ## Managing plugins with Vim packages {#managing-plugins-with-vim-packages}
71 To store your plugins in Vim packages (the native Vim plugin manager, see `:help packages`) the following example can be used:
75 vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; {
77 start = [ youcompleteme fugitive ];
78 # manually loadable by calling `:packadd $plugin-name`
79 # however, if a Vim plugin has a dependency that is not explicitly listed in
80 # opt that dependency will always be added to start to avoid confusion.
81 opt = [ phpCompletion elm-vim ];
82 # To automatically load a plugin when opening a filetype, add vimrc lines like:
83 # autocmd FileType php :packadd phpCompletion
88 `myVimPackage` is an arbitrary name for the generated package. You can choose any name you like.
89 For Neovim the syntax is:
95 # here your custom configuration goes!
97 packages.myVimPackage = with pkgs.vimPlugins; {
98 # see examples below how to use custom packages
100 # If a Vim plugin has a dependency that is not explicitly listed in
101 # opt that dependency will always be added to start to avoid confusion.
108 The resulting package can be added to `packageOverrides` in `~/.nixpkgs/config.nix` to make it installable:
112 packageOverrides = pkgs: with pkgs; {
113 myVim = vim-full.customize {
114 # `name` specifies the name of the executable and package
115 name = "vim-with-plugins";
116 # add here code from the example section
118 myNeovim = neovim.override {
120 # add code from the example section here
127 After that you can install your special grafted `myVim` or `myNeovim` packages.
129 ### What if your favourite Vim plugin isn’t already packaged? {#what-if-your-favourite-vim-plugin-isnt-already-packaged}
131 If one of your favourite plugins isn't packaged, you can package it yourself:
134 { config, pkgs, ... }:
137 easygrep = pkgs.vimUtils.buildVimPlugin {
138 name = "vim-easygrep";
139 src = pkgs.fetchFromGitHub {
141 repo = "vim-easygrep";
142 rev = "d0c36a77cc63c22648e792796b1815b44164653a";
143 hash = "sha256-bL33/S+caNmEYGcMLNCanFZyEYUOUmSsedCVBn4tV3g=";
148 environment.systemPackages = [
150 pkgs.neovim.override {
152 packages.myPlugins = with pkgs.vimPlugins; {
154 vim-go # already packaged plugin
155 easygrep # custom package
167 If your package requires building specific parts, use instead `pkgs.vimUtils.buildVimPlugin`.
169 ### Specificities for some plugins {#vim-plugin-specificities}
170 #### Treesitter {#vim-plugin-treesitter}
172 By default `nvim-treesitter` encourages you to download, compile and install
173 the required Treesitter grammars at run time with `:TSInstall`. This works
174 poorly on NixOS. Instead, to install the `nvim-treesitter` plugins with a set
175 of precompiled grammars, you can use `nvim-treesitter.withPlugins` function:
178 (pkgs.neovim.override {
180 packages.myPlugins = with pkgs.vimPlugins; {
182 (nvim-treesitter.withPlugins (
183 plugins: with plugins; [
194 To enable all grammars packaged in nixpkgs, use `pkgs.vimPlugins.nvim-treesitter.withAllGrammars`.
196 ## Managing plugins with vim-plug {#managing-plugins-with-vim-plug}
198 To use [vim-plug](https://github.com/junegunn/vim-plug) to manage your Vim
199 plugins the following example can be used:
203 vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; {
205 plug.plugins = [ youcompleteme fugitive phpCompletion elm-vim ];
210 Note: this is not possible anymore for Neovim.
213 ## Adding new plugins to nixpkgs {#adding-new-plugins-to-nixpkgs}
215 Nix expressions for Vim plugins are stored in [pkgs/applications/editors/vim/plugins](https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/editors/vim/plugins). For the vast majority of plugins, Nix expressions are automatically generated by running [`nix-shell -p vimPluginsUpdater --run vim-plugins-updater`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/updater.nix). This creates a [generated.nix](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/generated.nix) file based on the plugins listed in [vim-plugin-names](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/vim-plugin-names).
217 When the vim updater detects an nvim-treesitter update, it also runs [`nvim-treesitter/update.py $(nix-build -A vimPlugins.nvim-treesitter)`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/update.py) to update the tree sitter grammars for `nvim-treesitter`.
219 Some plugins require overrides in order to function properly. Overrides are placed in [overrides.nix](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/overrides.nix). Overrides are most often required when a plugin requires some dependencies, or extra steps are required during the build process. For example `deoplete-fish` requires both `deoplete-nvim` and `vim-fish`, and so the following override was added:
223 deoplete-fish = super.deoplete-fish.overrideAttrs(old: {
224 dependencies = with super; [ deoplete-nvim vim-fish ];
229 Sometimes plugins require an override that must be changed when the plugin is updated. This can cause issues when Vim plugins are auto-updated but the associated override isn't updated. For these plugins, the override should be written so that it specifies all information required to install the plugin, and running `nix-shell -p vimPluginsUpdater --run vim-plugins-updater` doesn't change the derivation for the plugin. Manually updating the override is required to update these types of plugins. An example of such a plugin is `LanguageClient-neovim`.
231 To add a new plugin, run `nix-shell -p vimPluginsUpdater --run 'vim-plugins-updater add "[owner]/[name]"'`. **NOTE**: This script automatically commits to your git repository. Be sure to check out a fresh branch before running.
233 Finally, there are some plugins that are also packaged in nodePackages because they have Javascript-related build steps, such as running webpack. Those plugins are not listed in `vim-plugin-names` or managed by `vimPluginsUpdater` at all, and are included separately in `overrides.nix`. Currently, all these plugins are related to the `coc.nvim` ecosystem of the Language Server Protocol integration with Vim/Neovim.
235 ### Plugin optional configuration {#vim-plugin-required-snippet}
237 Some plugins require specific configuration to work. We choose not to
238 patch those plugins but expose the necessary configuration under
239 `PLUGIN.passthru.initLua` for neovim plugins. For instance, the `unicode-vim` plugin
240 needs the path towards a unicode database so we expose the following snippet `vim.g.Unicode_data_directory="${self.unicode-vim}/autoload/unicode"` under `vimPlugins.unicode-vim.passthru.initLua`.
243 ## Updating plugins in nixpkgs {#updating-plugins-in-nixpkgs}
245 Run the update script with a GitHub API token that has at least `public_repo` access. Running the script without the token is likely to result in rate-limiting (429 errors). For steps on creating an API token, please refer to [GitHub's token documentation](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token).
248 nix-shell -p vimPluginsUpdater --run 'vim-plugins-updater --github-token=mytoken' # or set GITHUB_API_TOKEN environment variable
251 Alternatively, set the number of processes to a lower count to avoid rate-limiting.
255 nix-shell -p vimPluginsUpdater --run 'vim-plugins-updater --proc 1'
258 ## How to maintain an out-of-tree overlay of vim plugins ? {#vim-out-of-tree-overlays}
260 You can use the updater script to generate basic packages out of a custom vim
264 nix-shell -p vimPluginsUpdater --run vim-plugins-updater -i vim-plugin-names -o generated.nix --no-commit
267 with the contents of `vim-plugin-names` being for example:
271 pwntester/octo.nvim,,
274 You can then reference the generated vim plugins via:
278 myVimPlugins = pkgs.vimPlugins.extend (
279 (pkgs.callPackage ./generated.nix {})