跳转至

Helix: Rust 编写的后 Vim 时代编辑器

为什么要学 Helix

Vim 是一个伟大的编辑器,但它的设计来自 1991 年。Neovim 改进了很多,但想要一个舒适的现代开发环境,你需要花大量时间配置插件(LSP、tree-sitter、自动补全、文件树……)。

Helix 的哲学是:把这些现代功能内置,而不是让用户去拼装插件

痛点Vim/NeovimHelix
LSP 支持需要安装配置 nvim-lspconfig开箱即用
语法高亮需要安装 nvim-treesitter内置 tree-sitter
自动补全需要 nvim-cmp + 多个源内置
文件选择器需要 telescope.nvim内置 fuzzy picker
配置时间数小时到数天几乎零配置
编辑范式先动作后对象 (dw)先选择后动作 (wd)

Helix 不是"另一个 Vim 克隆",而是重新思考了模态编辑的交互方式。它采用 Kakoune 风格的"先选择后操作"范式,在实践中更直观。


核心概念

白话解释

Helix 的核心思路是: 1. 先看见,再操作:先用光标/选择命令选中文本,确认选中内容正确,再执行操作(删除、复制、替换等) 2. LSP 是一等公民:安装了语言服务器就能用,不需要额外配置 3. tree-sitter 驱动:语法高亮、代码折叠、结构化选择都基于语法树,而不是正则表达式

Vim vs Helix 操作范式

Vim 方式:  d  →  w        (先说"删除",再说"一个词") — 操作是盲的
Helix 方式: w  →  d        (先选中一个词,看到高亮,再删除) — 所见即所得

核心概念表

概念说明Vim 等价物
Normal 模式导航和选择Normal 模式
Insert 模式输入文本Insert 模式
Select 模式扩展选区Visual 模式
Goto 模式快速跳转 (g)g 前缀命令
Match 模式匹配操作 (m)%
Space 模式功能菜单 (Space)Leader 键菜单
View 模式视图控制 (z/Z)z 命令
Picker模糊搜索界面Telescope
tree-sitter 节点语法树中的代码单元无(text objects 近似)

模式切换图

         ┌─────────┐
    i  ──│ Insert  │── Esc
    a    │  模式   │
    o    └─────────┘
         ┌─────────┐
  ──────│ Normal  │──────
         │  模式   │
  ──────│ (默认)  │──────
         └─────────┘
    v  ──┌─────────┐
         │ Select  │── Esc
         │  模式   │
         └─────────┘
    g  ──┌─────────┐── 按键后自动返回
         │  Goto   │
         └─────────┘
   空格──┌─────────┐── 按键后自动返回
         │ Space   │
         └─────────┘

安装配置

安装方式

macOS

brew install helix

Linux

# Arch Linux
pacman -S helix

# Ubuntu/Debian (通过 PPA 或 snap)
sudo snap install helix --classic

# 或者通过 AppImage
# 从 https://github.com/helix-editor/helix/releases 下载

# 通过 Cargo (Rust 包管理器)
cargo install --locked helix-term

从源码编译

git clone https://github.com/helix-editor/helix.git
cd helix
cargo install --locked --path helix-term
# 链接运行时文件
ln -s $(pwd)/runtime ~/.config/helix/runtime

安装语言服务器

Helix 内置了 LSP 支持,但你需要安装对应语言的 Language Server:

# Rust
rustup component add rust-analyzer

# Go
go install golang.org/x/tools/gopls@latest

# Python
pip install pyright
# 或
pip install python-lsp-server

# TypeScript/JavaScript
npm install -g typescript-language-server typescript

# C/C++
# Ubuntu
sudo apt install clangd
# macOS
brew install llvm

# Markdown
brew install marksman

验证语言服务器状态:

hx --health
# 或查看特定语言
hx --health go
hx --health python

配置文件

Helix 的配置文件位于 ~/.config/helix/

# ~/.config/helix/config.toml

theme = "catppuccin_mocha"

[editor]
line-number = "relative"
mouse = true
bufferline = "multiple"
color-modes = true
true-color = true
rulers = [80, 120]
idle-timeout = 0
completion-timeout = 5

[editor.cursor-shape]
insert = "bar"
normal = "block"
select = "underline"

[editor.file-picker]
hidden = false
git-ignore = true

[editor.lsp]
display-messages = true
display-inlay-hints = true

[editor.indent-guides]
render = true
character = "│"

[editor.statusline]
left = ["mode", "spinner", "file-name", "file-modification-indicator"]
center = ["diagnostics"]
right = ["selections", "position", "file-encoding", "file-line-ending", "file-type"]

[editor.whitespace.render]
tab = "all"
newline = "none"

[editor.soft-wrap]
enable = true

自定义按键映射

# ~/.config/helix/config.toml (续)

[keys.normal]
C-s = ":write"
C-q = ":quit"
A-x = "extend_to_line_bounds"
X = ["extend_line_up", "extend_to_line_bounds"]

[keys.normal.space]
w = ":write"
q = ":quit"
f = "file_picker"
b = "buffer_picker"
g = "global_search"

[keys.insert]
C-s = ":write"
j = { k = "normal_mode" }  # jk 退出插入模式

语言特定配置

# ~/.config/helix/languages.toml

[[language]]
name = "python"
auto-format = true
formatter = { command = "black", args = ["-", "--quiet"] }

[[language]]
name = "rust"
auto-format = true

