极客油画

helix编辑器

vim: 先决定操作,再选择范围。helix: 先选择范围,再执行操作。
helix 25.07.1 (a05c151b)。
vscode插件:mermaiddraw.io

可以使用 :tutor 命令来查看helix教程。

基本概念:

  • Buffers: 缓冲区是文件在内存中的映像。
  • yank: 在编辑器领域特指将文本提取到寄存器而不删除的操作,中文技术社区固定译作"复制"。

1. hx和vim快捷键对比

hx独有特性--多光标:

hx独有特性--Space键:

  • 搜索结果中可使用 Ctrl-n/Ctrl-p上下导航,Enter确认选择
  • Space+ f(或直接输入 :file-open)打开文件选择器。
  • Space+ s 搜索当前文件的符号(如函数、变量),基于 Tree-sitter 的语法树解析,结果更精准
  • Space+ / 启动全局搜索,输入关键词后会在项目范围内匹配内容
Multi-File:
    :e filename   [hx :open filename] = edit a file in a new buffer
    :bn           [hx :buffer-next]   = go to next buffer
    :bd           [hx :buffer-close]  = delete a buffer(close file)
    :sp filename  [hx :hsplit]        = open a file in new buffer and split window(以水平的方式打开)
    :vsp filename [hx :vsplit]        = open a file in new buffer and split window(以垂直的方式打开)
        :windo :set scrollbind        = 移动一个窗口另一个窗口也跟着移动。
        :windo :set noscrollbind      = 解绑。
        :windo :set cursorbind        = 同时控制光标。
        :windo :set nocursorbind      = 解绑。
    ctr w         [hx-same]           = window commands:
        ctrl-w s = split window(以水平的方式)
        ctrl-w w = switch windows
        ctrl-w q = quit a window
        ctrl-w v = split windows vertically(以垂直的方式)
    Tab Commands  [hx-nonsupport]:
        :tabe filename = edit file in new tab
        gt             = next tab
        gT             = previous tabs
        :tabr          = First tab
        :tabl          = Last tab
        :tabm [N]      = move current tab after tab N


Exiting [hx-same]:
    :w  = save
    :wq = save and quit
    :q  = quit, but failed if unsaved
    :q! = quit


Search/Replace:
    /pattern       = search for pattern
    ?/pattern      = search backwards for pattern
    n              = repeat search in same direction
    N              = repeat search in opposite direction
    :s/old/new/g   = replace all old with throughout file
    :s/old/new/gc  = replace all old with new in this line and confirm each one
    :%s/old/new/gc = replace all old with new in this file and confirm each one
        去掉所有的<200b>字符 = :%s/\%u200b//g [hx ....]
    :g/^#/d        = 删除所有以#开头的行
    :g/^$/d        = 删除所有的空行


Visual Mode:
    # 进入可视化模式的命令
        v      = start visual mode
        V      = start linewise visual mode
        ctrl-v = start blockwise visual mode
    Marking Text:
        o  = move to other end of marked area
        U  = upper case of marked area
        O  = move to Other corner of block
        aw = mark a word
        ab = a ()block (with braces)(只能作用小括号)
        aB = a {}block (with brackets){只能作用大括号}
        ib = inner () block(和ab一样,但是不包含括号)
        iB = inner {} block
    commands:
        > = shift right
        < = shift left
        y = yank
        d = delete
        ~ = switch case


Cut and Paste:
    dd  = delete (cut) a line
    dw  = delete the current word
    x   = delete current character
    X   = delete previous character
    D   = delete to end of line
    yy  = yank (copy a line)
    2yy = yank 2 lines
    yw  = yank word
    y$  = yank to end to line
    p(小写) = put the clipboard after cursor/current line
    P(大写) = put the clipboard before the cursor/current line
    ]p = put the clipboard at the proper indentation
    "a = use a register named a for the next yank / paste operation


