Skip to content

Add an option so that opening a file from macOS’s "external editor" mechanism does not bring macvim to foreground #1408

Description

@MartyLake

In macOS, I am setting the default editor for source code files to open with macvim be default so that macvim can be the editor when debugging on lldb with lldb --editor. However, whenever a breakpoint is hit, or a frame changed, the focus automatically goes from lldb to macvim. I wish I could keep the focus on lldb instead.

Describe the solution you'd like

Maybe there could be an option called macvim_dont_bring_to_foreground, set to 0 by default, that enables the current behavior (bringing macvim to foreground when a remote command arrives), and can be set to 1 to disable the foreward bringing).

Describe alternatives you've considered

I have considered using vim in the terminal instead, by the server part of +clientserver is disabled.

Additional context
Add any other context or screenshots about the feature request here.

EDIT: lldb don’t use $EDITOR but the host’s external editor instead.

Activity

  1. ychin commented on Jun 19, 2023

    @ychin
    Member

    Right. Let me think about this a little and see if it makes sense to make a PR to upstream Vim instead (so all gvim implementation benefits). Just curious, what do you use lldb --editor with? I haven't used this option much. What kind of command are you invoking MacVim with when you hit a breakpoint?

  2. MartyLake commented on Jun 20, 2023

    @MartyLake
    Author

    Thanks for your swift answer!

    I made a mistake, sorry. When launching an lldb session with --editor, lldb will use the host's "external editor" mechanism.. In my case, a long time ago, I used Finder to change the default editor of interesting source files .h, .c, .mm, .cpp, etc. to open by default with MacVim.

    When lldb hits a breakpoint (b InterestingFunction then run), or any command that lists source code during the debugging session (like changing frame with up or down, lldb will automatically open the file at the correct line.

    I have reworked the original ticket.

    Is there an option, or a script I can run in macvim to dump system calls when this happens?

  3. changed the title [-]Add an option so that `mvim --remote-silent` does not bring macvim to foreground[/-] [+]Add an option so that opening a file from macOS’s "external editor" mechanism does not bring macvim to foreground[/+] on Jun 20, 2023
  4. ychin commented on Jun 20, 2023

    @ychin
    Member

    Is there a reason why you don't want the editor to come to the foreground? Why would you want to edit the file but not have it come to focus? I'm still not understanding what feature in lldb is actually opening MacVim. From what I can tell the --editor flag just configures lldb and tells it how to open a file? I don't think just setting a breakpoint will open a file right? Do you have some command or setting that causes it to open the editor?

    As for how this works, I'm guessing it's just using the open command in macOS (you can type man open in terminal to see how it works). There is a -g command to prevent it from coming to the foreground but this isn't something MacVim has control over, as it's up to the caller how to invoke open, hence me being curious exactly what in lldb is causing it to want to open the editor.

  5. MartyLake commented on Jun 21, 2023

    @MartyLake
    Author

    Is there a reason why you don't want the editor to come to the foreground? Why would you want to edit the file but not have it come to focus? I don't think just setting a breakpoint will open a file right? Do you have some command or setting that causes it to open the editor?

    When debugging using lldb --editor, whenever the editor display source code, for example when encountering a breakpoint, or inspecting another frame, lldb will open at file and line. Which means: if you are stepping a lot in a debugging session, or inspecting frames, focus on lldb is lost to macvim very frequently, opening files of no interest.

    I'm still not understanding what feature in lldb is actually opening MacVim. From what I can tell the --editor flag just configures lldb and tells it how to open a file?

    The flag only tells lldb to open whenever code is displayed, either when stopping because of a breakpoint, or when inspecting another frame.

    As for how this works, I'm guessing it's just using the open command in macOS (you can type man open in terminal to see how it works). There is a -g command to prevent it from coming to the foreground but this isn't something MacVim has control over, as it's up to the caller how to invoke open, hence me being curious exactly what in lldb is causing it to want to open the editor.

    As I try to describe the issue with further details, I realise that it may be intractable from macvim standpoint. lldb should not open each and every file and line it encounters, and a user command should really do that only for interesting places, which means that macvim is probably fine as-is.

  6. ychin commented on Jun 22, 2023

    @ychin
    Member

    Ok I think I might have been misunderstanding what lldb --editor does. Upon testing it myself, you are right, it does open each breakpoint with the editor, which seems… like a iffy feature for the reasons you said haha.

    Upon testing, it does seem like lldb does use the open -g flag to make sure the editor should be opening the file in the background. What happens is that the first time MacVim opens a file, it does open it in the background. The second time it is opened though, it reuses the same opened window (which is fine) but somehow puts MacVim in the foreground. This does seem like a bug to me as MacVim isn't respecting the open -g command properly.

    If you use Xcode for example, you will see that it won't steal focus.

    I can take a look to see how to fix it.

  7. added this to the Release 177 milestone on Jun 22, 2023
  8. modified the milestones: Release 177, Release 178 on Jul 9, 2023
  9. modified the milestones: Release 178, Release 179 on Sep 9, 2023
  10. modified the milestones: Release 179, Release 180 on Dec 18, 2023
  11. modified the milestones: Release 180, Release 181 on Sep 10, 2024
  12. modified the milestones: Release 181, Release 182 on Feb 7, 2025
  13. modified the milestones: Release 182, Release 183 on Oct 25, 2025
  14. modified the milestones: Release 183, Release 184 on Apr 7, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions