Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quit with ZZ like in vim #2041

Closed
andreaslillevangbech opened this issue Apr 8, 2022 · 12 comments
Closed

Quit with ZZ like in vim #2041

andreaslillevangbech opened this issue Apr 8, 2022 · 12 comments
Labels
C-enhancement Category: Improvements

Comments

@andreaslillevangbech
Copy link

Describe your feature request

Tried doing a remap with Z = { Z = ":wq" } but it didn't work

@andreaslillevangbech andreaslillevangbech added the C-enhancement Category: Improvements label Apr 8, 2022
@the-mikedavis
Copy link
Member

For me,

# on unix: ~/.config/helix/config.toml

[keys.normal]
Z = { Z = ":wq" }

works when editing a buffer with a name (like hx foo.txt). Is that what your config.toml looks like?

@andreaslillevangbech
Copy link
Author

I'm on a mac. With that config I get

Bad config: data did not match any variant of untagged enum KeyTrie for key keys.normal at line 3 column 1
Press to continue with default config

when trying to open the config with hx

@the-mikedavis
Copy link
Member

Are you using the latest release 22.03? That path ~/.config/helix/config.toml should work on macos.

@andreaslillevangbech
Copy link
Author

I'm on 22.03 installed with homebrew. Using same path as you

@andreaslillevangbech
Copy link
Author

I just compiled the version 22.05-dev and it has the same issue

@the-mikedavis
Copy link
Member

What's the full contents of your config file? Could you paste pbcopy < ~/.config/helix/config.toml to this issue?

@andreaslillevangbech
Copy link
Author

I just noticed a mistake. It works now. Really sorry. Great editor btw

@David-Else
Copy link
Contributor

David-Else commented Apr 9, 2022

It does not work for me on Linux. First press of the Z brings the view menu:
Screenshot from 2022-04-09 08-37-45

and the 2nd Z does nothing. There is a very long wait, and sometimes it exits eventually.

2022-04-09T08:40:00.263 helix_view::document [WARN] LSP formatting failed: request timed out
2022-04-09T08:40:00.263 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"shutdown","params":null,"id":2}
2022-04-09T08:40:00.265 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","id":2,"result":null}
2022-04-09T08:40:00.265 helix_lsp::transport [INFO] <- null
2022-04-09T08:40:00.265 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"exit","params":null}

I tried with Kitty and Gnome Terminal.

@the-mikedavis
Copy link
Member

That appears to be that the LSP formatting request timed out (currently it blocks quit while formatting). I think that same behavior should happen if you use :wq under the same circumstances, see #1639. If you try ZZ on a file like file.txt I think it will work fine.

@David-Else
Copy link
Contributor

You are right, but this behaviour is really bad! I hope it can be fixed soon.

@dead10ck
Copy link
Member

Binding ZZ like this definitely works, I've had and used that binding for as long as I've used helix. This looks like a very similar problem to #1639, i.e. your LSP is taking a long time for some reason, which there's not much we can do, except work around it by adding timeouts. In the meantime, I suggest investigating why your LSP is getting stuck.

@m13253
Copy link

m13253 commented Oct 3, 2022

There is a minor issue with ZZ in Helix: You can't ZZ an empty Helix.

Steps to reproduce:

  1. Use my config:
    [keys.normal]
    Z = { Q = ":quit!", Z = ":x" }
  2. Open an empty Helix:
    $ hx
  3. Type ZZ to quit.

What to expect:
Helix should exit.

What to observe:
Error message: cannot write a buffer without a filename

Workaround
In Vim, a similar keybinding is called ZQ, which triggers :quit!.
You can use ZQ in this situation.

Why ZZ doesn't work in Helix?
There is a difference in Helix's :x command comparing with Vim's.
In Vim:

  • :wq means save and quit, no matter the file has been modified or not.
  • :x (:xit) means if the file has been modified, save and quit, otherwise directly quit.
  • For an empty unnamed buffer, :x works without a filename, while :wq doesn't.

However in Helix:

  • :x is an alias to :wq.
  • Both save and quit, even with no changes or with external changes.
  • For an empty unnamed buffer, both don't work without a filename.

Proposed solutions
Make :x different from :wq.
Besides the benefit of being able to :x an empty unnamed buffer, the original behavior of :x is important when the file is changed from another application: You usually don't want to overwrite that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Improvements
Projects
None yet
Development

No branches or pull requests

5 participants