Vim/ja: Difference between revisions
Haruki7049 (talk | contribs) Created page with "=== Home Managerを使用した例 ===" |
Updating to match new version of source page |
||
| (27 intermediate revisions by 2 users not shown) | |||
| Line 9: | Line 9: | ||
<span id="Basic_Install"></span> | <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; [ | environment.systemPackages = with pkgs; [ vim-full ]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 23: | Line 31: | ||
=== Home Managerを使用した例 === | === Home Managerを使用した例 === | ||
Vimは[[Special:MyLanguage/Home Manager|Home Manager]]を使用して簡単にセットアップ出来ます。以下は最低限の一例です: | |||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
programs.vim = { | programs.vim = { | ||
| Line 35: | Line 43: | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 41: | Line 48: | ||
</div> | </div> | ||
< | <span id="Vim_Spell_Files"></span> | ||
=== | === Vimスペルファイル === | ||
<div | <div class="mw-translate-fuzzy"> | ||
個々のスペルファイルをパッケージ化することで、ユーザーディレクトリにスペルファイルをインストールするようにhome-managerを設定することができます。以下はneovimとフランス語の例です: | |||
</div> | </div> | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
let | let | ||
| Line 56: | 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 79: | 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> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 96: | Line 94: | ||
</div> | </div> | ||
< | <span id="System_wide_vim/nvim_configuration"></span> | ||
== | == システム全体でのvim/nvim設定 == | ||
vim/nvimのシステム全体の"ベースライン"設定が必要な場合は、次の二つの例を参照してください: | |||
unstableでは: | |||
< | <syntaxhighlight lang="nix"> | ||
{ pkgs, ... }: | { pkgs, ... }: | ||
{ | { | ||
programs.vim = { | |||
enable = true; | |||
defaultEditor = true; | |||
package = (pkgs.vim-full.override { }).customize{ | |||
( | |||
name = "vim"; | name = "vim"; | ||
# | # 例として、Nixファイルのシンタックスハイライト表示用のプラグインをインストールする | ||
vimrcConfig.packages.myplugins = with pkgs.vimPlugins; { | vimrcConfig.packages.myplugins = with pkgs.vimPlugins; { | ||
start = [ vim-nix vim-lastplace ]; | start = [ vim-nix vim-lastplace ]; | ||
| Line 119: | Line 115: | ||
}; | }; | ||
vimrcConfig.customRC = '' | vimrcConfig.customRC = '' | ||
" | " 自分のカスタムvimrc | ||
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 = '' | |||
" 自分のカスタムvimrc | |||
" | |||
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 172: | Line 159: | ||
} | } | ||
</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 182: | Line 167: | ||
</div> | </div> | ||
Vimプラグインはnixの助けを借りてインストールすることができます。vimプラグインマネージャーを使用せず、すべて<code>.nixpkgs/config</code>で行うことができます。 | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
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. | ||
</div> | </div> | ||
< | <span id="Customizations"></span> | ||
=== | === カスタマイズする === | ||
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"; | ||
# add here code from the example section | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
# add here code from the example section | |||
</div> | |||
}; | }; | ||
myNeovim = neovim.override { | myNeovim = neovim.override { | ||
configure = { | configure = { | ||
customRC = '' | customRC = '' | ||
# here your custom configuration goes! | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
# here your custom configuration goes! | |||
</div> | |||
''; | ''; | ||
packages.myVimPackage = with pkgs.vimPlugins; { | packages.myVimPackage = with pkgs.vimPlugins; { | ||
# see examples below how to use custom packages | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
# see examples below how to use custom packages | |||
</div> | |||
start = [ ]; | start = [ ]; | ||
opt = [ ]; | opt = [ ]; | ||
| Line 224: | Line 207: | ||
}; | }; | ||
} | } | ||
</ | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 243: | Line 225: | ||
</div> | </div> | ||
< | <syntaxhighlight lang="nix"> | ||
vim-full.customize { | |||
name = "vim-with-plugins"; | name = "vim-with-plugins"; | ||
# add custom .vimrc lines like this: | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
# add custom .vimrc lines like this: | |||
</div> | |||
vimrcConfig.customRC = '' | vimrcConfig.customRC = '' | ||
set hidden | set hidden | ||
| Line 253: | Line 236: | ||
''; | ''; | ||
} | } | ||
</ | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 264: | Line 246: | ||
</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 274: | ||
<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> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 299: | Line 286: | ||
</div> | </div> | ||
<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> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 310: | Line 295: | ||
<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 335: | Line 314: | ||
</div> | </div> | ||
< | <syntaxhighlight lang="nix"> | ||
let | let | ||
vim-better-whitespace = pkgs.vimUtils.buildVimPlugin { | vim-better-whitespace = pkgs.vimUtils.buildVimPlugin { | ||
| Line 347: | Line 325: | ||
}; | }; | ||
}; | }; | ||
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 359: | Line 334: | ||
]; | ]; | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 366: | Line 340: | ||
</div> | </div> | ||
<code>configuration.nix</code>: | <code>configuration.nix</code>: | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 390: | Line 363: | ||
}; | }; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<code>flake.nix</code>: | <code>flake.nix</code>: | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 403: | Line 374: | ||
}; | }; | ||
}; | }; | ||
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 419: | Line 388: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 430: | Line 398: | ||
<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 437: | Line 405: | ||
</div> | </div> | ||
< | <syntaxhighlight lang="nix"> | ||
vim-full.customize { | |||
vimrcConfig = { | vimrcConfig = { | ||
customRC = '' | customRC = '' | ||
| Line 457: | Line 424: | ||
} | } | ||
}; | }; | ||
</ | </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> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
| Line 479: | Line 447: | ||
<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> | ||
| Line 514: | Line 474: | ||
<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:}}]] | ||