Vim: Difference between revisions

imported>Krey
No edit summary
imported>Krey
No edit summary
Line 1: Line 1:
= Using Home Manager =
Vim can easily be set up using [[Home Manager]]. Here's a minimal example:
<syntaxhighlight lang="nix>
  programs.vim = {
    enable = true;
    plugins = [ "vim-airline" ];
    settings = { ignorecase = true; };
    extraConfig = ''
      set mouse=a
    '';
  };
</syntaxhighlight>
= Custom setup without using Home Manager =
{{note|To get a general overview about how to set up your vim in nix, refer to [https://www.mpscholten.de/nixos/2016/04/11/setting-up-vim-on-nixos.html mpscholten's blog] }}
{{note|To get a general overview about how to set up your vim in nix, refer to [https://www.mpscholten.de/nixos/2016/04/11/setting-up-vim-on-nixos.html mpscholten's blog] }}
Vim plugins can be installed with the help of nix. You can omit using vim plugin managers and do everything in your <code>.nixpkgs/config</code>.
Vim plugins can be installed with the help of nix. You can omit using vim plugin managers and do everything in your <code>.nixpkgs/config</code>.


It is also possible to configure vim using [[Home Manager]].
A lot of documentation about package management and configuration of vim in nix is stored at [https://github.com/NixOS/nixpkgs/blob/master/pkgs/misc/vim-plugins/vim-utils.nix vim-utils.nix in nixpkgs
 
A lot of documentation about package management and configuration of vim in nix is stored at [https://github.com/NixOS/nixpkgs/blob/master/pkgs/misc/vim-plugins/vim-utils.nix vim-utils.nix in nixpkgs].


= Customizations =
== Customizations ==


Both vim and neovim can be further configured to include your favorite plugins and additional libraries. To list all available vim plugins, run <code>nix-env -qaP -A nixos.vimPlugins</code>.
Both vim and neovim can be further configured to include your favorite plugins and additional libraries. To list all available vim plugins, run <code>nix-env -qaP -A nixos.vimPlugins</code>.
Line 36: Line 50:
After that you can install your special grafted `myVim` or `myNeovim` packages.
After that you can install your special grafted `myVim` or `myNeovim` packages.


= Examples =
== Examples ==


== Apply custom vimrc configuration ==
=== Apply custom vimrc configuration ===


<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
Line 51: Line 65:
</syntaxHighlight>
</syntaxHighlight>


== Using vim's builtin packaging capability ==
=== Using vim's builtin packaging capability ===


<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
Line 66: Line 80:
</syntaxHighlight>
</syntaxHighlight>


== Using VAM as manager ==
=== Using VAM as manager ===
You can add this to you nix configuration to get vim with custom <code>.vimrc</code> and listed plugins.  
You can add this to you nix configuration to get vim with custom <code>.vimrc</code> and listed plugins.  
<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
Line 86: Line 100:
Full documentation at [https://github.com/MarcWeber/vim-addon-manager VAM homepage].
Full documentation at [https://github.com/MarcWeber/vim-addon-manager VAM homepage].


== Using Pathogen as manager ==
=== Using Pathogen as manager ===
There is a pathogen implementation as well, but its startup is slower and [VAM] has more features.  
There is a pathogen implementation as well, but its startup is slower and [VAM] has more features.  
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 93: Line 107:
</syntaxhighlight>
</syntaxhighlight>


= Adding new plugins =
== Adding new plugins ==


* Check https://github.com/NixOS/nixpkgs/tree/master/pkgs/misc/vim-plugins
* Check https://github.com/NixOS/nixpkgs/tree/master/pkgs/misc/vim-plugins
Line 101: Line 115:




= Add a new custom plugin to the users packages  =
== Add a new custom plugin to the users packages  ==
Sometimes you do not want to change upstream plugins, for this you can use  <code>vimrcConfig.vam.knownPlugins</code> and <code>vimrcConfig.vam.pluginDirectories</code> like this:
Sometimes you do not want to change upstream plugins, for this you can use  <code>vimrcConfig.vam.knownPlugins</code> and <code>vimrcConfig.vam.pluginDirectories</code> like this:


Line 127: Line 141:
</syntaxHighlight>
</syntaxHighlight>


= Real life examples =
== Real life examples ==


* [https://github.com/jagajaga/my_configs/blob/master/.nixpkgs/common.nix Jagajaga’s config]
* [https://github.com/jagajaga/my_configs/blob/master/.nixpkgs/common.nix Jagajaga’s config]
* [https://github.com/andrewrk/dotfiles/blob/master/.nixpkgs/config.nix andrewrk's config]
* [https://github.com/andrewrk/dotfiles/blob/master/.nixpkgs/config.nix andrewrk's config]


= YouCompleteMe =
== YouCompleteMe ==
Currently the youcompleteme plugin uses [https://github.com/NixOS/nixpkgs/blob/8e7b1f2ac2e261d5a644fef860a0d050ea227c06/pkgs/misc/vim-plugins/default.nix#L695 unwrapped clang on linux]. This causes it to not find <code>stdlib.h</code>. There is a [https://github.com/andrewrk/genesis/blob/5f49cd9a8c2b61b9859a22102bc3f732add9461a/.ycm_extra_conf.py workaround] you can put in your <code>.ycm_extra_conf.py</code> file, which works by executing the C/C++ compiler and getting it to output the list of search paths - which includes the search path to find <code>stdlib.h</code>.
Currently the youcompleteme plugin uses [https://github.com/NixOS/nixpkgs/blob/8e7b1f2ac2e261d5a644fef860a0d050ea227c06/pkgs/misc/vim-plugins/default.nix#L695 unwrapped clang on linux]. This causes it to not find <code>stdlib.h</code>. There is a [https://github.com/andrewrk/genesis/blob/5f49cd9a8c2b61b9859a22102bc3f732add9461a/.ycm_extra_conf.py workaround] you can put in your <code>.ycm_extra_conf.py</code> file, which works by executing the C/C++ compiler and getting it to output the list of search paths - which includes the search path to find <code>stdlib.h</code>.