Neovim: Difference between revisions

(changed the order of paragraphs (NixOS install/configuration before home-manager install/configuration. Added information about distributions.)
Line 1: Line 1:
[https://neovim.io Neovim] is a fork of [[Vim]] aiming to improve the codebase, allowing for easier implementation of APIs, improved user experience and plugin implementation.  
[https://neovim.io Neovim] is a fork of [[Vim]] aiming to improve the codebase, allowing for easier implementation of APIs, improved user experience and plugin implementation.
 
Due to the large number of plugins, it is possible to extend and configure neovim to fit the exact needs of the user. Many users start working with neovim with a preconfigured neovim distribution (such as LazyVim, AstroVim, NVChad) or use the preconfigured NixOS package for LunarVim. This way you can learn what is possible. Experienced users often advise to familiarize themselves with neovim and then create their own configuration from scratch.
 
For people who like the modal text editors in a terminal but don't want to spend so much time configuring it, the Helix editor might be the right choice.


== Installation ==
== Installation ==
=== System-wide ===
If you do not use Home Manager, you can use the following code in your NixOS configuration:
<syntaxhighlight lang="nix">
programs.neovim = {
  enable = true;
  defaultEditor = true;
};
</syntaxhighlight>
You can also manually add Neovim to your packages. This should only be used if the two version above do not work for you.
<syntaxhighlight lang="nix">
environment.systemPackages = [ pkgs.neovim ];
</syntaxhighlight>


=== With Home Manager ===
=== With Home Manager ===
Line 18: Line 39:
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].
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].


== Configuration ==
Neovim shares most of its configuration with Vim. See the [[Vim|Vim page]] for more details on the use of both.
=== System-wide ===
=== System-wide ===


If you do not use Home Manager, you can use the following code in your NixOS configuration:
The NixOS module does not have an <code>extraConfig</code> option as the Home Manager module does.
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>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">
programs.neovim = {
programs.neovim = {
   enable = true;
   enable = true;
   defaultEditor = true;
   configure = {
    customRC = ''
      set number
      set cc=80
      set list
      set listchars=tab:→\ ,space:·,nbsp:␣,trail:•,eol:¶,precedes:«,extends:»
      if &diff
        colorscheme blue
      endif
    '';
    packages.myVimPackage = with pkgs.vimPlugins; {
      start = [ ctrlp ];
    };
  };
};
};
</syntaxhighlight>
</syntaxhighlight>


You can also manually add Neovim to your packages. This should only be used if the two version above do not work for you.
To set Neovim as your default editor:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
environment.systemPackages = [ pkgs.neovim ];
programs.neovim = {
  defaultEditor = true;
};
</syntaxhighlight>
</syntaxhighlight>


== Configuration ==
Further, the NixOS module does also expose options to automatically add <code>vi</code> and <code>vim</code> aliases.
 
To use them, add the following to your NixOS configuration:
Neovim shares most of its configuration with Vim. See the [[Vim|Vim page]] for more details on the use of both.


<syntaxhighlight lang="nix">
programs.neovim = {
  viAlias = true;
  vimAlias = true;
};
</syntaxhighlight>
=== With Home Manager ===
=== With Home Manager ===


Line 97: Line 144:
</syntaxhighlight>
</syntaxhighlight>


=== System-wide ===
The NixOS module does not have an <code>extraConfig</code> option as the Home Manager module does.
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>ctrlp</code> to support fuzzy file search (see [https://github.com/ctrlpvim/ctrlp.vim homepage] on how to use it)
<syntaxhighlight lang="nix">
programs.neovim = {
  enable = true;
  configure = {
    customRC = ''
      set number
      set cc=80
      set list
      set listchars=tab:→\ ,space:·,nbsp:␣,trail:•,eol:¶,precedes:«,extends:»
      if &diff
        colorscheme blue
      endif
    '';
    packages.myVimPackage = with pkgs.vimPlugins; {
      start = [ ctrlp ];
    };
  };
};
</syntaxhighlight>
To set Neovim as your default editor:


<syntaxhighlight lang="nix">
programs.neovim = {
  defaultEditor = true;
};
</syntaxhighlight>
Further, the NixOS module does also expose options to automatically add <code>vi</code> and <code>vim</code> aliases.
To use them, add the following to your NixOS configuration:
<syntaxhighlight lang="nix">
programs.neovim = {
  viAlias = true;
  vimAlias = true;
};
</syntaxhighlight>


== Tips and tricks ==
== Tips and tricks ==