Vim: Difference between revisions
Haruki7049 (talk | contribs) No edit summary |
Haruki7049 (talk | contribs) Marked this version for translation |
||
| Line 1: | Line 1: | ||
<languages/> | <languages/> | ||
<translate> | <translate> | ||
<!--T:1--> | |||
[https://www.vim.org/ Vim] (vi improved) is a highly configurable modal text editor program for the terminal. | [https://www.vim.org/ Vim] (vi improved) is a highly configurable modal text editor program for the terminal. | ||
== Installation == | == Installation == <!--T:2--> | ||
=== Basic Install === | === Basic Install === <!--T:3--> | ||
<!--T:4--> | |||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
environment.systemPackages = with pkgs; [ vim ]; | environment.systemPackages = with pkgs; [ vim ]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<!--T:5--> | |||
or | or | ||
<!--T:6--> | |||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
environment.systemPackages = with pkgs; [ vim_configurable ]; | environment.systemPackages = with pkgs; [ vim_configurable ]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Using Home Manager === | === Using Home Manager === <!--T:7--> | ||
<!--T:8--> | |||
Vim can easily be set up using [[Special:MyLanguage/Home Manager|Home Manager]]. Here's a minimal example: | Vim can easily be set up using [[Special:MyLanguage/Home Manager|Home Manager]]. Here's a minimal example: | ||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
| Line 31: | Line 36: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<!--T:9--> | |||
See [https://github.com/rycee/home-manager/blob/master/modules/programs/vim.nix] for the full set of options. | See [https://github.com/rycee/home-manager/blob/master/modules/programs/vim.nix] for the full set of options. | ||
=== Vim Spell Files === | === Vim Spell Files === <!--T:10--> | ||
<!--T:11--> | |||
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: | ||
<!--T:12--> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
let | let | ||
| Line 44: | Line 52: | ||
}; | }; | ||
<!--T:13--> | |||
nvim-spell-fr-utf8-suggestions = builtins.fetchurl { | nvim-spell-fr-utf8-suggestions = builtins.fetchurl { | ||
url = "http://ftp.vim.org/vim/runtime/spell/fr.utf-8.sug"; | url = "http://ftp.vim.org/vim/runtime/spell/fr.utf-8.sug"; | ||
| Line 49: | Line 58: | ||
}; | }; | ||
<!--T:14--> | |||
nvim-spell-fr-latin1-dictionary = builtins.fetchurl { | nvim-spell-fr-latin1-dictionary = builtins.fetchurl { | ||
url = "http://ftp.vim.org/vim/runtime/spell/fr.latin1.spl"; | url = "http://ftp.vim.org/vim/runtime/spell/fr.latin1.spl"; | ||
| Line 54: | Line 64: | ||
}; | }; | ||
<!--T:15--> | |||
nvim-spell-fr-latin1-suggestions = builtins.fetchurl { | nvim-spell-fr-latin1-suggestions = builtins.fetchurl { | ||
url = "http://ftp.vim.org/vim/runtime/spell/fr.latin1.sug"; | url = "http://ftp.vim.org/vim/runtime/spell/fr.latin1.sug"; | ||
| Line 67: | Line 78: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
==== NeoVim with Coc for Python ==== | ==== NeoVim with Coc for Python ==== <!--T:16--> | ||
<!--T:17--> | |||
For NeoVim use this home manager config: | For NeoVim use this home manager config: | ||
https://github.com/NixOS/nixpkgs/issues/98166#issuecomment-725319238 | https://github.com/NixOS/nixpkgs/issues/98166#issuecomment-725319238 | ||
== System wide vim/nvim configuration == | == System wide vim/nvim configuration == <!--T:18--> | ||
<!--T:19--> | |||
If you want a system wide "baseline" configuration for vim/nvim here are two examples:. | If you want a system wide "baseline" configuration for vim/nvim here are two examples:. | ||
| Line 81: | Line 94: | ||
environment.variables = { EDITOR = "vim"; }; | environment.variables = { EDITOR = "vim"; }; | ||
environment.systemPackages = with pkgs; [ | <!--T:20--> | ||
environment.systemPackages = with pkgs; [ | |||
((vim_configurable.override { }).customize{ | ((vim_configurable.override { }).customize{ | ||
name = "vim"; | name = "vim"; | ||
| Line 102: | Line 116: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<!--T:21--> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
{ pkgs, ... }: | { pkgs, ... }: | ||
| Line 107: | Line 122: | ||
environment.variables = { EDITOR = "vim"; }; | environment.variables = { EDITOR = "vim"; }; | ||
environment.systemPackages = with pkgs; [ | <!--T:22--> | ||
environment.systemPackages = with pkgs; [ | |||
(neovim.override { | (neovim.override { | ||
vimAlias = true; | vimAlias = true; | ||
| Line 127: | Line 143: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<!--T:23--> | |||
import these in your <code>configuration.nix</code> and | import these in your <code>configuration.nix</code> and | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 138: | Line 155: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
== Custom setup without using Home Manager == | == Custom setup without using Home Manager == <!--T:24--> | ||
<!--T:25--> | |||
{{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] }} | ||
<!--T:26--> | |||
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>. | ||
<!--T:27--> | |||
A lot of documentation about package management and configuration of vim in nix is stored at [https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/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/applications/editors/vim/plugins/vim-utils.nix] in nixpkgs. | ||
=== Customizations === | === Customizations === <!--T:28--> | ||
<!--T:29--> | |||
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 search nixpkgs#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 search nixpkgs#vimPlugins</code>. | ||
<!--T:30--> | |||
Add the following code to your <code>~/.nixpkgs/config.nix</code>: | Add the following code to your <code>~/.nixpkgs/config.nix</code>: | ||
<!--T:31--> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
{ | { | ||
| Line 175: | Line 198: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<!--T:32--> | |||
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 === <!--T:33--> | ||
==== Apply custom vimrc configuration ==== | ==== Apply custom vimrc configuration ==== <!--T:34--> | ||
<!--T:35--> | |||
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. | ||
<!--T:36--> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
vim_configurable.customize { | vim_configurable.customize { | ||
| Line 194: | Line 220: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<!--T:37--> | |||
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]). | ||
=== Using vim's builtin packaging capability === | === Using vim's builtin packaging capability === <!--T:38--> | ||
<!--T:39--> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
vim_configurable.customize { | vim_configurable.customize { | ||
| Line 211: | Line 239: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<!--T:40--> | |||
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]. | ||
=== Using Pathogen as manager === | === Using Pathogen as manager === <!--T:41--> | ||
<!--T:42--> | |||
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 221: | Line 251: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Using Vim-Plug as manager === | === Using Vim-Plug as manager === <!--T:43--> | ||
<!--T:44--> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
vimrcConfig.plug.plugins = with pkgs.vimPlugins; [vim-addon-nix youcompleteme]; | vimrcConfig.plug.plugins = with pkgs.vimPlugins; [vim-addon-nix youcompleteme]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Adding new plugins === | === Adding new plugins === <!--T:45--> | ||
<!--T:46--> | |||
As per the instructions found in https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/vim.section.md | As per the instructions found in https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/vim.section.md | ||
* First run <code>./update.py</code>. | * First run <code>./update.py</code>. | ||
| Line 237: | Line 269: | ||
* 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. | * 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 ==== <!--T:47--> | ||
<!--T:48--> | |||
For additional info, you may wish to look at [https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/vim.section.md documentation on the nixpkgs repository]. | For additional info, you may wish to look at [https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/vim.section.md documentation on the nixpkgs repository]. | ||
=== Add a new custom plugin to the users packages === | === Add a new custom plugin to the users packages === <!--T:49--> | ||
<!--T:50--> | |||
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: | ||
<!--T:51--> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
let | let | ||
| Line 257: | Line 292: | ||
}; | }; | ||
<!--T:52--> | |||
in { | in { | ||
users.users.<yourNickname>.packages = [ | users.users.<yourNickname>.packages = [ | ||
| Line 268: | Line 304: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
==== Using flake ==== | ==== Using flake ==== <!--T:53--> | ||
<!--T:54--> | |||
<code>configuration.nix</code>: | <code>configuration.nix</code>: | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 294: | Line 331: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<!--T:55--> | |||
<code>flake.nix</code>: | <code>flake.nix</code>: | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 305: | Line 343: | ||
}; | }; | ||
outputs = inputs@{ nixpkgs, ... }: { | <!--T:56--> | ||
outputs = inputs@{ nixpkgs, ... }: { | |||
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { | nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { | ||
system = "x86_64-linux"; | system = "x86_64-linux"; | ||
| Line 319: | Line 358: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<!--T:57--> | |||
Then we can update the package with <code>nix flake lock --update-input winresizer-vim</code>, or update all inputs in flake.nix with <code>nix flake update</code>. | Then we can update the package with <code>nix flake lock --update-input winresizer-vim</code>, or update all inputs in flake.nix with <code>nix flake update</code>. | ||
=== Vim as a Python IDE === | === Vim as a Python IDE === <!--T:58--> | ||
<!--T:59--> | |||
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 ==== <!--T:60--> | ||
<!--T:61--> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
vim_configurable.customize { | vim_configurable.customize { | ||
| Line 348: | Line 390: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<!--T:62--> | |||
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, | ||
to install python-language-server: | to install python-language-server: | ||
| Line 359: | Line 402: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
=== Real life examples === | === Real life examples === <!--T:63--> | ||
<!--T:64--> | |||
* [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] | ||
* [https://github.com/wagnerf42/nixos-config/blob/master/config/my_vim.nix wagnerf42's config (good for rust language)] | * [https://github.com/wagnerf42/nixos-config/blob/master/config/my_vim.nix wagnerf42's config (good for rust language)] | ||
=== YouCompleteMe === | === YouCompleteMe === <!--T:65--> | ||
<!--T:66--> | |||
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>. | ||
<!--T:67--> | |||
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 == | == Python 3 support for vim == <!--T:68--> | ||
<!--T:69--> | |||
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: | 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: | ||
| Line 381: | Line 428: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
== gvim and gview == | == gvim and gview == <!--T:70--> | ||
<!--T:71--> | |||
<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>). | <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> | <syntaxhighlight lang=bash> | ||
| Line 388: | Line 436: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<!--T:72--> | |||
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>: | 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> | <syntaxhighlight lang=nix> | ||