u/After-Tumbleweed1107

Helix keybinding: copy file location + selected code for coding agents

I have been using a small Helix keybinding that has turned out to be very useful when working with coding agents.

The idea is simple: select some code, press a key, and copy both:

  • the current file location, including line range
  • the selected text, wrapped in a Markdown code fence

This makes it easy to paste precise context into ChatGPT, Codex, Claude, GitHub issues, or review comments.

For example, selecting a few lines and pressing Space l copies something like this:

src/main.rs:L42-L44
```
fn main() {
    println!("hello");
}
```

Space L does the same thing, but expands the file path to an absolute path.

Requirements

This depends on current Helix preview/master because it uses :set-register.

The keybinding also uses Helix expansion variables such as %{buffer_name}, %{selection_line_start}, %{selection_line_end}, and %{selection}.

I use Nushell as the editor shell so the small script can stay reasonably cross-platform:

[editor]
shell = ["nu", "-c"]

Configuration

[editor]
shell = ["nu", "-c"]

[keys.normal]

# Copy the current primary selection together with its relative file location.
space.l = [
  "extend_to_line_bounds",
  ''':set-register l %sh{
  let file = "%{buffer_name}"
  let start = ("%{selection_line_start}" | into int)
  let end = ("%{selection_line_end}" | into int)
  let first_line = ([$start, $end] | math min)
  let last_line = ([$start, $end] | math max)

  if $first_line == $last_line {
    print -n $"($file):L($first_line)"
  } else {
    print -n $"($file):L($first_line)-L($last_line)"
  }
}''',
  ''':set-register + %reg{l}
```
%{selection}```''',
  ":clear-register l",
]

# Same as Space-l, but expand the file location to an absolute path.
space.L = [
  "extend_to_line_bounds",
  ''':set-register l %sh{
  let file = ("%{buffer_name}" | path expand)
  let start = ("%{selection_line_start}" | into int)
  let end = ("%{selection_line_end}" | into int)
  let first_line = ([$start, $end] | math min)
  let last_line = ([$start, $end] | math max)

  if $first_line == $last_line {
    print -n $"($file):L($first_line)"
  } else {
    print -n $"($file):L($first_line)-L($last_line)"
  }
}''',
  ''':set-register + %reg{l}
```
%{selection}```''',
  ":clear-register l",
]

Notes

extend_to_line_bounds is intentional here. When I send code to an agent, I usually want complete lines rather than a partial character selection.

The temporary l register is only used to build the location string. The final result is written to the system clipboard register +, then the temporary register is cleared.

The relative-path version is better for repository-local discussion. The absolute-path version is useful when the receiving tool has access to the same local filesystem and can open the exact file directly.

reddit.com
u/After-Tumbleweed1107 — 19 hours ago

Two small Helix Steel plugins: file auto-reload and fcitx5 focus handling

Hi, I've been experimenting with Helix's Steel plugin system and wanted to share two small plugins I've been using locally.

Both currently require a Helix build from the open Steel plugin-system PR: https://github.com/helix-editor/helix/pull/8675

1. helix-file-watcher

Repo: https://github.com/mtul0729/helix-file-watcher

This is my heavily modified fork of the original helix-file-watcher plugin: https://github.com/mattwparas/helix-file-watcher

I forked it because the original plugin no longer worked for me with the current Steel/Helix setup, and upstream seems to have limited maintenance bandwidth at the moment.

It watches files opened in Helix and reloads them after external changes.

It is useful when files are modified by formatters, generators, Git operations, external tools, or another editor, and you want Helix to pick up those changes automatically.

Basic usage:

(require "helix-file-watcher/file-watcher.scm")

;; default reload delay: 2000 ms
(spawn-watcher)

;; custom delay
(spawn-watcher 1000)

Install with Forge:

forge pkg install --git https://github.com/mtul0729/helix-file-watcher.git

2. helix-fcitx-focus

Repo: https://github.com/mtul0729/helix-fcitx-focus

This plugin is for fcitx5 users, especially CJK input workflows.

It keeps fcitx5 inactive / English outside insert mode, then restores the previous input method when entering insert mode again. This makes normal-mode commands stay ASCII while still letting insert mode resume the input method you were using.

Behavior summary:

  • Leaving insert mode saves the current fcitx5 state and switches to inactive / English.
  • Entering insert mode restores the saved input method if there was one.
  • Focusing Helix in normal/select mode closes fcitx5.
  • Focusing Helix while still in insert mode restores the saved input method.
  • When Helix loses focus, it can restore the input method state from the previous application.
  • SSH and non-graphical sessions are ignored.

Install with Forge:

forge pkg install --git https://github.com/mtul0729/helix-fcitx-focus

Then load it from ~/.config/helix/init.scm:

(require "helix-fcitx-focus/cogs/fcitx-focus.scm")

The repo also includes a Nix flake package and Home Manager module for declarative setup.

Notes

These are still early plugins and depend on Helix's Steel plugin work, so they are probably most useful for people already trying that PR.

Feedback, bug reports, and suggestions are welcome.

u/After-Tumbleweed1107 — 19 hours ago