Cursor Movement:
    h,j,k,l
    ctrl-f = page up
    ctrl-b = page down
    %      = 由左括号跳转到右括号
    w      [hx-same] = 跳转到下一个单词的开头 
    e      = 跳转到以一个单词的结尾
    b      = jump backword by words
    gg     = go to first line
    gd     = go to def of the function or var under the cursor
    [N]G   = go to line N or last line
    fx     [hx-same] = 跳转到当前文本行的下一个x字符
    ;      = repeat last f command  (行内查找重复)
    tx     = 跳转到当前文本行的下一个x字符前
    Fx     = move the cursor backwords to the next occurrence of x
    )      = move the cursor to next sentence
    (      = move the cursor to previous sentence
    *      = 跳转到当前游标中的字符串下次出现的位置
    #      = 和星号相反
    `.     = 跳转到最后编辑的地方
当前屏幕跳转:
    H      = move the cursor to the Highest line on the screen
    M      = move the cursor to the Middle of the screen
    L      = move the cursor to the Lowest line of the screen
打锚点和跳转到锚点:
    ma     = Make a bookmark name a at the current cursor position
    `a     = Go to bookmark a (backtick, not single quote)


Insert Mode :
    i   = insert mode at cursor
    I   = insert at the beginning of line
    a   = append after the cursor
    A   = append at the end of the line
    o   = open blank line below current line
    O   = open blank line above current line
    Esc = exit insert mode
    Completions(Type a few chars then):
        ctrl-n = next completion
        ctrl-p = previous completion


Edit(编辑快捷键):
    r      = replace a single character(!insert mode)
    J      = join line below to the cursor line
    cc     = change an entire line
    cw     = change to the end of word
    c$     = change to the end of line
    s      = delete character at cursor and substitute text
    S      = delete line at cursor and substitute text
    xp     = transpose to letters
    u      [hx u] = undo
    ctrl-r [hx U] = redo
    .      = repeat last command(文本改变重复)
    ~      = switch case
    g~iw   = switch case of current word
    gUiw   = make current word uppercase
    guiw   = make current word lowercase
    >>     = indent line one column right
    <<     = indent line one column left
    ==     = auto-indent current line
    ctrl+a = 该操作会从光标处开始,向后查找离光标最近的数字,如果找到就将数字的值加1。
    ctrl+x = 就是将数字减1。


重复:
    .           = 文本改变重复,回退用 u
    ;           = 行内查找重复,回退用 ,
    n           = 全文查找重复,回退用 N
    &           = 文本替换重复(重复行内替换 :s/target/replacement/g),回退用 u
    @[register] = 宏重复,回退用 u
        说明: vim里面可以用q{寄存器}开始进行录制,之后用q来结束录制,寄存器的名字a-z中的任意一个,比如qa就是将操作录制到寄存器a中,之后如果想要使用该宏,使用@a接可以重复录制的操作。
        例子: `qa,yy,p,ctrl+a,q`然后10@a  =  将this is number1文本进行复制,然后粘贴到下一行,并将数字1增加到2,每行都递增,重复10行


Other:
    ctrl+s = 锁定vim
    ctrl+q = 解锁vim

2. hx调用系统粘贴板

:show-clipboard-provider 可以展示当前使用的系统粘贴板工具名。

  • Helix 在 Linux 下默认依赖 xclip,但支持通过配置适配wl-clip
  • 安装: apt install -y xclip
  • 测试:
    echo "测试文本" | xclip -selection clipboard  # 复制到剪贴板
    xclip -selection clipboard -o                # 从剪贴板粘贴
    
  • 安装: apt install -y wl-clipboard
  • 测试:
    echo "测试文本" | wl-copy    # 复制到剪贴板
    wl-paste                    # 从剪贴板粘贴
    

3. 配置

helix的配置:

theme = "ayu_dark"
[editor]
mouse = false
[editor.soft-wrap]
enable = true
[keys.normal]
"g" = { ";" = ":echo %sh{git blame -L %{cursor_line},+1 %{buffer_name}}" }

.vimrc配置:

syntax on
set fillchars+=vert:\\
set encoding=utf-8
":e ++enc=gb18030  尝试用 GB18030 重新加载
set fileencodings=ucs-bom,utf-8,gb18030,gbk,gb2312,cp936,latin1
set nocompatible
set backspace=indent,eol,start
set autoindent copyindent
set mouse-=a
filetype on
set fileformat=unix
autocmd BufNewFile * setlocal fileformat=unix
set fileformats=unix,dos,mac
set noeb belloff=all t_vb=
" 在编程过程中,在右下角显示光标位置的状态行
set ruler
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
" 插入模式:不闪烁方块 (█)
let &t_SI = "\<Esc>[2 q"
" 普通模式:不闪烁方块 (█)
let &t_EI = "\<Esc>[2 q"

vscode的settings.json配置:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
    "workbench.startupEditor": "none",
    "workbench.colorTheme": "Visual Studio Light",
    "hediet.vscode-drawio.resizeImages": null,
    "workbench.editorAssociations": {
        "*.drawio.png": "hediet.vscode-drawio"
    },
    "update.showReleaseNotes": false,
    "chat.disableAIFeatures": true
}