[[language]]
name = "go"
auto-format = true
formatter = { command = "goimports" }

[[language]]
name = "typescript"
auto-format = true
formatter = { command = "prettier", args = ["--parser", "typescript"] }

快速上手

打开文件

# 打开单个文件
hx main.go

# 打开多个文件
hx src/main.rs src/lib.rs

# 打开目录(进入文件选择器)
hx .

基本导航

按键功能
h/j/k/l左/下/上/右
w跳到下一个词首
b跳到上一个词首
e跳到词尾
f{char}跳到行内某字符
t{char}跳到行内某字符前
gg跳到文件开头
ge跳到文件结尾
:{n}跳到第 n 行

选择与编辑

w    → 选中下一个词
d    → 删除选中内容
c    → 删除选中内容并进入插入模式
y    → 复制选中内容
p    → 粘贴

# 典型操作流程
w d        → 选中一个词,删除它
2w d       → 选中两个词,删除它们
v jjj d    → 进入选择模式,扩选三行,删除

LSP 功能

按键功能
gd跳转到定义
gr查找引用
gy跳转到类型定义
gi跳转到实现
Space+a代码操作(Code Action)
Space+r重命名符号
Space+k显示悬浮文档
Space+d显示诊断
]d / [d跳到下/上一个诊断

文件操作

按键/命令功能
Space+f文件选择器(fuzzy find)
Space+bBuffer 选择器
:open path打开文件
:write:w保存
:quit:q退出
:wq保存并退出

进阶用法

tree-sitter 结构化选择

这是 Helix 最强大的功能之一——基于语法树选择代码:

按键功能
Alt+o向外扩展选区到父语法节点
Alt+i向内收缩选区到子语法节点
Alt+n选中下一个兄弟节点
Alt+p选中上一个兄弟节点

实际操作示例:

# 光标在 "hello" 上
print("hello world")

# Alt+o → 选中 "hello world" (字符串内容)
# Alt+o → 选中 "hello world" (含引号)
# Alt+o → 选中 print("hello world") (函数调用)
# Alt+o → 选中整个语句

多光标编辑

按键功能
C在下一行添加光标
Alt+C在上一行添加光标
s在选区中搜索并选中匹配
,取消多选,保留主选区
Alt+,取消主选区,保留其他
( / )在多光标间循环
# 实际操作:批量重命名变量
1. w 选中一个词
2. * 选中文件中所有相同词(或 s 在选区内匹配)
3. c 删除并进入插入模式
4. 输入新名字
5. Esc 完成

宏录制

Q    → 开始/停止录制宏
q    → 回放宏
5q   → 回放宏 5 次

集成终端

Helix 虽然没有内置终端,但可以通过快捷键与外部工具协作:

# 在 config.toml 中添加
[keys.normal.space]
t = ":sh tmux split-window -h"

DAP 调试支持

Helix 支持 Debug Adapter Protocol:

# languages.toml 中配置调试器
[[language]]
name = "go"
debugger = { name = "dlv", transport = "tcp", command = "dlv", args = ["dap"] }

[[language]]
name = "rust"
debugger = { name = "lldb-vscode", transport = "stdio", command = "lldb-vscode" }

调试快捷键: | 按键 | 功能 | |------|------| | Space+g+l | 启动调试 | | Space+g+b | 切换断点 | | Space+g+c | 继续执行 | | Space+g+n | 下一步 | | Space+g+s | 步入 |


常见问题

Q1: Vim 用户迁移到 Helix 有多难?

中等难度。基本的 hjkl 导航、i/a/o 插入、:w 保存都一样。最大的区别是操作顺序——从 dw(动词+名词) 变成 wd(名词+动词)。大多数人需要 1-2 周适应。

Q2: Helix 能完全替代 Neovim 吗?

目前还有差距: - Helix 没有插件系统(正在开发中) - 没有内置终端 - 没有文件树侧边栏(用 picker 替代) - 自定义程度不如 Neovim

但如果你的需求是"写代码 + LSP + Git",Helix 已经够用了。

Q3: 没有插件系统怎么扩展功能?

目前的解决方案: - 使用 :sh 命令调用外部工具 - 配合 tmux/Zellij 管理多窗口 - 等待官方插件系统(基于 Wasm)

Q4: 为什么 tree-sitter 比正则高亮好?

  • 正则表达式无法理解代码结构,经常误高亮
  • tree-sitter 构建真实的语法树,理解嵌套、作用域
  • 基于语法树的选择让你可以按函数、参数、语句来选择代码

Q5: hx --health 显示某语言 LSP 未安装?

安装对应的语言服务器二进制文件,确保在 $PATH 中:

# 检查
which gopls
which pyright

# 再次验证
hx --health python

参考资源

资源链接
官方网站https://helix-editor.com
GitHub 仓库https://github.com/helix-editor/helix
官方文档https://docs.helix-editor.com
按键映射速查https://docs.helix-editor.com/keymap.html
语言支持列表https://docs.helix-editor.com/lang-support.html
tree-sitterhttps://tree-sitter.github.io/tree-sitter
Kakoune 编辑范式https://kakoune.org

总结:Helix 是目前"零配置即可获得现代编辑体验"的最佳终端编辑器。如果你厌倦了花时间配置 Neovim 插件,或者想尝试"先选择后操作"的编辑范式,Helix 值得认真尝试。它的 tree-sitter 集成和 LSP 支持在终端编辑器中是第一梯队。