Vim/en: Difference between revisions

FuzzyBot (talk | contribs)
Updating to match new version of source page
Tags: Mobile edit Mobile web edit
FuzzyBot (talk | contribs)
Updating to match new version of source page
 
Line 5: Line 5:


=== Basic Install ===
=== Basic Install ===
On unstable:
<syntaxhighlight lang="nix>
<syntaxhighlight lang="nix>
   programs.vim.enable = true;
   programs.vim.enable = true;
Line 14: Line 11:
or
or


<syntaxhighlight lang="nix>
<syntaxhighlight lang="nix">
   programs.vim = {
   programs.vim = {
     enable = true;
     enable = true;
     package = pkgs.vim_configurable;
     package = pkgs.vim-full;
   };
   };
</syntaxhighlight>
On 24.05 or older:
<syntaxhighlight lang="nix>
  environment.systemPackages = with pkgs; [ vim ];
</syntaxhighlight>
</syntaxhighlight>


or
or


<syntaxhighlight lang="nix>
<syntaxhighlight lang="nix">
   environment.systemPackages = with pkgs; [ vim_configurable ];
   environment.systemPackages = with pkgs; [ vim-full ];
</syntaxhighlight>
</syntaxhighlight>


Line 52: Line 43:
=== Vim Spell Files ===
=== Vim Spell Files ===


You can configure home-manager to install spelling files into your user directory by packaging individual spell files.  Here' an example for neovim and French:
You can configure home-manager to install spelling files into your user directory by packaging individual spell files.  Here' an example for [[neovim]] and French:


<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
Line 95: Line 86:
On unstable:
On unstable:


<syntaxHighlight lang="nix">
<syntaxhighlight lang="nix">
{ pkgs, ... }:
{ pkgs, ... }:
{
{
Line 101: Line 92:
     enable = true;
     enable = true;
     defaultEditor = true;
     defaultEditor = true;
     package = (pkgs.vim_configurable.override {  }).customize{
     package = (pkgs.vim-full.override {  }).customize{
       name = "vim";
       name = "vim";
       # Install plugins for example for syntax highlighting of nix files
       # Install plugins for example for syntax highlighting of nix files
Line 119: Line 110:
   };
   };
}
}
</syntaxHighlight>
</syntaxhighlight>
 
On 24.05 or older:
 
