Vim: Difference between revisions
Haruki7049 (talk | contribs) Marked this version for translation |
Replace dead link. |
||
| (16 intermediate revisions by 7 users not shown) | |||
| Line 7: | Line 7: | ||
=== Basic Install === <!--T:3--> | === Basic Install === <!--T:3--> | ||
</translate> | |||
<syntaxhighlight lang="nix> | |||
programs.vim.enable = true; | |||
</syntaxhighlight> | |||
<translate> | |||
<!--T:74--> | |||
or | |||
< | </translate> | ||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix"> | ||
programs.vim = { | |||
enable = true; | |||
package = pkgs.vim-full; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
<!--T:5--> | <!--T:5--> | ||
or | or | ||
< | </translate> | ||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix"> | ||
environment.systemPackages = with pkgs; [ | environment.systemPackages = with pkgs; [ vim-full ]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
=== Using Home Manager === <!--T:7--> | === Using Home Manager === <!--T:7--> | ||
| Line 25: | Line 38: | ||
<!--T:8--> | <!--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: | ||
</translate> | |||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
programs.vim = { | programs.vim = { | ||
| Line 35: | Line 50: | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
<!--T:9--> | <!--T:9--> | ||
| Line 42: | Line 58: | ||
<!--T:11--> | <!--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: | ||
< | </translate> | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
let | let | ||
| Line 52: | Line 68: | ||
}; | }; | ||
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 58: | Line 73: | ||
}; | }; | ||
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 64: | Line 78: | ||
}; | }; | ||
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 71: | Line 84: | ||
in | in | ||
{ | { | ||
xdg.configFile."nvim/spell/fr.utf-8.spl".source = nvim-spell-fr-utf8-dictionary; | |||
xdg.configFile."nvim/spell/fr.utf-8.sug".source = nvim-spell-fr-utf8-suggestions; | |||
xdg.configFile."nvim/spell/fr.latin1.spl".source = nvim-spell-fr-latin1-dictionary; | |||
xdg.configFile."nvim/spell/fr.latin1.sug".source = nvim-spell-fr-latin1-suggestions; | |||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
==== NeoVim with Coc for Python ==== <!--T:16--> | ==== NeoVim with Coc for Python ==== <!--T:16--> | ||
| Line 88: | Line 102: | ||
<!--T:19--> | <!--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:. | ||
< | <!--T:76--> | ||
On unstable: | |||
</translate> | |||
<syntaxhighlight lang="nix"> | |||
{ pkgs, ... }: | { pkgs, ... }: | ||
{ | { | ||
programs.vim = { | |||
enable = true; | |||
defaultEditor = true; | |||
package = (pkgs.vim-full.override { }).customize{ | |||
( | |||
name = "vim"; | name = "vim"; | ||
# Install plugins for example for syntax highlighting of nix files | <translate> | ||
<!--T:77--> | |||
# Install plugins for example for syntax highlighting of nix files | |||
</translate> | |||
vimrcConfig.packages.myplugins = with pkgs.vimPlugins; { | vimrcConfig.packages.myplugins = with pkgs.vimPlugins; { | ||
start = [ vim-nix vim-lastplace ]; | start = [ vim-nix vim-lastplace ]; | ||
| Line 104: | Line 124: | ||
}; | }; | ||
vimrcConfig.customRC = '' | vimrcConfig.customRC = '' | ||
" your custom vimrc | <translate> | ||
<!--T:78--> | |||
" your custom vimrc | |||
</translate> | |||
set nocompatible | set nocompatible | ||
set backspace=indent,eol,start | set backspace=indent,eol,start | ||
" Turn on syntax highlighting by default | <translate> | ||
<!--T:79--> | |||
" Turn on syntax highlighting by default | |||
</translate> | |||
syntax on | syntax on | ||
" ... | " ... | ||
''; | ''; | ||
} | }; | ||
}; | |||
} | } | ||
</ | </syntaxhighlight> | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
{ pkgs, ... }: | { pkgs, ... }: | ||
{ | { | ||
programs.neovim = { | |||
enable = true; | |||
defaultEditor = true; | |||
vimAlias = true; | |||
configure = { | |||
customRC = '' | |||
<translate> | |||
" your custom vimrc | <!--T:84--> | ||
" your custom vimrc | |||
</translate> | |||
set nocompatible | set nocompatible | ||
set backspace=indent,eol,start | set backspace=indent,eol,start | ||
" ... | " ... | ||
''; | ''; | ||
packages.myPlugins = with pkgs.vimPlugins; { | |||
start = [ vim-lastplace vim-nix ]; | |||
opt = []; | |||
}; | }; | ||
} | }; | ||
}; | |||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
<!--T:23--> | <!--T:23--> | ||
import these in your <code>configuration.nix</code> and | import these in your <code>configuration.nix</code> and | ||
</translate> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
{ | { | ||
| Line 154: | Line 180: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
== Custom setup without using Home Manager == <!--T:24--> | == Custom setup without using Home Manager == <!--T:24--> | ||
| Line 164: | Line 191: | ||
<!--T:27--> | <!--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/ | A lot of documentation about package management and configuration of vim in nix is stored at [https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/vim.section.md] in nixpkgs. | ||
=== Customizations === <!--T:28--> | === Customizations === <!--T:28--> | ||
| Line 174: | Line 201: | ||
Add the following code to your <code>~/.nixpkgs/config.nix</code>: | Add the following code to your <code>~/.nixpkgs/config.nix</code>: | ||
< | </translate> | ||
< | <syntaxhighlight lang="nix"> | ||
{ | { | ||
packageOverrides = pkgs: with pkgs; { | packageOverrides = pkgs: with pkgs; { | ||
myVim = | myVim = vim-full.customize { | ||
name = "vim-with-plugins"; | name = "vim-with-plugins"; | ||
# add here code from the example section | <translate> | ||
<!--T:85--> | |||
# add here code from the example section | |||
</translate> | |||
}; | }; | ||
myNeovim = neovim.override { | myNeovim = neovim.override { | ||
configure = { | configure = { | ||
customRC = '' | customRC = '' | ||
# here your custom configuration goes! | <translate> | ||
<!--T:86--> | |||
# here your custom configuration goes! | |||
</translate> | |||
''; | ''; | ||
packages.myVimPackage = with pkgs.vimPlugins; { | packages.myVimPackage = with pkgs.vimPlugins; { | ||
# see examples below how to use custom packages | <translate> | ||
<!--T:87--> | |||
# see examples below how to use custom packages | |||
</translate> | |||
start = [ ]; | start = [ ]; | ||
opt = [ ]; | opt = [ ]; | ||
| Line 196: | Line 232: | ||
}; | }; | ||
} | } | ||
</ | </syntaxhighlight> | ||
<translate> | |||
<!--T:32--> | <!--T:32--> | ||
| Line 208: | Line 245: | ||
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. | ||
< | </translate> | ||
< | <syntaxhighlight lang="nix"> | ||
vim-full.customize { | |||
name = "vim-with-plugins"; | name = "vim-with-plugins"; | ||
# add custom .vimrc lines like this: | <translate> | ||
<!--T:88--> | |||
# add custom .vimrc lines like this: | |||
</translate> | |||
vimrcConfig.customRC = '' | vimrcConfig.customRC = '' | ||
set hidden | set hidden | ||
| Line 218: | Line 258: | ||
''; | ''; | ||
} | } | ||
</ | </syntaxhighlight> | ||
<translate> | |||
<!--T:37--> | <!--T:37--> | ||
| Line 225: | Line 266: | ||
=== Using vim's builtin packaging capability === <!--T:38--> | === Using vim's builtin packaging capability === <!--T:38--> | ||
< | </translate> | ||
< | <syntaxhighlight lang="nix"> | ||
vim-full.customize { | |||
vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; { | vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; { | ||
# loaded on launch | <translate> | ||
<!--T:89--> | |||
# loaded on launch | |||
</translate> | |||
start = [ YouCompleteMe fugitive ]; | start = [ YouCompleteMe fugitive ]; | ||
# manually loadable by calling `:packadd $plugin-name` | <translate> | ||
<!--T:90--> | |||
# manually loadable by calling `:packadd $plugin-name` | |||
</translate> | |||
opt = [ phpCompletion elm-vim ]; | opt = [ phpCompletion elm-vim ]; | ||
# To automatically load a plugin when opening a filetype, add vimrc lines like: | <translate> | ||
<!--T:91--> | |||
# To automatically load a plugin when opening a filetype, add vimrc lines like: | |||
</translate> | |||
# autocmd FileType php :packadd phpCompletion | # autocmd FileType php :packadd phpCompletion | ||
} | } | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
<translate> | |||
<!--T:40--> | <!--T:40--> | ||
| Line 246: | Line 297: | ||
<!--T:42--> | <!--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. | ||
</translate> | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
vimrcConfig.pathogen.knownPlugins = vimPlugins; # optional | vimrcConfig.pathogen.knownPlugins = vimPlugins; # optional | ||
vimrcConfig.pathogen.pluginNames = [ "vim-addon-nix" "youcompleteme" ]; | vimrcConfig.pathogen.pluginNames = [ "vim-addon-nix" "youcompleteme" ]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
=== Using Vim-Plug as manager === <!--T:43--> | === Using Vim-Plug as manager === <!--T:43--> | ||
< | </translate> | ||
<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> | ||
<translate> | |||
=== Adding new plugins === <!--T:45--> | === Adding new plugins === <!--T:45--> | ||
<!--T:46--> | <!--T:46--> | ||
Please see https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/vim.section.md. | |||
==== Notes Regarding Plugins ==== <!--T:47--> | ==== Notes Regarding Plugins ==== <!--T:47--> | ||
| Line 279: | Line 328: | ||
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: | ||
< | </translate> | ||
< | <syntaxhighlight lang="nix"> | ||
let | let | ||
vim-better-whitespace = pkgs.vimUtils.buildVimPlugin { | vim-better-whitespace = pkgs.vimUtils.buildVimPlugin { | ||
| Line 291: | Line 340: | ||
}; | }; | ||
}; | }; | ||
in { | in { | ||
users.users.<yourNickname>.packages = [ | users.users.<yourNickname>.packages = [ | ||
(pkgs. | (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 302: | Line 349: | ||
]; | ]; | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
<translate> | |||
==== Using flake ==== <!--T:53--> | ==== Using flake ==== <!--T:53--> | ||
< | </translate> | ||
<code>configuration.nix</code>: | <code>configuration.nix</code>: | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 331: | Line 379: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<code>flake.nix</code>: | <code>flake.nix</code>: | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 343: | Line 390: | ||
}; | }; | ||
outputs = inputs@{ nixpkgs, ... }: { | |||
outputs = inputs@{ nixpkgs, ... }: { | |||
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { | nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { | ||
system = "x86_64-linux"; | system = "x86_64-linux"; | ||
| Line 357: | Line 403: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
<!--T:57--> | <!--T:57--> | ||
| Line 364: | Line 411: | ||
<!--T:59--> | <!--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 ==== <!--T:60--> | ==== Using language client ==== <!--T:60--> | ||
< | </translate> | ||
< | <syntaxhighlight lang="nix"> | ||
vim-full.customize { | |||
vimrcConfig = { | vimrcConfig = { | ||
customRC = '' | customRC = '' | ||
| Line 388: | Line 435: | ||
} | } | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
<translate> | |||
<!--T:62--> | <!--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: | ||
</translate> | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
(python3.withPackages(ps: [ | (python3.withPackages(ps: [ | ||
ps.python-language-server | ps.python-language-server | ||
# the following plugins are optional, they provide type checking, import sorting and code formatting | <translate> | ||
<!--T:92--> | |||
# the following plugins are optional, they provide type checking, import sorting and code formatting | |||
</translate> | |||
ps.pyls-mypy ps.pyls-isort ps.pyls-black | ps.pyls-mypy ps.pyls-isort ps.pyls-black | ||
])) | ])) | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
=== Real life examples === <!--T:63--> | === Real life examples === <!--T:63--> | ||
| Line 406: | Line 459: | ||
<!--T:64--> | <!--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] | ||
<!--T:99--> | |||
* [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] | ||
<!--T:100--> | |||
* [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)] | ||
| Line 416: | Line 473: | ||
<!--T:67--> | <!--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] | ||
== gvim and gview == <!--T:70--> | == gvim and gview == <!--T:70--> | ||
<!--T:71--> | <!--T:71--> | ||
<code> | You can enable <code>guiSupport</code> to make <code>gvim</code> available, though this won't give you <code>gview</code>: | ||
</translate> | |||
<syntaxhighlight lang="nix"> | |||
<syntaxhighlight lang=nix> | (pkgs.vim-full.customize { | ||
guiSupport = true; | |||
}) | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate> | |||
</translate> | </translate> | ||
[[Category:Applications]] | [[Category:Applications]] | ||
[[Category:CLI Applications]] | |||
[[Category:Text Editor{{#translation:}}]] | [[Category:Text Editor{{#translation:}}]] | ||