Vim/ru: Difference between revisions
Created page with "==== Используя Flake ====" |
Updating to match new version of source page |
||
| (34 intermediate revisions by 2 users not shown) | |||
| Line 5: | Line 5: | ||
== Установка == | == Установка == | ||
< | <span id="Basic_Install"></span> | ||
=== | === Начальная Установка === | ||
</ | <syntaxhighlight lang="nix> | ||
programs.vim.enable = true; | |||
</syntaxhighlight> | |||
или | |||
<syntaxhighlight lang="nix"> | |||
<syntaxhighlight lang="nix> | programs.vim = { | ||
enable = true; | |||
package = pkgs.vim-full; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
или | или | ||
<syntaxhighlight lang="nix"> | |||
<syntaxhighlight lang="nix> | environment.systemPackages = with pkgs; [ vim-full ]; | ||
environment.systemPackages = with pkgs; [ | |||
</syntaxhighlight> | </syntaxhighlight> | ||
<span id="Using_Home_Manager"></span> | <span id="Using_Home_Manager"></span> | ||
| Line 28: | Line 31: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
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: | ||
</div> | |||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
programs.vim = { | programs.vim = { | ||
| Line 38: | Line 43: | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 44: | Line 48: | ||
</div> | </div> | ||
< | <span id="Vim_Spell_Files"></span> | ||
=== Vim | === Файлы Правописания Vim === | ||
<div | <div class="mw-translate-fuzzy"> | ||
Вы можете настроить на установку файлов правописания в каталог пользователя через home-manager, упаковывая отдельные файлы правописания. Вот пример для neovim и французского языка: | |||
</div> | </div> | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
let | let | ||
| Line 59: | Line 61: | ||
sha256 = "abfb9702b98d887c175ace58f1ab39733dc08d03b674d914f56344ef86e63b61"; | sha256 = "abfb9702b98d887c175ace58f1ab39733dc08d03b674d914f56344ef86e63b61"; | ||
}; | }; | ||
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"; | ||
sha256 = "0294bc32b42c90bbb286a89e23ca3773b7ef50eff1ab523b1513d6a25c6b3f58"; | sha256 = "0294bc32b42c90bbb286a89e23ca3773b7ef50eff1ab523b1513d6a25c6b3f58"; | ||
}; | }; | ||
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"; | ||
sha256 = "086ccda0891594c93eab143aa83ffbbd25d013c1b82866bbb48bb1cb788cc2ff"; | sha256 = "086ccda0891594c93eab143aa83ffbbd25d013c1b82866bbb48bb1cb788cc2ff"; | ||
}; | }; | ||
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 82: | Line 78: | ||
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> | ||
<span id="NeoVim_with_Coc_for_Python"></span> | <span id="NeoVim_with_Coc_for_Python"></span> | ||
| Line 97: | Line 92: | ||
https://github.com/NixOS/nixpkgs/issues/98166#issuecomment-725319238 | https://github.com/NixOS/nixpkgs/issues/98166#issuecomment-725319238 | ||
</div> | </div> | ||
<span id="System_wide_vim/nvim_configuration"></span> | |||
== Глобальная настройка vim/nvim == | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
If you want a system wide "baseline" configuration for vim/nvim here are two examples:. | |||
</div> | </div> | ||
On unstable ветке: | |||
<syntaxhighlight lang="nix"> | |||
< | |||
{ pkgs, ... }: | { pkgs, ... }: | ||
{ | { | ||
programs.vim = { | |||
enable = true; | |||
defaultEditor = true; | |||
package = (pkgs.vim-full.override { }).customize{ | |||
name = "vim"; | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
# Install plugins for example for syntax highlighting of nix files | |||
</div> | </div> | ||
vimrcConfig.packages.myplugins = with pkgs.vimPlugins; { | vimrcConfig.packages.myplugins = with pkgs.vimPlugins; { | ||
start = [ vim-nix vim-lastplace ]; | start = [ vim-nix vim-lastplace ]; | ||
| Line 121: | Line 118: | ||
}; | }; | ||
vimrcConfig.customRC = '' | vimrcConfig.customRC = '' | ||
" your custom vimrc | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
" your custom vimrc | |||
</div> | |||
set nocompatible | set nocompatible | ||
set backspace=indent,eol,start | set backspace=indent,eol,start | ||
" | " Включить подсветку синтаксиса по умолчанию | ||
syntax on | syntax on | ||
" ... | " ... | ||
''; | ''; | ||
} | }; | ||
}; | |||
} | } | ||
</ | </syntaxhighlight> | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
{ pkgs, ... }: | { pkgs, ... }: | ||
{ | { | ||
programs.neovim = { | |||
enable = true; | |||
defaultEditor = true; | |||
vimAlias = true; | |||
configure = { | |||
customRC = '' | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
" your custom vimrc | |||
</div> | </div> | ||
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> | ||
импортируйте их в свой <code>configuration.nix</code> и | |||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
{ | { | ||
| Line 174: | Line 166: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
< | <span id="Custom_setup_without_using_Home_Manager"></span> | ||
== | == Пользовательская настройка без использования Home Manager == | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 184: | Line 174: | ||
</div> | </div> | ||
Плагины Vim могут быть установлены с помощью Nix. Вы можете не использовать менеджеры плагинов и сделать все самостоятельно в <code>.nixpkgs/config</code>. | |||
Vim | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 196: | Line 184: | ||
</div> | </div> | ||
И в vim, и в neovim можно дополнительно включенить ваши любимые плагины и дополнительные библиотеки. Чтобы получить список всех доступных плагинов vim, выполните команду <code>nix search nixpkgs#vimPlugins</code>. | |||
Добавьте следующий код в ваш <code>~/.nixpkgs/config.nix</code> | |||
< | <syntaxhighlight lang="nix"> | ||
{ | { | ||
packageOverrides = pkgs: with pkgs; { | packageOverrides = pkgs: with pkgs; { | ||
myVim = | myVim = vim-full.customize { | ||
name = "vim-with-plugins"; | name = "vim-with-plugins"; | ||
# | # добавьте сюда код из секции с примером | ||
}; | }; | ||
myNeovim = neovim.override { | myNeovim = neovim.override { | ||
configure = { | configure = { | ||
customRC = '' | customRC = '' | ||
# | # здесь должна находится ваша пользовательская конфигурация! | ||
''; | ''; | ||
packages.myVimPackage = with pkgs.vimPlugins; { | packages.myVimPackage = with pkgs.vimPlugins; { | ||
# | # смотрите примеры ниже чтобы узнать как использовать пользовательские пакеты | ||
start = [ ]; | start = [ ]; | ||
opt = [ ]; | opt = [ ]; | ||
| Line 226: | Line 209: | ||
}; | }; | ||
} | } | ||
</ | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 236: | Line 218: | ||
=== Примеры === | === Примеры === | ||
< | <span id="Apply_custom_vimrc_configuration"></span> | ||
==== | ==== Добавить пользовательские настройка в вашу конфигурацию vimrc ==== | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 244: | Line 225: | ||
</div> | </div> | ||
< | <syntaxhighlight lang="nix"> | ||
vim-full.customize { | |||
name = "vim-with-plugins"; | name = "vim-with-plugins"; | ||
# | # добавьте пользовательские строки в .vimrc, например, такие: | ||
vimrcConfig.customRC = '' | vimrcConfig.customRC = '' | ||
set hidden | set hidden | ||
| Line 254: | Line 234: | ||
''; | ''; | ||
} | } | ||
</ | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 265: | Line 244: | ||
</div> | </div> | ||
< | <syntaxhighlight lang="nix"> | ||
vim-full.customize { | |||
vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; { | vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; { | ||
# loaded on launch | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
# loaded on launch | |||
</div> | |||
start = [ YouCompleteMe fugitive ]; | start = [ YouCompleteMe fugitive ]; | ||
# manually loadable by calling `:packadd $plugin-name` | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
# manually loadable by calling `:packadd $plugin-name` | |||
</div> | |||
opt = [ phpCompletion elm-vim ]; | opt = [ phpCompletion elm-vim ]; | ||
# To automatically load a plugin when opening a filetype, add vimrc lines like: | <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 | # autocmd FileType php :packadd phpCompletion | ||
} | } | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 288: | Line 271: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
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. | ||
</div> | |||
<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> | ||
<span id="Using_Vim-Plug_as_manager"></span> | <span id="Using_Vim-Plug_as_manager"></span> | ||
| Line 306: | Line 290: | ||
<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> | ||
< | <span id="Notes_Regarding_Plugins"></span> | ||
==== | ==== Плагины заслуживающие внимания ==== | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 323: | Line 300: | ||
</div> | </div> | ||
< | <span id="Add_a_new_custom_plugin_to_the_users_packages"></span> | ||
=== | === Добавьте новый пользовательский плагин в пользовательские пакеты === | ||
Иногда вы не хотите изменять плагины, находящиес в upstream, для этого вы можете использовать <code>vimUtils.buildVimPlugin</code> для создания своего собственного плагина: | |||
< | <syntaxhighlight lang="nix"> | ||
let | let | ||
vim-better-whitespace = pkgs.vimUtils.buildVimPlugin { | vim-better-whitespace = pkgs.vimUtils.buildVimPlugin { | ||
| Line 342: | Line 316: | ||
}; | }; | ||
}; | }; | ||
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 352: | Line 325: | ||
]; | ]; | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
<span id="Using_flake"></span> | <span id="Using_flake"></span> | ||
| Line 381: | Line 354: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<code>flake.nix</code>: | <code>flake.nix</code>: | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 392: | Line 364: | ||
}; | }; | ||
}; | }; | ||
outputs = inputs@{ nixpkgs, ... }: { | outputs = inputs@{ nixpkgs, ... }: { | ||
| Line 413: | Line 384: | ||
<span id="Vim_as_a_Python_IDE"></span> | <span id="Vim_as_a_Python_IDE"></span> | ||
=== Vim | === Vim в качестве Python IDE === | ||
<div class="mw-translate-fuzzy"> | |||
Следующий фрагмент создаст полнофункциональную IDE для python. | Следующий фрагмент создаст полнофункциональную IDE для python. | ||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 421: | Line 394: | ||
</div> | </div> | ||
< | <syntaxhighlight lang="nix"> | ||
vim-full.customize { | |||
vimrcConfig = { | vimrcConfig = { | ||
customRC = '' | customRC = '' | ||
| Line 441: | Line 413: | ||
} | } | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
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: | ||
</div> | |||
<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 | <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 | ps.pyls-mypy ps.pyls-isort ps.pyls-black | ||
])) | ])) | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<span id="Real_life_examples"></span> | <span id="Real_life_examples"></span> | ||
| Line 462: | Line 435: | ||
<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 lang="en" dir="ltr" class="mw-content-ltr"> | |||
* [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] | ||
</div> | |||
<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)] | * [https://github.com/wagnerf42/nixos-config/blob/master/config/my_vim.nix wagnerf42's config (good for rust language)] | ||
</div> | </div> | ||
| Line 474: | Line 453: | ||
<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] | 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> | ||
| Line 493: | Line 459: | ||
<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="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
[www.vim.org Vim] (vi improved) - свободный текстовый редактор, созданный на основе более старого vi. Ныне это мощный текстовый редактор с полной свободой настройки и автоматизации, возможными благодаря расширениям и надстройкам.
Установка
Начальная Установка
programs.vim.enable = true;
или
programs.vim = {
enable = true;
package = pkgs.vim-full;
};
или
environment.systemPackages = with pkgs; [ vim-full ];
Используя Home-Manager
Vim can easily be set up using Home Manager. Here's a minimal example:
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
Вы можете настроить на установку файлов правописания в каталог пользователя через home-manager, упаковывая отдельные файлы правописания. Вот пример для neovim и французского языка:
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 с Coc.nvim для Python
For NeoVim use this home manager config: https://github.com/NixOS/nixpkgs/issues/98166#issuecomment-725319238
Глобальная настройка vim/nvim
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";
<div lang="en" dir="ltr" class="mw-content-ltr">
# Install plugins for example for syntax highlighting of nix files
</div>
vimrcConfig.packages.myplugins = with pkgs.vimPlugins; {
start = [ vim-nix vim-lastplace ];
opt = [];
};
vimrcConfig.customRC = ''
<div lang="en" dir="ltr" class="mw-content-ltr">
" your custom vimrc
</div>
set nocompatible
set backspace=indent,eol,start
" Включить подсветку синтаксиса по умолчанию
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 = [];
};
};
};
}
импортируйте их в свой configuration.nix и
{
imports =
[
./vim.nix
];
# ...
}
Пользовательская настройка без использования Home Manager
Плагины Vim могут быть установлены с помощью Nix. Вы можете не использовать менеджеры плагинов и сделать все самостоятельно в .nixpkgs/config.
A lot of documentation about package management and configuration of vim in nix is stored at [2] in nixpkgs.
Customizations
И в vim, и в neovim можно дополнительно включенить ваши любимые плагины и дополнительные библиотеки. Чтобы получить список всех доступных плагинов vim, выполните команду nix search nixpkgs#vimPlugins.
Добавьте следующий код в ваш ~/.nixpkgs/config.nix
{
packageOverrides = pkgs: with pkgs; {
myVim = vim-full.customize {
name = "vim-with-plugins";
# добавьте сюда код из секции с примером
};
myNeovim = neovim.override {
configure = {
customRC = ''
# здесь должна находится ваша пользовательская конфигурация!
'';
packages.myVimPackage = with pkgs.vimPlugins; {
# смотрите примеры ниже чтобы узнать как использовать пользовательские пакеты
start = [ ];
opt = [ ];
};
};
};
};
}
After that you can install your special grafted `myVim` or `myNeovim` packages.
Примеры
Добавить пользовательские настройка в вашу конфигурацию vimrc
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";
# добавьте пользовательские строки в .vimrc, например, такие:
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.
Использование Pathogen в качестве менеджера плагинов
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" ];
Использование Vim-plug в качестве менеджера плагинов
vimrcConfig.plug.plugins = with pkgs.vimPlugins; [vim-addon-nix youcompleteme];
Добавление новых плагинов
Плагины заслуживающие внимания
For additional info, you may wish to look at documentation on the nixpkgs repository.
Добавьте новый пользовательский плагин в пользовательские пакеты
Иногда вы не хотите изменять плагины, находящиес в upstream, для этого вы можете использовать vimUtils.buildVimPlugin для создания своего собственного плагина:
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 ];
};
})
];
};
Используя 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 в качестве Python IDE
Следующий фрагмент создаст полнофункциональную IDE для python.
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
]))
Примеры из реальной жизни
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 и Gview
You can enable guiSupport to make gvim available, though this won't give you gview:
(pkgs.vim-full.customize {
guiSupport = true;
})