<syntaxHighlight lang="nix">
{ pkgs, ... }:
{
  environment.variables = { EDITOR = "vim";
  environment.systemPackages = with pkgs; [
    ((vim_configurable.override {  }).customize{
      name = "vim";
      # Install plugins for example for syntax highlighting of nix files
      vimrcConfig.packages.myplugins = with pkgs.vimPlugins; {
        start = [ vim-nix vim-lastplace ];
        opt = [];
      };
      vimrcConfig.customRC = ''
        " your custom vimrc
        set nocompatible
        set backspace=indent,eol,start
        " Turn on syntax highlighting by default
        syntax on
        " ...
      '';
    }
  )];
}
</syntaxHighlight>
 
<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
{ pkgs, ... }:
{ pkgs, ... }:
Line 196: Line 159:
Add the following code to your <code>~/.nixpkgs/config.nix</code>:
Add the following code to your <code>~/.nixpkgs/config.nix</code>:


<syntaxHighlight lang="nix">
<syntaxhighlight lang="nix">
{
{
   packageOverrides = pkgs: with pkgs; {
   packageOverrides = pkgs: with pkgs; {
     myVim = vim_configurable.customize {
     myVim = vim-full.customize {
       name = "vim-with-plugins";
       name = "vim-with-plugins";
       # add here code from the example section
       # add here code from the example section
Line 217: Line 180:
   };
   };
}
}
</syntaxHighlight>
</syntaxhighlight>


After that you can install your special grafted `myVim` or `myNeovim` packages.
After that you can install your special grafted `myVim` or `myNeovim` packages.
Line 227: Line 190:
NB: you ''must'' use <code>vimrcConfig.customRC</code> rather than installing a <code>~/.vimrc</code> by hand, since the customized Vim will silently ignore any vimrc in your home directory.
NB: you ''must'' use <code>vimrcConfig.customRC</code> rather than installing a <code>~/.vimrc</code> by hand, since the customized Vim will silently ignore any vimrc in your home directory.


<syntaxHighlight lang="nix">
<syntaxhighlight lang="nix">
vim_configurable.customize {
vim-full.customize {
   name = "vim-with-plugins";
   name = "vim-with-plugins";
   # add custom .vimrc lines like this:
   # add custom .vimrc lines like this:
Line 236: Line 199:
   '';
   '';
}
}
</syntaxHighlight>
</syntaxhighlight>


If you need to run code before plugins are added, you can use <code>vimrcConfig.beforePlugins</code> (be sure to include <code>set nocompatible</code> if you override [https://github.com/NixOS/nixpkgs/blob/c3df8057dad986bf7f3928de1b5233fadb52bb15/pkgs/misc/vim-plugins/vim-utils.nix#L264-L267 the default value]).
If you need to run code before plugins are added, you can use <code>vimrcConfig.beforePlugins</code> (be sure to include <code>set nocompatible</code> if you override [https://github.com/NixOS/nixpkgs/blob/c3df8057dad986bf7f3928de1b5233fadb52bb15/pkgs/misc/vim-plugins/vim-utils.nix#L264-L267 the default value]).
Line 242: Line 205:
=== Using vim's builtin packaging capability ===
=== Using vim's builtin packaging capability ===


<syntaxHighlight lang="nix">
<syntaxhighlight lang="nix">
vim_configurable.customize {
vim-full.customize {
   vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; {
   vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; {
     # loaded on launch
     # loaded on launch
Line 253: Line 216:
   }
   }
};
};
</syntaxHighlight>
</syntaxhighlight>


Note that dynamically loading with opt may be buggy and the workaround is to use [https://vi.stackexchange.com/a/20818/30821 start instead].
Note that dynamically loading with opt may be buggy and the workaround is to use [https://vi.stackexchange.com/a/20818/30821 start instead].
Line 274: Line 237:
=== Adding new plugins ===
=== Adding new plugins ===


As per the instructions found in https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/vim.section.md
Please see https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/vim.section.md.
 
* First run <code>./update.py</code>.
 
* Commit the changes with the commit message "vimPlugins: Update".
 
* Add your plugin to ./vim-plugin-names (please try to maintain the list alphabetically sorted). You can customize the branch by appending for example <code>@main</code> to an entry (search the file for examples)
 
* Run <code>./update.py</code> once again to generate the plugin's nix expression.
 
* Commit your changes one more time, this time with the message formated as such: "vimPlugins.[plugin-name]: init at [version]".
 
* If you need to add additional code/patches to the generated code, add those lines to <code>pkgs/misc/vim-plugins/vim2nix/additional-nix-code</code> and rerun <code>./update.py</code>. They will be included in the generated code.


==== Notes Regarding Plugins ====
==== Notes Regarding Plugins ====
Line 296: Line 247:
Sometimes you do not want to change upstream plugins, for this you can use  <code>vimUtils.buildVimPlugin</code> to create your own:
Sometimes you do not want to change upstream plugins, for this you can use  <code>vimUtils.buildVimPlugin</code> to create your own:


<syntaxHighlight lang="nix">
<syntaxhighlight lang="nix">
let
let
   vim-better-whitespace = pkgs.vimUtils.buildVimPlugin {
   vim-better-whitespace = pkgs.vimUtils.buildVimPlugin {
Line 309: Line 260:
in {
in {
   users.users.<yourNickname>.packages = [
   users.users.<yourNickname>.packages = [
     (pkgs.vim_configurable.customize {
     (pkgs.vim-full.customize {
       vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; {
       vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; {
         start = [ vim-better-whitespace ];
         start = [ vim-better-whitespace ];
Line 316: Line 267:
   ];
   ];
};
};
</syntaxHighlight>
</syntaxhighlight>


==== Using flake ====
==== Using flake ====
Line 373: Line 324:
=== Vim as a Python IDE ===
=== Vim as a Python IDE ===


The following snippet will make a full featured python IDE.
The following snippet will make a full featured [[python]] IDE.


==== Using language client ====
==== Using language client ====


<syntaxHighlight lang="nix">
<syntaxhighlight lang="nix">
vim_configurable.customize {
vim-full.customize {
   vimrcConfig = {
   vimrcConfig = {
     customRC = ''
     customRC = ''
Line 396: Line 347:
     }
     }
};
};
</syntaxHighlight>
</syntaxhighlight>


Then put the following expression in <code>environment.systemPackages</code> or in the home-manager package list,
Then put the following expression in <code>environment.systemPackages</code> or in the home-manager package list,
Line 423: Line 374:
A better alternative to youcompleteme for C/C++ is to use [https://github.com/cquery-project/cquery/ cquery] in combination with the [https://github.com/autozimu/LanguageClient-neovim LanguageClient-neovim]. It will also find in c header files when used in a nix-shell if you install cquery from nixpkgs as it uses a custom [https://github.com/NixOS/nixpkgs/commit/04f3b76dcec21f2fcba6b1b0afbb3ed224165050#diff-11cdfc0385b9e017089c1ac09c5b838e shell wrapper]
A better alternative to youcompleteme for C/C++ is to use [https://github.com/cquery-project/cquery/ cquery] in combination with the [https://github.com/autozimu/LanguageClient-neovim LanguageClient-neovim]. It will also find in c header files when used in a nix-shell if you install cquery from nixpkgs as it uses a custom [https://github.com/NixOS/nixpkgs/commit/04f3b76dcec21f2fcba6b1b0afbb3ed224165050#diff-11cdfc0385b9e017089c1ac09c5b838e shell wrapper]


== Python 3 support for vim ==
== gvim and gview ==


If you have defined your vim configuration in a `./my_vim.nix` file you can install vim with the python 3 support instead of python2 by overriding the python version like the following:
You can enable <code>guiSupport</code> to make <code>gvim</code> available, though this won't give you <code>gview</code>:


<syntaxHighlight  lang="nix">
<syntaxhighlight lang="nix">
(pkgs.callPackage ./my_vim.nix {                                                                                                                                                        
(pkgs.vim-full.customize {
      vim_configurable = vim_configurable.override { python = python3; };                                                                                                                    
  guiSupport = true;
})
})
</syntaxHighlight>
== gvim and gview ==
<code>gvim</code> and <code>gview</code> may be installed using the <code>[https://search.nixos.org/packages/?query=vimHugeX vimHugeX]</code> attribute name (package name <code>[https://search.nixos.org/packages/?query=vim_configurable vim_configurable]</code>).
<syntaxhighlight lang=bash>
$ nix-env -iA nixos.vimHugeX
</syntaxhighlight>
If you are using <code>vim_configurable.customize</code>, you can enable <code>wrapGui</code> to make <code>gvim</code> available, though this won't give you <code>gview</code>:
<syntaxhighlight lang=nix>
vim_configured = pkgs.vim_configurable.customize {
  name = "vim";
  wrapGui = true;
};
</syntaxhighlight>
</syntaxhighlight>


[[Category:Applications]]
[[Category:Applications]]
[[Category:CLI Applications]]
[[Category:Text Editor{{#translation:}}]]
[[Category:Text Editor{{#translation:}}]]