Skip to content

Open editor in the same line of the diff pane #1206

Closed

Description

@davxy

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.

Activity

  1. extrawurst commented on Apr 23, 2022

    @extrawurst
    Collaborator

    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?
  2. mark2185 commented on Apr 23, 2022

    @mark2185
    Contributor

    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?

  3. davxy commented on Apr 23, 2022

    @davxy
    Author

    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 :-) )

  4. star-szr commented on May 26, 2022

    @star-szr
    Contributor

    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.

  5. stale commented on Dec 21, 2022

    @stale

    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.

  6. davxy commented on Jan 5, 2023

    @davxy
    Author

    not stale? 🤞😃

  7. creeloper27 commented on Mar 16, 2023

    @creeloper27

    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?

  8. rawsp33d commented on Oct 3, 2026

    @rawsp33d

    This is one of the things I miss most from tig. In the diff view of tig, when I hit the edit key it opens my editor to whichever line I was highlighting. Gitui currently only lets you open the file from the stage view, not in the diff view where you actually want to edit the line or hunk you're looking at. If it added an [e]dit key to diff view that used the +lineno syntax it would go a long way.

    Some additional context, tig's config has this setting:

    set editor-line-number		= yes		# Automatically pass line number to editor? Used
    						# for opening file at specific line e.g. from a diff
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions