Jump to content

Neovim: Difference between revisions

m
imported>Ncfavier
m (Fix code snippets)
(12 intermediate revisions by 7 users not shown)
Line 5: Line 5:
=== With Home Manager ===
=== With Home Manager ===


[https://nixos.wiki/wiki/Home_Manager Home Manager] has a module for Neovim, which can be enabled via
[[Home Manager]] has a module for Neovim, which can be enabled via


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 16: Line 16:
</syntaxhighlight>
</syntaxhighlight>


More information about the module can be found here: [https://nix-community.github.io/home-manager/options.html#opt-programs.neovim.enable Home Manager Manual].
More information about the module can be found here: [https://nix-community.github.io/home-manager/options.xhtml#opt-programs.neovim.enable Home Manager Manual].


=== System-wide ===
=== System-wide ===
Line 82: Line 82:


An index of official packages can be found in on [https://search.nixos.org/packages?from=0&size=50&sort=relevance&type=packages&query=vimPlugins search.nixos.org].
An index of official packages can be found in on [https://search.nixos.org/packages?from=0&size=50&sort=relevance&type=packages&query=vimPlugins search.nixos.org].
In addition to the official packages, there are several user maintained repositories, such as [https://github.com/m15a/nixpkgs-vim-extra-plugins vim-extra-plugins] or [https://github.com/NixNeovim/NixNeovimPlugins NixNeovimPlugins].
In addition to the official packages, there are several user maintained repositories, such as [https://github.com/m15a/flake-awesome-neovim-plugins awesome-neovim-plugins] or [https://github.com/NixNeovim/NixNeovimPlugins NixNeovimPlugins]. Plugins which are
not available in any of these repositories may be integrated using the <code>vimUtils.buildVimPlugin</code> function from Nixpkgs:
 
<syntaxhighlight lang="nix">
pkgs.vimUtils.buildVimPlugin {
  pname = "whatever";
  version = "whatever";
  src = builtins.fetchGit {
    url = "https://github.com/example/whatever.git";
    ref = "whatever";
  };
  buildScript = ":";
}
</syntaxhighlight>


=== System-wide ===
=== System-wide ===
Line 89: Line 102:
Instead, you can use the <code>programs.neovim.configure</code> option as described [https://search.nixos.org/options?show=programs.neovim.configure&type=packages&query=neovim here].
Instead, you can use the <code>programs.neovim.configure</code> option as described [https://search.nixos.org/options?show=programs.neovim.configure&type=packages&query=neovim here].


The following example configures RC commands and enables the plugin <code>vim-nix</code> to support syntax highlighting for Nix files
The following example configures RC commands and enables the plugin <code>ctrlp</code> to support fuzzy file search (see [https://github.com/ctrlpvim/ctrlp.vim homepage] on how to use it)


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 105: Line 118:
     '';
     '';
     packages.myVimPackage = with pkgs.vimPlugins; {
     packages.myVimPackage = with pkgs.vimPlugins; {
       start = [ vim-nix ];
       start = [ ctrlp ];
     };
     };
   };
   };
Line 111: Line 124:
</syntaxhighlight>
</syntaxhighlight>


Similarly to the Home Manager module, to set Neovim as your default editor you have to set the <code>EDITOR</code> environment variable like this:
To set Neovim as your default editor:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
environment.variables.EDITOR = "nvim";
programs.neovim = {
  defaultEditor = true;
};
</syntaxhighlight>
</syntaxhighlight>


Line 149: Line 164:
   plugins = [
   plugins = [
     {
     {
       plugin = nvim-colorizer-lua
       plugin = pkgs.vimPlugins.nvim-colorizer-lua;
       config = ''
       config = ''
         packadd! nvim-colorizer.lua
         packadd! nvim-colorizer.lua
         lua require 'colorizer'.setup()
         lua << END
require 'colorizer'.setup {
  '*'; -- Highlight all files, but customize some others.
  '!vim'; -- Exclude vim from highlighting.
}
END
       '';
       '';
     }
     }
1

edit