Neovim/zh: Difference between revisions

Created page with "安装"
Tags: Mobile edit Mobile web edit
Ardenet (talk | contribs)
mNo edit summary
Tags: Mobile edit Mobile web edit
 
(35 intermediate revisions by 2 users not shown)
Line 18: Line 18:
}}
}}


<div lang="en" dir="ltr" class="mw-content-ltr">
:''另见: [[Special:MyLanguage/Vim|Vim]]''
:''See also: [[Vim]]''
 
[https://neovim.io/ Neovim]<ref>Neovim Team, "Home - Neovim", Neovim Official Website, Last updated March 2025, Accessed June 2025. https://neovim.io/</ref> is a highly extensible and open source text editor that aims to improve upon and modernize the popular [[Vim]]<ref>NixOS Wiki Community, "Vim", NixOS Wiki, Last edited 24 February 2025, Accessed June 2025. https://wiki.nixos.org/wiki/Vim</ref> editor. It's designed to be a drop-in replacement for Vim, maintaining compatibility with most Vim plugins and configurations while offering additional features and improvements. Neovim focuses on extensibility, usability, and performance.
[https://neovim.io/ Neovim]<ref>Neovim 团队, "Home - Neovim", Neovim 官方网站, 最后更新日期:2025年3月;访问日期:2025年6月。 https://neovim.io/</ref> 是一款高度可扩展的开源文本编辑器,旨在改进和现代化流行的 [[Special:MyLanguage/Vim|Vim]]<ref>NixOS 维基社区, "Vim", NixOS 维基, 最后编辑于 2025 年 2 月 24 日,访问于 2025 年 6 月。 https://wiki.nixos.org/wiki/Vim</ref> 编辑器。它被设计为 Vim 的无缝衔接替代品,在保持与大多数 Vim 插件和配置的兼容性的同时,提供额外的功能和改进。Neovim 注重可扩展性、易用性和性能。
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
它引入了强大的插件架构,支持异步插件执行,这可以显著提升某些操作的性能。它还内置了终端模拟器,允许用户直接在编辑器中运行 shell 命令。该项目注重代码质量和可维护性,拥有简洁且文档完善的代码库,方便开发者贡献代码。
It introduces a powerful plugin architecture that allows for asynchronous plugin execution, which can significantly improve performance for certain operations. It also includes a built-in terminal emulator, allowing users to run shell commands directly within the editor. The project emphasizes code quality and maintainability, with a clean, well-documented codebase that makes it easier for developers to contribute.
</div>


<span id="Installation"></span>
<span id="Installation"></span>
安装
== 安装 ==


<div lang="en" dir="ltr" class="mw-content-ltr">
==== Shell ====
==== Shell ====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
要在不修改系统配置的情况下临时在 shell 环境中使用 Neovim,您可以运行:
To temporarily use Neovim in a shell environment without modifying your system configuration, you can run:
</div>


{{code|lang=bash|line=no|1=$ nix-shell -p neovim}}
{{code|lang=bash|line=no|1=$ nix-shell -p neovim}}


<div lang="en" dir="ltr" class="mw-content-ltr">
这样就能在当前 shell 中使用 Neovim 编辑器了。之后,您可以通过输入 <code>nvim</code> 来启动 Neovim。
This makes the Neovim editor available in your current shell. You can then launch Neovim by typing <code>neovim</code>.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="System_setup"></span>
==== System setup ====
==== 系统设置 ====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
要在系统范围内安装 Neovim,使其可供所有用户使用,请将以下内容添加到您的配置中:
To install Neovim system-wide, making it available to all users, add the following to your configuration:
</div>


{{code|lang=nix|line=no|1=<span lang="en" dir="ltr" class="mw-content-ltr"># Example for /etc/nixos/configuration.nix</span>
{{code|lang=nix|line=no|1=# /etc/nixos/configuration.nix 示例
environment.systemPackages = [
environment.systemPackages = [
   pkgs.neovim
   pkgs.neovim
];
];


<span lang="en" dir="ltr" class="mw-content-ltr"># User-specific installation (in ~/.config/nixpkgs/home.nix)</span>
# 单用户安装(位于 ~/.config/nixpkgs/home.nix
home.packages = [
home.packages = [
   pkgs.neovim
   pkgs.neovim
];}}
];}}


<div lang="en" dir="ltr" class="mw-content-ltr">
使用 <code>nixos-rebuild switch</code> <code>home-manager switch</code> 重建系统后,Neovim 将被安装且可使用。
After rebuilding your system with <code>nixos-rebuild switch</code> or <code>home-manager switch</code>, Neovim will be installed and accessible.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Configuration"></span>
== Configuration ==
== 配置 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Basic"></span>
==== Basic ====
==== 基础 ====
</div>


{{code|lang=nix|line=no|1=<div lang="en" dir="ltr" class="mw-content-ltr">
{{code|lang=nix|line=no|1=# 全局配置
# Global Configuration
</div>
programs.neovim = {
programs.neovim = {
   enable = true;
   enable = true;
Line 82: Line 64:
};
};


<div lang="en" dir="ltr" class="mw-content-ltr">
# 单用户配置
# Home Configuration
</div>
programs.neovim = {
programs.neovim = {
   enable = true;
   enable = true;
Line 92: Line 72:
};}}
};}}


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Advanced"></span>
==== Advanced ====
==== 进阶 ====
</div>


{{code|lang=nix|line=no|1=<div lang="en" dir="ltr" class="mw-content-ltr">
{{code|lang=nix|line=no|1=# 全局配置
# Global Configuration
</div>
programs.neovim = {
programs.neovim = {
   enable = true;
   enable = true;
Line 120: Line 97:
};
};


<div lang="en" dir="ltr" class="mw-content-ltr">
# 单用户配置
# Home Configuration
# 您需要添加以下代码行,将其设置为默认编辑器:
# You have to add the line below to set it as the default editor:
programs.neovim.defaultEditor = true;}}
</div>
environment.variables.EDITOR = "nvim";}}


<div lang="en" dir="ltr" class="mw-content-ltr">
== 小技巧 ==
== Tips and Tricks ==
{{expand}}
{{expand}}
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Package_Variations"></span>
==== Package Variations ====
==== 包的变体 ====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
请查看 [https://github.com/nix-community/neovim-nightly-overlay Neovim Nightly Overlay]<ref>Nix 社区, "neovim-nightly-overlay", GitHub, 最后更新于 2025 年 6 月,访问于 2025 年 6 月。https://github.com/nix-community/neovim-nightly-overlay</ref> 以安装最新的 Neovim nightly 版本。
Have a look at the [https://github.com/nix-community/neovim-nightly-overlay Neovim Nightly Overlay]<ref>Nix Community, "neovim-nightly-overlay", GitHub, Last updated June 2025, Accessed June 2025. https://github.com/nix-community/neovim-nightly-overlay</ref> to install the most recent current nightly version of Neovim.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
您可以通过以下命令运行主版本:
You can run the master version via the following command:
</div>


{{code|lang=bash|line=no|1=$ nix run "github:nix-community/neovim-nightly-overlay"}}
{{code|lang=bash|line=no|1=$ nix run "github:nix-community/neovim-nightly-overlay"}}


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Plugin_Management"></span>
==== Plugin Management ====
==== 插件管理 ====
</div>


{{code|lang=nix|line=no|1=plugins = [
{{code|lang=nix|line=no|1=plugins = [
   <div lang="en" dir="ltr" class="mw-content-ltr">
   # 示例插件: nvim-tree-lua
# Example Plugin: nvim-tree-lua
</div>
   pkgs.vimPlugins.nvim-tree-lua
   pkgs.vimPlugins.nvim-tree-lua


   <div lang="en" dir="ltr" class="mw-content-ltr">
   # 示例插件: 配置后的vim-startify
# Example Plugin: vim-startify with configuration
</div>
   {
   {
     plugin = pkgs.vimPlugins.vim-startify;
     plugin = pkgs.vimPlugins.vim-startify;
Line 163: Line 126:
   }
   }


   <div lang="en" dir="ltr" class="mw-content-ltr">
   # 示例插件: 带 Lua 配置的 nvim-colorizer-lua
# Example Plugin: nvim-colorizer-lua with Lua config
   # 由于 Lua 模块运行时路径的处理方式,您的配置可能需要
   # Due to how the runtimepath for Lua modules is processed, your configuration may require
   # packadd! plugin-name 以引入模块. 一个 home-manager 示例如下:
   # packadd! plugin-name to require a module. A home-manager example:
</div>
   {
   {
     plugin = pkgs.vimPlugins.nvim-colorizer-lua;
     plugin = pkgs.vimPlugins.nvim-colorizer-lua;
Line 174: Line 135:
       lua << END
       lua << END
         require 'colorizer'.setup {
         require 'colorizer'.setup {
           '*'; <span lang="en" dir="ltr" class="mw-content-ltr">-- Highlight all files, but customize some others.</span>
           '*'; -- 高亮所有类型文件,但可自定义一些类型。
           '!vim'; <span lang="en" dir="ltr" class="mw-content-ltr">-- Exclude vim from highlighting.</span>
           '!vim'; -- 排除 vim 类型文件高亮.
         }
         }
       END
       END
Line 181: Line 142:
   }
   }


   <div lang="en" dir="ltr" class="mw-content-ltr">
   # 示例插件: 带 Lua 配置的 nvim-treesitter
# Example Plugin: nvim-treesitter with Lua config
</div>
   {
   {
     plugin = pkgs.vimPlugins.nvim-treesitter;
     plugin = pkgs.vimPlugins.nvim-treesitter;
Line 191: Line 150:
         require'nvim-treesitter.configs'.setup {
         require'nvim-treesitter.configs'.setup {
           highlight = {
           highlight = {
             enable = true,              <span lang="en" dir="ltr" class="mw-content-ltr">-- false will disable the whole extension</span>
             enable = true,              -- false 将禁用整个插件
             disable = {},              <span lang="en" dir="ltr" class="mw-content-ltr">-- list of languages that will be disabled</span>
             disable = {},              -- 被禁用的语言列表
           },
           },
           incremental_selection = {
           incremental_selection = {
Line 220: Line 179:
   }
   }


   <div lang="en" dir="ltr" class="mw-content-ltr">
   # tree-sitter 安装语法
# Installing grammars for tree-sitter
   # 选项 1:安装所有语法包
   # Option 1: Install all grammar packages
   pkgs.vimPlugins.nvim-treesitter.withAllGrammars
   pkgs.vimPlugins.nvim-treesitter.withAllGrammars
 
 
   # Option 2: Install specific grammar packages
   # 选项 2:安装特定语法包
   # (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [ p.c p.java ]))
   # (pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [ p.c p.java ]))
</div>


   <div lang="en" dir="ltr" class="mw-content-ltr">
   # 选项 3:不使用 Nix 安装语法
# Option 3: Installing grammars without Nix
# 通过内置命令安装语法包可能会导致错误。
  # Installing grammar packages through the built-in command can lead to errors.
# 以下 Neovim 命令将为 C 编程语言安装语法高亮::TSInstall c
  # The following Neovim command will install syntax highlighting for the C programming language: :TSInstall c
</div>
];}}
];}}


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Frameworks"></span>
==== Frameworks ====
==== 框架 ====
</div>
 
如果您不想手动配置系统,NixOS 提供了多种预定义配置和社区支持的选项。以下列举其中一些:


<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://www.lazyvim.org/ LazyVim]<ref>LazyVim 团队, "入门教程", LazyVim 官方网站, © 2025, 访问于 2025年6月。 https://www.lazyvim.org/</ref>
If you prefer not to configure your system manually, NixOS offers several predefined configurations and community-supported options. Here are a few of them:
* [https://astronvim.com/ AstroNvim]<ref>AstroNvim 团队, "AstroNvim", AstroNvim 官方网站, N/A, 访问于 2025年6月。 https://astronvim.com/</ref>
</div>
* [https://nvchad.com/ NVChad]<ref>Siduck, "NvChad", NvChad 官方网站, © 2025, 访问于 2025年6月。 https://nvchad.com/</ref>


<div lang="en" dir="ltr" class="mw-content-ltr">
默认情况下,LazyVim 会阻止加载非 LazyVim 管理的插件。这包括所有通过 Nix 安装的插件。如果您想同时使用 Nix 和 LazyVim 安装插件,请将以下内容添加到您的 LazyVim 配置中:
* [https://www.lazyvim.org/ LazyVim]<ref>LazyVim Team, "Getting Started", LazyVim Official Website, © 2025, Accessed June 2025. https://www.lazyvim.org/</ref>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
{{code|lang=lua|line=no|1=
* [https://astronvim.com/ AstroNvim]<ref>AstroNvim Team, "AstroNvim", AstroNvim Official Website, N/A, Accessed June 2025. https://astronvim.com/</ref>
require("lazy").setup(lazyPackages, {
</div>
  performance = {
    reset_packpath = false, -- so that plugins outside of lazy can be loaded
  },
})
vim.cmd([[ packloadall]] ) -- load plugins outside of lazy
}}


<div lang="en" dir="ltr" class="mw-content-ltr">
[https://github.com/folke/lazy.nvim/issues/402#issuecomment-2084997594 源码]
* [https://nvchad.com/ NVChad]<ref>Siduck, "NvChad", NvChad Official Website, © 2025, Accessed June 2025. https://nvchad.com/</ref>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="FHS_wrapper"></span>
==== FHS wrapper ====
==== FHS 包装 ====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
您可以创建自定义的 Neovim FHS 包装器
You can create a custom neovim FHS wrapper
</div>


{{code|lang=nix|line=no|1=
{{code|lang=nix|line=no|1=
Line 281: Line 235:


<!--T:FHS_WRAPPER_SOURCE-->
<!--T:FHS_WRAPPER_SOURCE-->
<div lang="en" dir="ltr" class="mw-content-ltr">
FHS 封装示例基于 nixpkgs 中的一个贡献代码<ref name="nixpkgs-pr-334032">NixOS,“功能:自定义 Neovim FHS 封装”(Pull Request #334032),GitHub,2025 年,访问于 2025 年 6 月。https://github.com/NixOS/nixpkgs/pull/334032</ref>
This FHS wrapper example is based on a contribution to nixpkgs<ref name="nixpkgs-pr-334032">NixOS, "Feature: Custom Neovim FHS Wrapper" (Pull Request #334032), GitHub, 2025, Accessed June 2025. https://github.com/NixOS/nixpkgs/pull/334032</ref>.
有关包含使用类似 FHS 环境设置 <code>mason.nvim</code> 的扩展配置,请参阅此 [https://github.com/NixOS/nixpkgs/issues/281219#issuecomment-2284713258 NixOS/nixpkgs 问题评论]
For an extended configuration that includes setting up `mason.nvim` with a similar FHS environment, see this [https://github.com/NixOS/nixpkgs/issues/281219#issuecomment-2284713258 NixOS/nixpkgs issue comment].
</div>


== 故障排除 ==
== 故障排除 ==
{{expand}}
{{expand}}


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="lua-language-server:_Dynamically_linked_executable_error"></span>
==== lua-language-server: Dynamically linked executable error ====
==== lua-language-server: 动态链接可执行文件错误 ====
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
在您的<code>~/.local/state/nvim/lsp.log</code>文件中,您会看到以下错误:
In your <code>~/.local/state/nvim/lsp.log</code>, you have the following error:
</div>


{{code|lang=text|line=no|1=[ERROR][2025-06-07 23:13:15] ...p/_transport.lua:36 "rpc" "lua-language-server" "stderr" "Could not start dynamically linked executable: /home/incogshift/.local/share/nvim/mason/packages/lua-language-server/libexec/bin/lua-language-server\nNixOS cannot run dynamically linked executables intended for generic\nlinux environments out of the box. For more information, see:\nhttps://nix.dev/permalink/stub-ld\n"}}
{{code|lang=text|line=no|1=[ERROR][2025-06-07 23:13:15] ...p/_transport.lua:36 "rpc" "lua-language-server" "stderr" "Could not start dynamically linked executable: /home/incogshift/.local/share/nvim/mason/packages/lua-language-server/libexec/bin/lua-language-server\nNixOS cannot run dynamically linked executables intended for generic\nlinux environments out of the box. For more information, see:\nhttps://nix.dev/permalink/stub-ld\n"}}


<!--T:LUA_LS_SO_REF-->
<!--T:LUA_LS_SO_REF-->
<div lang="en" dir="ltr" class="mw-content-ltr">
这个问题可以在 Stack Overflow 上找到解决方案<ref name="so-lua-ls-dynlink">Stack Overflow 贡献者,“对‘无法在 NixOS 上启动动态链接可执行文件...’的解答”,Stack Overflow,2025,访问于 2025 年 6 月。https://stackoverflow.com/a/78215911/27134695</ref>
A solution for this issue can be found on Stack Overflow<ref name="so-lua-ls-dynlink">Stack Overflow Contributor, "Answer to 'Could not start dynamically linked executable... on NixOS'", Stack Overflow, 2025, Accessed June 2025. https://stackoverflow.com/a/78215911/27134695</ref>.
</div>


<span id="See_also"></span>
<span id="See_also"></span>
Line 315: Line 262:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="References"></span>
== References ==
== 参考 ==
</div>


[[Category:Applications|分类:应用程序]]
[[Category:Applications]]
[[Category:CLI Applications|分类:CLI 程序]]
[[Category:CLI Applications]]
[[Category:Text Editor|分类:文本编辑器]]
[[Category:Text Editor]]