Vim/de: Difference between revisions
Created page with "oder" |
Updating to match new version of source page |
||
| (10 intermediate revisions by 2 users not shown) | |||
| Line 8: | Line 8: | ||
<span id="Basic_Install"></span> | <span id="Basic_Install"></span> | ||
=== Grundinstallation === | === Grundinstallation === | ||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
programs.vim.enable = true; | programs.vim.enable = true; | ||
| Line 17: | Line 14: | ||
oder | oder | ||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix"> | ||
programs.vim = { | programs.vim = { | ||
enable = true; | enable = true; | ||
package = pkgs. | package = pkgs.vim-full; | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
oder | oder | ||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix"> | ||
environment.systemPackages = with pkgs; [ | environment.systemPackages = with pkgs; [ vim-full ]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
< | <span id="Using_Home_Manager"></span> | ||
=== | === Verwenden von Home Manager === | ||
Vim kann sehr einfach mit [[Special:MyLanguage/Home Manager|Home Manager]] eingerichtet werden. Hier ist ein minimales Beispiel: | |||
Vim | |||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
| Line 59: | Line 47: | ||
</div> | </div> | ||
< | <span id="Vim_Spell_Files"></span> | ||
=== Vim Spell | === Vim Spell Dateien === | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
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: | ||
</div> | </div> | ||
| Line 97: | Line 84: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
< | <span id="NeoVim_with_Coc_for_Python"></span> | ||
==== NeoVim | ==== NeoVim mit Coc für Python ==== | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 106: | Line 92: | ||
</div> | </div> | ||
< | <span id="System_wide_vim/nvim_configuration"></span> | ||
== System | == System weite vim/nvim Konfiguration == | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 118: | Line 103: | ||
</div> | </div> | ||
< | <syntaxhighlight lang="nix"> | ||
{ pkgs, ... }: | { pkgs, ... }: | ||
{ | { | ||
| Line 124: | Line 109: | ||
enable = true; | enable = true; | ||
defaultEditor = true; | defaultEditor = true; | ||
package = (pkgs. | package = (pkgs.vim-full.override { }).customize{ | ||
name = "vim"; | name = "vim"; | ||
# Installiere Plugins wie zum Beispiel für Syntaxhervorhebung von Nix Dateien | |||
# | |||
vimrcConfig.packages.myplugins = with pkgs.vimPlugins; { | vimrcConfig.packages.myplugins = with pkgs.vimPlugins; { | ||
start = [ vim-nix vim-lastplace ]; | start = [ vim-nix vim-lastplace ]; | ||
| Line 134: | Line 117: | ||
}; | }; | ||
vimrcConfig.customRC = '' | vimrcConfig.customRC = '' | ||
" deine benutzerdefinierte vimrc | |||
set nocompatible | set nocompatible | ||
set backspace=indent,eol,start | set backspace=indent,eol,start | ||
" Syntaxhervorhebung standardmäßig aktivieren | |||
syntax on | syntax on | ||
" ... | " ... | ||
| Line 148: | Line 127: | ||
}; | }; | ||
} | } | ||
</ | </syntaxhighlight> | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
{ pkgs, ... }: | { pkgs, ... }: | ||
| Line 251: | Line 194: | ||
</div> | </div> | ||
< | <syntaxhighlight lang="nix"> | ||
{ | { | ||
packageOverrides = pkgs: with pkgs; { | packageOverrides = pkgs: with pkgs; { | ||
myVim = | myVim = vim-full.customize { | ||
name = "vim-with-plugins"; | name = "vim-with-plugins"; | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 278: | Line 221: | ||
}; | }; | ||
} | } | ||
</ | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 296: | Line 239: | ||
</div> | </div> | ||
< | <syntaxhighlight lang="nix"> | ||
vim-full.customize { | |||
name = "vim-with-plugins"; | name = "vim-with-plugins"; | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 307: | Line 250: | ||
''; | ''; | ||
} | } | ||
</ | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 317: | Line 260: | ||
</div> | </div> | ||
< | <syntaxhighlight lang="nix"> | ||
vim-full.customize { | |||
vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; { | vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; { | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 334: | Line 277: | ||
} | } | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 366: | Line 309: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Please see https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/vim.section.md. | |||
</div> | </div> | ||
| Line 391: | Line 328: | ||
</div> | </div> | ||
< | <syntaxhighlight lang="nix"> | ||
let | let | ||
vim-better-whitespace = pkgs.vimUtils.buildVimPlugin { | vim-better-whitespace = pkgs.vimUtils.buildVimPlugin { | ||
| Line 404: | Line 341: | ||
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 411: | Line 348: | ||
]; | ]; | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 475: | Line 412: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
The following snippet will make a full featured python IDE. | The following snippet will make a full featured [[python]] IDE. | ||
</div> | </div> | ||
| Line 482: | Line 419: | ||
</div> | </div> | ||
< | <syntaxhighlight lang="nix"> | ||
vim-full.customize { | |||
vimrcConfig = { | vimrcConfig = { | ||
customRC = '' | customRC = '' | ||
| Line 501: | Line 438: | ||
} | } | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 524: | Line 461: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* [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] | ||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* [https://github.com/andrewrk/dotfiles/blob/master/.nixpkgs/config.nix andrewrk's config] | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* [https://github.com/wagnerf42/nixos-config/blob/master/config/my_vim.nix wagnerf42's config (good for rust language)] | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
=== YouCompleteMe === | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
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>. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
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] | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 559: | Line 488: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
<code> | You can enable <code>guiSupport</code> to make <code>gvim</code> available, though this won't give you <code>gview</code>: | ||
</div> | </div> | ||
<syntaxhighlight lang= | <syntaxhighlight lang="nix"> | ||
(pkgs.vim-full.customize { | |||
guiSupport = true; | |||
}) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Applications]] | [[Category:Applications]] | ||
[[Category:CLI Applications]] | |||
[[Category:Text Editor{{#translation:}}]] | [[Category:Text Editor{{#translation:}}]] | ||
Latest revision as of 20:14, 7 October 2025
Vim (vi improved) is a highly configurable modal text editor program for the terminal.
Installation
Grundinstallation
programs.vim.enable = true;
oder
programs.vim = {
enable = true;
package = pkgs.vim-full;
};
oder
environment.systemPackages = with pkgs; [ vim-full ];
Verwenden von Home Manager
Vim kann sehr einfach mit Home Manager eingerichtet werden. Hier ist ein minimales Beispiel:
programs.vim = {
enable = true;
plugins = with pkgs.vimPlugins; [ vim-airline ];
settings = { ignorecase = true; };
extraConfig = ''
set mouse=a
'';
};
See [1] for the full set of options.
Vim Spell Dateien
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:
let
nvim-spell-fr-utf8-dictionary = builtins.fetchurl {
url = "http://ftp.vim.org/vim/runtime/spell/fr.utf-8.spl";
sha256 = "abfb9702b98d887c175ace58f1ab39733dc08d03b674d914f56344ef86e63b61";
};
nvim-spell-fr-utf8-suggestions = builtins.fetchurl {
url = "http://ftp.vim.org/vim/runtime/spell/fr.utf-8.sug";
sha256 = "0294bc32b42c90bbb286a89e23ca3773b7ef50eff1ab523b1513d6a25c6b3f58";
};
nvim-spell-fr-latin1-dictionary = builtins.fetchurl {
url = "http://ftp.vim.org/vim/runtime/spell/fr.latin1.spl";
sha256 = "086ccda0891594c93eab143aa83ffbbd25d013c1b82866bbb48bb1cb788cc2ff";
};
nvim-spell-fr-latin1-suggestions = builtins.fetchurl {
url = "http://ftp.vim.org/vim/runtime/spell/fr.latin1.sug";
sha256 = "5cb2c97901b9ca81bf765532099c0329e2223c139baa764058822debd2e0d22a";
};
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;
}
NeoVim mit Coc für Python
For NeoVim use this home manager config: https://github.com/NixOS/nixpkgs/issues/98166#issuecomment-725319238
System weite vim/nvim Konfiguration
If you want a system wide "baseline" configuration for vim/nvim here are two examples:.
On unstable:
{ pkgs, ... }:
{
programs.vim = {
enable = true;
defaultEditor = true;
package = (pkgs.vim-full.override { }).customize{
name = "vim";
# Installiere Plugins wie zum Beispiel für Syntaxhervorhebung von Nix Dateien
vimrcConfig.packages.myplugins = with pkgs.vimPlugins; {
start = [ vim-nix vim-lastplace ];
opt = [];
};
vimrcConfig.customRC = ''
" deine benutzerdefinierte vimrc
set nocompatible
set backspace=indent,eol,start
" Syntaxhervorhebung standardmäßig aktivieren
syntax on
" ...
'';
};
};
}
{ pkgs, ... }:
{
programs.neovim = {
enable = true;
defaultEditor = true;
vimAlias = true;
configure = {
customRC = ''
<div lang="en" dir="ltr" class="mw-content-ltr">
" your custom vimrc
</div>
set nocompatible
set backspace=indent,eol,start
" ...
'';
packages.myPlugins = with pkgs.vimPlugins; {
start = [ vim-lastplace vim-nix ];
opt = [];
};
};
};
}
import these in your configuration.nix and
{
imports =
[
./vim.nix
];
# ...
}
Custom setup without using Home Manager
Vim plugins can be installed with the help of nix. You can omit using vim plugin managers and do everything in your .nixpkgs/config.
A lot of documentation about package management and configuration of vim in nix is stored at [2] in nixpkgs.
Customizations
Both vim and neovim can be further configured to include your favorite plugins and additional libraries. To list all available vim plugins, run nix search nixpkgs#vimPlugins.
Add the following code to your ~/.nixpkgs/config.nix:
{
packageOverrides = pkgs: with pkgs; {
myVim = vim-full.customize {
name = "vim-with-plugins";
<div lang="en" dir="ltr" class="mw-content-ltr">
# add here code from the example section
</div>
};
myNeovim = neovim.override {
configure = {
customRC = ''
<div lang="en" dir="ltr" class="mw-content-ltr">
# here your custom configuration goes!
</div>
'';
packages.myVimPackage = with pkgs.vimPlugins; {
<div lang="en" dir="ltr" class="mw-content-ltr">
# see examples below how to use custom packages
</div>
start = [ ];
opt = [ ];
};
};
};
};
}
After that you can install your special grafted `myVim` or `myNeovim` packages.
Examples
Apply custom vimrc configuration
NB: you must use vimrcConfig.customRC rather than installing a ~/.vimrc by hand, since the customized Vim will silently ignore any vimrc in your home directory.
vim-full.customize {
name = "vim-with-plugins";
<div lang="en" dir="ltr" class="mw-content-ltr">
# add custom .vimrc lines like this:
</div>
vimrcConfig.customRC = ''
set hidden
set colorcolumn=80
'';
}
If you need to run code before plugins are added, you can use vimrcConfig.beforePlugins (be sure to include set nocompatible if you override the default value).
Using vim's builtin packaging capability
vim-full.customize {
vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; {
<div lang="en" dir="ltr" class="mw-content-ltr">
# loaded on launch
</div>
start = [ YouCompleteMe fugitive ];
<div lang="en" dir="ltr" class="mw-content-ltr">
# manually loadable by calling `:packadd $plugin-name`
</div>
opt = [ phpCompletion elm-vim ];
<div lang="en" dir="ltr" class="mw-content-ltr">
# To automatically load a plugin when opening a filetype, add vimrc lines like:
</div>
# autocmd FileType php :packadd phpCompletion
}
};
Note that dynamically loading with opt may be buggy and the workaround is to use start instead.
Using Pathogen as manager
There is a pathogen implementation as well, but its startup is slower and [VAM] has more features.
vimrcConfig.pathogen.knownPlugins = vimPlugins; # optional
vimrcConfig.pathogen.pluginNames = [ "vim-addon-nix" "youcompleteme" ];
Using Vim-Plug as manager
vimrcConfig.plug.plugins = with pkgs.vimPlugins; [vim-addon-nix youcompleteme];
Adding new plugins
Notes Regarding Plugins
For additional info, you may wish to look at documentation on the nixpkgs repository.
Add a new custom plugin to the users packages
Sometimes you do not want to change upstream plugins, for this you can use vimUtils.buildVimPlugin to create your own:
let
vim-better-whitespace = pkgs.vimUtils.buildVimPlugin {
name = "vim-better-whitespace";
src = pkgs.fetchFromGitHub {
owner = "ntpeters";
repo = "vim-better-whitespace";
rev = "984c8da518799a6bfb8214e1acdcfd10f5f1eed7";
sha256 = "10l01a8xaivz6n01x6hzfx7gd0igd0wcf9ril0sllqzbq7yx2bbk";
};
};
in {
users.users.<yourNickname>.packages = [
(pkgs.vim-full.customize {
vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; {
start = [ vim-better-whitespace ];
};
})
];
};
Using flake
configuration.nix:
{ inputs, ... }:
{
nixpkgs = {
overlays = [
(self: super:
let
winresizer-vim = super.vimUtils.buildVimPlugin {
name = "winresizer-vim";
src = inputs.winresizer-vim;
};
in
{
vimPlugins =
super.vimPlugins // {
inherit winresizer-vim;
};
}
)
];
};
flake.nix:
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05";
winresizer-vim = {
url = "github:simeji/winresizer";
flake = false;
};
};
outputs = inputs@{ nixpkgs, ... }: {
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
./configuration.nix
./hardware-configuration.nix
{ nix.registry.nixpkgs.flake = nixpkgs; }
];
};
};
}
Then we can update the package with nix flake lock --update-input winresizer-vim, or update all inputs in flake.nix with nix flake update.
Vim as a Python IDE
The following snippet will make a full featured python IDE.
Using language client
vim-full.customize {
vimrcConfig = {
customRC = ''
let g:LanguageClient_serverCommands = {
\ 'python': ['pyls']
\ }
nnoremap <F5> :call LanguageClient_contextMenu()<CR>
nnoremap <silent> gh :call LanguageClient_textDocument_hover()<CR>
nnoremap <silent> gd :call LanguageClient_textDocument_definition()<CR>
nnoremap <silent> gr :call LanguageClient_textDocument_references()<CR>
nnoremap <silent> gs :call LanguageClient_textDocument_documentSymbol()<CR>
nnoremap <silent> <F2> :call LanguageClient_textDocument_rename()<CR>
nnoremap <silent> gf :call LanguageClient_textDocument_formatting()<CR>
'';
packages.myVimPackage = with pkgs.vimPlugins; {
start = [ LanguageClient-neovim ];
}
};
Then put the following expression in environment.systemPackages or in the home-manager package list,
to install python-language-server:
(python3.withPackages(ps: [
ps.python-language-server
<div lang="en" dir="ltr" class="mw-content-ltr">
# the following plugins are optional, they provide type checking, import sorting and code formatting
</div>
ps.pyls-mypy ps.pyls-isort ps.pyls-black
]))
Real life examples
YouCompleteMe
Currently the youcompleteme plugin uses unwrapped clang on linux. This causes it to not find stdlib.h. There is a workaround you can put in your .ycm_extra_conf.py 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 stdlib.h.
A better alternative to youcompleteme for C/C++ is to use cquery in combination with the 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 shell wrapper
gvim and gview
You can enable guiSupport to make gvim available, though this won't give you gview:
(pkgs.vim-full.customize {
guiSupport = true;
})