Vim/zh: Difference between revisions

Ardenet (talk | contribs)
Created page with "* [https://github.com/wagnerf42/nixos-config/blob/master/config/my_vim.nix wagnerf42 的配置(适用于 Rust 语言)]"
Tags: Mobile edit Mobile web edit
Ardenet (talk | contribs)
Created page with "对于 C/C++ 来说,比 youcompleteme 更好的替代方案是使用 [https://github.com/cquery-project/cquery/ cquery] 并结合 [https://github.com/autozimu/LanguageClient-neovim LanguageClient-neovim]。如果您从 nixpkgs 安装 cquery,它在 nix-shell 中使用时也能找到 C 头文件,因为它使用了一个自定义的 [https://github.com/NixOS/nixpkgs/commit/04f3b76dcec21f2fcba6b1b0afbb3ed224165050#diff-11cdfc0385b9e017089c1ac09c5b838e shell 包装器]。"
 
(8 intermediate revisions by the same user not shown)
Line 42: Line 42:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
有关所有选项,请参阅 [https://github.com/rycee/home-manager/blob/master/modules/programs/vim.nix]
See [https://github.com/rycee/home-manager/blob/master/modules/programs/vim.nix] for the full set of options.
</div>


<span id="Vim_Spell_Files"></span>
<span id="Vim_Spell_Files"></span>
Line 84: Line 82:
==== NeoVim 配置带有 Python 支持的 Coc ====
==== NeoVim 配置带有 Python 支持的 Coc ====


<div lang="en" dir="ltr" class="mw-content-ltr">
对于 NeoVim,请使用以下 home-manager 配置:
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
</div>


<span id="System_wide_vim/nvim_configuration"></span>
<span id="System_wide_vim/nvim_configuration"></span>
Line 158: Line 154:
== 不使用 Home Manager 的自定义设置 ==
== 不使用 Home Manager 的自定义设置 ==


<div lang="en" dir="ltr" class="mw-content-ltr">
{{note|要了解如何在 Nix 系统中设置 Vim 的总体概述,请参阅 [https://www.mpscholten.de/nixos/2016/04/11/setting-up-vim-on-nixos.html mpscholten的博客]}}
{{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] }}
</div>


Vim 插件可以通过 nix 安装。您可以不使用 vim 插件管理器,直接在 <code>.nixpkgs/config</code> 中完成所有操作。
Vim 插件可以通过 nix 安装。您可以不使用 vim 插件管理器,直接在 <code>.nixpkgs/config</code> 中完成所有操作。


<div lang="en" dir="ltr" class="mw-content-ltr">
在 nix 中对 vim 进行包管理和配置的大部分文档存储在 nixpkgs 的 [https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/vim.section.md] 中。
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>


<span id="Customizations"></span>
<span id="Customizations"></span>
Line 206: Line 198:
==== 应用自定义 vimrc 配置 ====
==== 应用自定义 vimrc 配置 ====


<div lang="en" dir="ltr" class="mw-content-ltr">
注意:您必须使用 <code>vimrcConfig.customRC</code> 而不是手动安装 <code>~/.vimrc</code>,因为自定义 Vim 会默认忽略您主目录中的任何 vimrc 文件。
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.
</div>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
vim-full.customize {
vim-full.customize {
   name = "vim-with-plugins";
   name = "vim-with-plugins";
   <div lang="en" dir="ltr" class="mw-content-ltr">
   # 添加自定义的 .vimrc 行,例如:
# add custom .vimrc lines like this:
</div>
   vimrcConfig.customRC = ''
   vimrcConfig.customRC = ''
     set hidden
     set hidden
Line 223: Line 211:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
如果您需要在添加插件之前运行代码,可以使用 <code>vimrcConfig.beforePlugins</code>(如果您要覆盖 [https://github.com/NixOS/nixpkgs/blob/c3df8057dad986bf7f3928de1b5233fadb52bb15/pkgs/misc/vim-plugins/vim-utils.nix#L264-L267 默认值],请务必包含 <code>set nocompatible</code>)。
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]).
</div>


<span id="Using_vim&#039;s_builtin_packaging_capability"></span>
<span id="Using_vim&#039;s_builtin_packaging_capability"></span>
Line 387: Line 373:
(python3.withPackages(ps: [
(python3.withPackages(ps: [
   ps.python-language-server
   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
   ps.pyls-mypy ps.pyls-isort ps.pyls-black
]))
]))
Line 405: Line 389:
=== YouCompleteMe ===
=== YouCompleteMe ===


<div lang="en" dir="ltr" class="mw-content-ltr">
目前 youcompleteme 插件在 Linux 上使用 [https://github.com/NixOS/nixpkgs/blob/8e7b1f2ac2e261d5a644fef860a0d050ea227c06/pkgs/misc/vim-plugins/default.nix#L695 unwrapped clang]。这导致它找不到 <code>stdlib.h</code>。您可以在您的 <code>.ycm_extra_conf.py</code> 文件中添加 [https://github.com/andrewrk/genesis/blob/5f49cd9a8c2b61b9859a22102bc3f732add9461a/.ycm_extra_conf.py 使其正常运行的示例],其工作原理是执行 C/C++ 编译器并使其输出搜索路径列表,其中包括查找 <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>.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
对于 C/C++ 来说,比 youcompleteme 更好的替代方案是使用 [https://github.com/cquery-project/cquery/ cquery] 并结合 [https://github.com/autozimu/LanguageClient-neovim LanguageClient-neovim]。如果您从 nixpkgs 安装 cquery,它在 nix-shell 中使用时也能找到 C 头文件,因为它使用了一个自定义的 [https://github.com/NixOS/nixpkgs/commit/04f3b76dcec21f2fcba6b1b0afbb3ed224165050#diff-11cdfc0385b9e017089c1ac09c5b838e shell 包装器]
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>


<span id="gvim_and_gview"></span>
<span id="gvim_and_gview"></span>