4. helix编译

$ git clone https://github.com/helix-editor/helix
$ cd helix
# 可复现的
$ cargo install --path helix-term --locked

helix的runtime目录下有三个子目录:

  • grammars: 存放 Tree-sitter grammars 文件。
  • queries: 存放 helix query 文件
  • themes: 存放 helix themes 文件

自定义runtime目录的位置:

  • 设置 HELIX_RUNTIME 环境变量
  • 如果有多个 runtime 目录,helix会按照如下顺序来检索它们:
    • 当前包的 Cargo.toml文件所在目录的绝对路径($CARGO_MANIFEST_DIR)下的 runtime/ 子目录。
    • helix的config.toml文件所在目录的 runtime/ 子目录。
    • $HELIX_RUNTIME 环境变量的所在位置。
    • 发行版专属后备目录(在编译时——而非运行时——通过 HELIX_DEFAULT_RUNTIME 环境变量设置)
    • hx.exe可执行文件所在目录的 runtime/ 子目录。

附录A hx语言服务器支持的主流语言

c/c++

NOTE: Clang >= 9 is recommended!

clangd relies on a JSON compilation database specified as compile_commands.json or, for simpler projects, a compile_flags.txt.

For details on how to automatically generate one using CMake look here. Alternatively, you can use Bear.

rust

rustup component add rust-analyzer

Add the following to your languages.toml to enable clippy on save:

[language-server.rust-analyzer.config.check]
command = "clippy"

You may also wish to enable all features, as it will allow you to use rust-analyzer in integration-test for example.

[language-server.rust-analyzer.config.cargo]
features = "all"

See docs for extra settings.

Everything under the rust-analyzer key goes under language-server.rust-analyzer.config key in helix (for example, rust-analyzer.check.command = "clippy" is translated into the language.toml as above.)

golang

go install golang.org/x/tools/gopls@latest                               # LSP
go install github.com/go-delve/delve/cmd/dlv@latest                      # Debugger
go install golang.org/x/tools/cmd/goimports@latest                       # Formatter
go install github.com/nametake/golangci-lint-langserver@latest           # Linter
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest # Linter cli

The LSP formatter (gofmt) does not fix imports, goimports should be used instead.

languages.toml:

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

python

ruff安装命令: uv tool install ruff

ty安装命令: uv tool install ty

Ruff ships with a builtin LSP, see ruff docs for integration with helix.

[[language]]
name = "python"
language-servers = [ "ty", "ruff" ]
auto-format = true
[language-server.ty]
command = "ty"
args = ["server"]
[language-server.ruff]
command = "ruff"
args = ["server"]

typescript

npm install -g typescript typescript-language-server

To configure type language server, add a tsconfig.json or jsconfig.json to the root of your project.

Here’s an example that disables type checking in JavaScript files.

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "checkJs": false
    },
    "exclude": ["node_modules"]
}

html和scss和json: npm i -g vscode-langservers-extracted

