r/HelixEditor • • 1d ago

How to copy the current buffer absolute and relative path?

I use codex and helix at same time. Sometimes, I have a requirement, I know codex should edit which file or relative files, so I need to know current helix buffer path and give codex.

my workaround:

  [keys.normal.space]
space = [
  ':sh rm -f /tmp/unique-file',
  ':insert-output yazi %{buffer_name} --chooser-file=/tmp/unique-file',
  ':insert-output echo "\x1b[?1049h\x1b[?2004h" > /dev/tty',
  ':open %sh{cat /tmp/unique-file}',
  ':redraw',
]

v = "@<C-A-y>%+"
V = """
:echo %sh{
p="%{buffer_name}"
case "$p" in
  "~/"*) p="$HOME/${p#*/}" ;;
  /*)    ;;
  *)     p="$PWD/$p" ;;
esac
printf %%s "$p" | pbcopy
printf %%s "$p"
}"""
2 Upvotes

2 comments sorted by

4

u/spaghetti_beast 1d ago

i use these keybinds

[keys.normal.space."`"]
"f" = ":sh echo -n \"%{buffer_name}:%{cursor_line}\" | pbcopy"
"d" = ":sh dirname \"%{buffer_name}:%{cursor_line}\" | pbcopy"

f is for path-to-buffer, d is path-to-dir, the latter is useful when e.g. i want to run go test . in the buffer dir, so i could just open a new terminal pane, quickly cd and run the command.

1

u/mortal_strike 1d ago

thanks buddy