Neovim: Difference between revisions
imported>Onny mNo edit summary |
imported>Ncfavier m Fix code snippets |
||
Line 7: | Line 7: | ||
[https://nixos.wiki/wiki/Home_Manager Home Manager] has a module for Neovim, which can be enabled via | [https://nixos.wiki/wiki/Home_Manager Home Manager] has a module for Neovim, which can be enabled via | ||
<syntaxhighlight lang="nix"> | |||
programs.neovim = { | |||
enable = true; | |||
extraConfig = '' | |||
set number relativenumber | |||
''; | |||
}; | |||
</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.html#opt-programs.neovim.enable Home Manager Manual]. | ||
Line 20: | Line 22: | ||
If you do not use Home Manager, you can use the following code in your NixOS configuration: | 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. | 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> | |||
== Configuration == | == Configuration == | ||
Line 38: | Line 44: | ||
You can copy your old config or directly load your default Neovim config via: | You can copy your old config or directly load your default Neovim config via: | ||
<syntaxhighlight lang="nix"> | |||
programs.neovim.extraConfig = lib.fileContents ../path/to/your/init.vim; | |||
</syntaxhighlight> | |||
To use Neovim as your default editor, you can set the <code>EDITOR</code> [https://search.nixos.org/options?show=environment.variables&type=packages&query=environment.variables environmental variable] to "nvim" by adding the following to your NixOS configuration: | To use Neovim as your default editor, you can set the <code>EDITOR</code> [https://search.nixos.org/options?show=environment.variables&type=packages&query=environment.variables environmental variable] to "nvim" by adding the following to your NixOS configuration: | ||
<syntaxhighlight lang="nix"> | |||
environment.variables.EDITOR = "nvim"; | |||
</syntaxhighlight> | |||
The Home Manager module does also expose options to automatically add <code>vi</code> and <code>vim</code> aliases. | The Home Manager module does also expose options to automatically add <code>vi</code> and <code>vim</code> aliases. | ||
To use them, add the following to your Home Manager configuration: | To use them, add the following to your Home Manager configuration: | ||
<syntaxhighlight lang="nix"> | |||
programs.neovim = { | |||
viAlias = true; | |||
vimAlias = true; | |||
}; | |||
</syntaxhighlight> | |||
==== Installing Plugins ==== | ==== Installing Plugins ==== | ||
Line 57: | Line 69: | ||
You can add only the plugin, or the plugin with its corresponding config: | You can add only the plugin, or the plugin with its corresponding config: | ||
<syntaxhighlight lang="nix"> | |||
programs.neovim.plugins = [ | |||
pkgs.vimPlugins.nvim-tree-lua | |||
{ | |||
plugin = pkgs.vimPlugins.vim-startify; | |||
config = "let g:startify_change_to_vcs_root = 0"; | |||
} | |||
]; | |||
</syntaxhighlight> | |||
If you only add the plugin, you can add the configuration as described above. | If you only add the plugin, you can add the configuration as described above. | ||
Line 77: | Line 91: | ||
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>vim-nix</code> to support syntax highlighting for Nix files | ||
<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 = [ vim-nix ]; | |||
}; | }; | ||
}; | }; | ||
}; | |||
</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: | 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: | ||
<syntaxhighlight lang="nix"> | |||
environment.variables.EDITOR = "nvim"; | |||
</syntaxhighlight> | |||
Further, the NixOS module does also expose options to automatically add <code>vi</code> and <code>vim</code> aliases. | 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: | 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 == | ||
Line 125: | Line 145: | ||
Due to how the `runtimepath` for Lua modules is [https://github.com/nanotee/nvim-lua-guide#a-note-about-packages processed], your configuration may require <code>packadd! plugin-name</code> to require a module. A home-manager example: | Due to how the `runtimepath` for Lua modules is [https://github.com/nanotee/nvim-lua-guide#a-note-about-packages processed], your configuration may require <code>packadd! plugin-name</code> to require a module. A home-manager example: | ||
<syntaxhighlight lang="nix"> | |||
programs.neovim = { | |||
plugins = [ | |||
{ | |||
plugin = nvim-colorizer-lua | |||
config = '' | |||
packadd! nvim-colorizer.lua | |||
lua require 'colorizer'.setup() | |||
''; | |||
} | |||
]; | |||
} | |||
</syntaxhighlight> | |||
== See Also == | == See Also == |