代码format和lint的工具:

  • Biome:
    • 安装: npm install --save-dev --save-exact @biomejs/biome
    • helix languages.toml配置: https://biomejs.dev/guides/editors/third-party-extensions/#helix
      [language-server]
      biome = { command = "biome", args = ["lsp-proxy"] }
      
      [[language]]
      name = "javascript"
      language-servers = [ { name = "typescript-language-server", except-features = [ "format" ] }, "biome" ]
      auto-format = true
      
      [[language]]
      name = "typescript"
      language-servers = [ { name = "typescript-language-server", except-features = [ "format" ] }, "biome" ]
      auto-format = true
      
      [[language]]
      name = "tsx"
      auto-format = true
      language-servers = [ { name = "typescript-language-server", except-features = [ "format" ] }, "biome" ]
      
      [[language]]
      name = "jsx"
      auto-format = true
      language-servers = [ { name = "typescript-language-server", except-features = [ "format" ] }, "biome" ]
      
      [[language]]
      name = "json"
      language-servers = [ { name = "vscode-json-language-server", except-features = [ "format" ] }, "biome" ]
      
  • ESLint:
    • 安装:npm i -g vscode-langservers-extracted
    • helix languages.toml配置:
      [[language]]
      name = "javascript"
      language-servers = [
        "typescript-language-server", # optional
        "vscode-eslint-language-server",
      ]
      [[language]]
      name = "jsx"
      language-servers = [
        "typescript-language-server",
        "vscode-eslint-language-server",
      ]
      
      [[language]]
      name = "typescript"
      language-servers = [
        "typescript-language-server",
        "vscode-eslint-language-server",
      ]
      [[language]]
      name = "tsx"
      language-servers = [
        "typescript-language-server",
        "vscode-eslint-language-server",
      ]
      
    • 给当前JS/TS项目配置eslint: https://eslint.org/docs/latest/use/getting-started

Typst排版系统

typesetting system: 排版系统

cargo install --git https://github.com/Myriad-Dreamin/tinymist --locked tinymist-cli

[language-server.tinymist]
command = "tinymist"

[[language]]
name = "typst"
language-servers = ["tinymist"]

Typst的包管理:使用自有的包仓库,语法内置。

markdown

去掉反引号自动匹对功能:

[[language]]
name = "markdown"
[language.auto-pairs]
'(' = ')'
'{' = '}'
'[' = ']'
'"' = '"'
'<' = '>'

附录B hx支持的所有配置

config.toml支持的配置:

  • scrolloff
  • scroll-lines
  • mouse
  • shell
  • line-number
  • cursorline
  • cursorcolumn
  • gutters
  • middle-click-paste
  • auto-pairs
  • auto-completion
  • path-completion
  • auto-format
  • default-yank-register
  • auto-save
    • Helix Editor通过自动保存功能来解决意外退出导致的数据丢失问题,而不是像Vim那样生成.swp文件。
  • text-width
  • idle-timeout
  • completion-timeout
  • preview-completion-insert
  • completion-trigger-len
  • completion-replace
  • continue-comments
  • auto-info
  • file-picker
  • statusline
  • cursor-shape
  • true-color
  • undercurl
  • search
  • lsp
  • terminal
  • rulers
  • whitespace
  • bufferline
  • indent-guides
  • color-modes
  • soft-wrap
  • workspace-lsp-roots
  • default-line-ending
  • insert-final-newline
  • atomic-save
  • trim-final-newlines
  • trim-trailing-whitespace
  • smart-tab
  • popup-border
  • indent-heuristic
  • jump-label-alphabet
  • inline-diagnostics
  • end-of-line-diagnostics
  • clipboard-provider
  • editor-config

专题:

本文发表于 2025-11-18,最后修改于 2025-11-18。

本站永久域名「 jiavvc.top 」,也可搜索「 极客油画 」找到我。


上一篇 « markdown-typst 下一篇 » alacritty-tmux

赞赏支持

请我吃鸡腿 =^_^=

i ysf

云闪付

i wechat

微信

推荐阅读

Big Image