gitui icon indicating copy to clipboard operation
gitui copied to clipboard

Open editor in the same line of the diff pane

Open davxy opened this issue 3 years ago • 4 comments

During diff inspection, it would be nice to open the editor to the same line number as it is within the diff pane. This feature would allow to quickly make changes to the file under inspection.

It would be also very useful to print numbers at the begin of the lines in the diff pane.

Thanks for your awesome work.

davxy avatar Apr 22 '22 10:04 davxy

that has two challenges:

  1. we open any editor configured via environment variables
  2. we could probably pass on some variable that works with vi but what happens if someone has other editors convigured?

extrawurst avatar Apr 23 '22 12:04 extrawurst

We could check the $EDITOR or $GIT_EDITOR for a handful of most common editors and support that? E.g. vim, nvim, vi, nano, emacs, subl, vscode, they all support something like <editor> +<line> <file>.

If it's not one of those, we could read a config entry in the form of <editor> <args> <file> and let the user provide their own?

mark2185 avatar Apr 23 '22 13:04 mark2185

IMO it would be a reasonable compromise to have this feature for all editors supporting the +line arg. I assume that with the editors just enumerated you already covered a huge part of gitui users (maybe all :-) )

davxy avatar Apr 23 '22 13:04 davxy

I have found myself wishing for this feature fairly often since it's great to be able to live inside gitui!

The most satisfying and flexible way I've seen this problem being solved is the token-based approach in qutebrowser for defining an editor command via config:

https://www.qutebrowser.org/doc/help/settings.html#editor.command

... The following placeholders are defined:

{file}: Filename of the file to be edited. {line}: Line in which the caret is found in the text. {column}: Column in which the caret is found in the text. {line0}: Same as {line}, but starting from index 0. {column0}: Same as {column}, but starting from index 0. ...

This method allows for configuration that would work with almost any editor. We also probably wouldn't need column or column0 here.

There could still be default configuration similar to the current functionality, but with the ability to override beyond just setting an environment variable. The +line could even be part of the default configuration, like:

editor_command: "$EDITOR +{line} {file}"

The big caveat of this idea/suggestion being that from what I know gitui doesn't currently have anything like a config.ron, but we do have config files for themes and keybinds.

star-szr avatar May 26 '22 18:05 star-szr

This issue has been automatically marked as stale because it has not had any activity half a year. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 21 '22 01:12 stale[bot]

not stale? 🤞😃

davxy avatar Jan 05 '23 11:01 davxy

Any update on this? I just started using this amazing software (good job with this project BTW! :D) but this part is quite frankly really annoying, when working with decently sized files this problem causes quite a lot of wasted time having to scroll to the line you were on when you pressed "e" to edit the file while on gitui, is there any chance this might get implemented using one of the suggested possible solutions (or something else) in the future?

creeloper27 avatar Mar 16 '23 16:03 creeloper27