lazygit
lazygit copied to clipboard
Use editor defined in `EDITOR` environment variable instead of `vim`
Some versions ago editor from EDITOR environment variable was used. But this were broken in latest versions (#2576). Currently it seems that editor should be already known (editor_presets.go) or defined in config.yml.
Better to use editor in EDITOR environment variable with default preset:
func standardTerminalEditorPreset(editor string) *editPreset {
return &editPreset{
editTemplate: editor + " -- {{filename}}",
editAtLineTemplate: editor + " +{{line}} -- {{filename}}",
editAtLineAndWaitTemplate: editor + " +{{line}} -- {{filename}}",
editInTerminal: true,
}
}
For example, EDITOR=mcedit works great with standard terminal editor preset, including line numbers.
This would only work if the editor supports the +123 syntax for jumping to a line. Not all editors do; some need a different syntax for specifying the line. Also, lazygit would have no way of knowing whether the editor is console based, i.e. whether it needs to suspend itself to the background before calling the editor.
In short, there was a reason why we changed the behavior. If you use an editor for which lazygit doesn't have a built-in preset, consider contributing one.
If I press "e" in files pane, then line number is not passed to editor and it is safe to launch with standard template. Yes, I can add "mcedit", I just not sure if we can (should) add all known editors to source code, previously with EDITOR it was not needed. For now I've added editor to config.yml, but seems that need to do it for every user (#2623).
That's true, we could use ${EDITOR} for launching the editor in the files panel. We decided not to, as it would be even more confusing if a different editor is launched depending on whether you are in the files panel or in the staging panel. I'm pretty sure people would report that as a bug too.
Removing support for $EDITOR is sad news. I found the docs on how to change the editor, but fail embarrassingly…
I expect lazygit to use helix but no matter what it uses nvim:
# ~/.config/lazygit/config.yml
os:
editPreset: 'helix'
% env | rg '(EDITOR|VISUAL)'
EDITOR=hx
VISUAL=hx
% git config --global core.editor
% git config core.editor
@brutus You shouldn't need any configuration in lazygit for this to work correctly. Support for auto-detection of helix was added in v0.39.0, and it does work for me. Which lazygit version are you using?
Hi @stefanhaller , thanks for your fast response. I tried it on a Fedora box, running 0.38.2, so it should be resolved soonish :smiley: :+1:
I just tested it on Arch running 0.40.2 too. Here helix detection seems to almost work, but I get
bash: line 1: hx: command not found
With no lazygit config file, no git settings for core.editor and EDITOR and VISUAL set to helix (not hx).
I get the same error, when I create ~/.config/lazygit/config.yml as above. I thought detection might get derailed by my hx fish shell abbr, but I still get the same results, when I remove it.
I just glimpsed over the editor presets (not fluent in Golang), but it seems to be the other way around: it's always assumed, that the binary is called hx? Not sure about most distros, but while it is called hx on Fedora, that is not the case in Arch (and probalby other distros, b/c of hex IIRC).
If I create a symlink from helix to hx it works - no config needed.
So yeah: works for me I guess. But maybe the auto detection could use some tweaking? Or am I still missing something?
@brutus I wasn't aware that the helix binary is not always called hx. Here's a PR that should improve the situation: #3346, are you able to build from source and test it?
@brutus I wasn't aware that the helix binary is not always called
hx. Here's a PR that should improve the situation: #3346, are you able to build from source and test it?
Yes, your PR works. No config needed . :tada: Thanks!