helix

官方文档

解决方案

shell

配置

即使 Helix 在零配置下也可以使用,如果想要更加符合自己的习惯还是需要一些配置。 erasin/helix-config 是我自己正在使用的配置文件。

在 Helix 中,加载配置的顺序是 默认配置 –>> .config/helix/ 中自定义配置 –> self-project/.helix/ 项目文件夹下自定义配置。在三层配置这种常规设计基本上可以满足各种使用的情况了。

配置文件结构主要有:

  • config.toml <– 编辑器配置
  • language.toml <– 语言支持配置
  • themes/ <– 自定义主题
    • self-theme1.toml
  • icons/ <– 自定义图标
    • self-icons.toml

config.toml

配置主要提供 true-color 支持,自定义显示,以及自定义键盘布局。在编辑器器中使用 :set-option 可以看到配置选项,或者阅读官方文档配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
theme = "zed_onedark"
# icons = "nerd"

# editor 编辑器
[editor]

# 真彩支持
true-color = true

# 光标样式
[editor.cursor-shape]
insert = "bar"
normal = "block"
select = "underline"

# 状态栏定义
[editor.statusline]
# [#2869] file-type-icon
left = ["mode", "spacer", "spinner", "spacer", "file-name", "file-modification-indicator"]
center = ["diagnostics","workspace-diagnostics"]
right = ["position-percentage", "file-encoding", "file-type", ]

# 键盘布局
[keys.normal]
# use `li` or remap `after insert`
a = ["move_char_right","insert_mode"]
"C-s" = ":write" # 原保存跳转列表位置,修改为 C-j
"C-j" = ["save_selection"]
"C-r" = ":reload"
"C-z" = "normal_mode" # replace suspend
"C-q" = ":quit"
"A-/" = "toggle_comments"
"\\" = ":reflow" # |
"X" = "extend_line_above"
"Z" = { "Z" = [":quit"] }

# space mode
[keys.normal.space]
"x" = ":buffer-close"
"w" = { "r" = ":config-reload" }
"." = "file_picker_in_current_buffer_directory"

[keys.insert]
# macos 自动切换到英文环境
# "esc" = [":sh macism com.apple.keylayout.ABC", "normal_mode"]

# [keys.select]

Helix 提供 keymap 和 commands 命令, 这些命令在自定义键盘布局中自由组合,命令组会顺序处理。比如 a = ["move_char_right","insert_mode"] Helix 中 a 默认为选区追加, 将其覆盖为字符向后移动一位编辑模式。详细的请参看 配置文档 。

lsp

通过 hx --health language 检查 lsp
内置语言支持 Tree-Sitter 查看项目的 languages.toml 可以看到支持的语言。
How to install the default language servers · helix-editor/helix Wiki
编写 languages.toml,保存在 ~/.config/helix/ 路径下。参考官网的配置就好,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[[language]]
name = "rust"
auto-format = false

# If this doesn't work, you might be on a older release version which handles this differently.
# Try using [language.config.check] instead of [language-server.rust-analyzer.config.check]
[language-server.rust-analyzer.config.check]
command = "clippy"

# [[grammar]]
# name = "rust"
# source = { git = "https://github.com/tree-sitter/tree-sitter-rust", rev = "????" }

# 下这是复制粘贴来的。
[[language]]
name = "python"
scope = "source.python"
injection-regex = "python"
file-types = ["py","pyi","py3","pyw","ptl",".pythonstartup",".pythonrc","SConstruct"]
shebangs = ["python"]
roots = ["setup.py", "setup.cfg", "pyproject.toml"]
comment-token = "#"
language-server = { command = "pyright-langserver", args = ["--stdio"] }
indent = { tab-width = 4, unit = " " }
# will get "Async jobs timed out" errors if this empty config is not added
config = {}

# [language-server.pyright-langserver.config.check]
# command = "clippy"

在配置文件中 “[[grammar]]“ 底下有指定要安装某个语言的 LSP 服务器,但是我不理解其中一些配置参数。这个配置文件的内容我是仿照 Languages (helix-editor.com) 复制粘贴的。

自定义语言支持

如果有自定义的特殊语言支持,一种是提交 issues 到官方项目寻求帮助,另外一种是自己动手处理,具体可以分解以下步骤:

  1. 向 languages.toml 中追加语言和语言的 tree-sitter 实现。

  2. 向 runtime/queries/ 下对语言 hightlights.scm 高亮支持 , textobjects.scm 文本选择支持, indents.scm 缩进支持。

  3. 如果是在 helix 项目中提交代码,需要执行 cargo xtask docgen 来生成文档支持, 自定义的则不需要这一步。

  4. hx -g fetch & hx -g build 会自动拉去配置 tree-sitter 并编译。之后就可以测试了。

可参考

neovim

windows

安装

安装必要组件:

1
scoop install neovim neovide git lazygit gcc ripgrep fd unzip tree-sitter luarocks

下载并安装 LazyVim 配置:

1
git clone https://github.com/LazyVim/starter $env:LOCALAPPDATA\nvim --depth=1

为了显示 Neovim 界面中的图标,需要安装一款 Nerd Font 字体,这里选择 UbuntuMono Nerd Font 字体。可以通过 Scoop 进行安装:

1
2
scoop bucket add nerd-fonts
scoop install UbuntuMono-NF

在配置文件 $env:LOCALAPPDATA\nvim\lua\config\options.lua 中添加下行代码来设置字体:

1
2
3
local opt = vim.opt

opt.guifont = "UbuntuMono Nerd Font:h12"

在命令行中使用 neovide 命令就可以启动 Neovim 了。值得注意的是, Neovide 只要使用参数 --wsl 就可以在 WSL 环境中运行,不过这时 LazyVim 的配置也需要安装到 WSL 环境中:

1
git clone https://github.com/LazyVim/starter ~/.config/nvim --depth=1

初始化

程序第一次运行时会自动下载和安装插件。如果遇到网络问题而导致安装失败也没关系,按下 R (大写)重新安装直至成功为止。所有插件安装成功后, nvim-treesitter 还会继续安装组件,等所有插件和组件安装完毕后,按下 q 退出安装界面。

参考