helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
33.5k stars 2.48k forks source link

Support `Alt+<key>` to act as `ESC <key>` (ref: Emacs/Neovim/Iterm2) #3162

Closed goyalyashpal closed 6 months ago

goyalyashpal commented 2 years ago

Details

Examples from nvim: from insert mode
enter command mode esc > colon (shift + semicolon) alt + colon
move to start of line esc > 0 alt + 0
move to end of line esc > $ (shift + 4) alt + $

Reference:

Question for achieving this via config: https://github.com/helix-editor/helix/issues/3162#issuecomment-1339666582

Quoting/citations for this behaviour from other editors

Title and Summaries:

alternate rephrasals of the issue:

the-mikedavis commented 2 years ago

I'm not sure we get enough events from crossterm to implement this: alt and shift are both modifiers so I don't think we get a KeyEvent for them being pressed/held in conjunction

sudormrfbin commented 2 years ago

I don't think neovim has this shortcut either? It does have ctrl-[ which works because it gets interpreted as Escape, similar to how ctrl-i gets interpreted as Tab.

goyalyashpal commented 2 years ago

I don't think neovim has this shortcut either

umh, maybe it just uses alt for that.

anyways, the instance is that: inside nvim, say i am in edit mode, then either i do: esc > ⇑; (i.e. :) or i do alt + ⇑; both have same effect of landing me to the command mode

Update: i retried `nvim` today to get a refresher. so: * pressing alt doesn't do anything on its own * rather `alt` acts as a modifier with other key combinations, i.e. `alt` + `key` * what it does when used in insert mode is that it exits edit mode, and performs the action of the `key` * as compared to the normal procedure of `esc` to exit, then to press the corresponding `key` + so, effectively, u can use it with some pretty harmless `key` like `l` or `h` to use it as escape
goyalyashpal commented 2 years ago

i have added my clarifications in the description, sorry for the confusion created earlier.

offtopic Prasies:

none but this issue very few issues remains so far: * this above issue * _**Update:** [soft wrap][#136] #136 is complicated; `reflow` operates on selection only_ ~no option for soft-wrap?? `:reflow` doesn't seem to be working~ * _**Update:** Apparently t'was the msys2-runtime issue. 'ts resolved now._ ~it doesn't launch when using via msys2's bash~ [#136]: https://github.com/helix-editor/helix/discussions/4527
goyalyashpal commented 2 years ago

self hiding as outdated


ping

the-mikedavis commented 2 years ago

Please don't ping :)

The keys in the description can be bound with config:

# ~/.config/helix/config.toml
[keys.insert]
"A-:" = "command_mode"
"A-0" = "goto_line_start"
"A-$" = "goto_line_end"
goyalyashpal commented 2 years ago

self hiding as outdated


Please don't ping :)

umh, sorry, what?

geometryolife commented 2 years ago

This is the keymap I use most to move the cursor position in edit mode.

289B7CD6-2A97-4EF8-8F2D-89753BFEDB43

goyalyashpal commented 1 year ago

Refer/quote: User Input (GNU Emacs Manual) - list/bulleting is mine:

  • You can also type Meta characters using two-character sequences starting with ESC (highlighted link).
  • Thus, you can enter M-a by typing ESC a.
  • You can enter C-M-a (holding down both Ctrl and Alt, then pressing a) by typing ESC C-a.
  • Unlike Meta, ESC is entered as a separate character. You don’t hold down ESC while typing the next character; instead, press ESC and release it, then enter the next character.
  • This feature is useful on certain text terminals where the Meta key does not function reliably.
I found that * the duality behaviour of `ESC` and `Alt` key * or say equivalence of `ESC ` (escape then key) and `M-` (hold alt while key) * i was describing above is actually the norm as quoted below: notice the space vs hyphen: * space means `leave then press`, * hyphen means `hold while pressing` ---- trail: * Emacs wiki πŸ”: [User Input] * <-- while i have been searching for this today for https://github.com/TeamNewPipe/NewPipe/pull/9471
goyalyashpal commented 1 year ago

The keys in the description can be bound with config: - @ the-mikedavis https://github.com/helix-editor/helix/issues/3162#issuecomment-1287805037

# ~/.config/helix/config.toml
[keys.insert]
"A-:" = "command_mode"

is there some way for me to set this "Meta character/modifier" scheme as a substitute for all the two-character sequences starting with ESC, or will I have to add the shortcuts in the configuration for every one of them??

goyalyashpal commented 1 year ago

self hiding as offtopic


Update: 2023.01.12: Reference:

These "3 escapes" refer to:

  1. close [pick dialogs] and prompts i.e. esc
  2. close multicursors i.e. , or keep_primary_selection only
  3. deselect i.e. ; or collapse_selection onto a single cursor/character

Note to self: Defaults are good; don't follow that suggestion, precisely as the navigation (say by wb - word/back) causes selection too. In suggestion, deselection will close multicursors too so, requires two separate habits: esc and ,/; for same 2/3 behaviour


The suggested combining of three _escapes_ into one. ```toml # ~/.config/helix/config.toml [keys.normal] esc = ["collapse_selection", "keep_primary_selection"] ``` hey, i can't understand this, can someone explain it to me? i was watching a [video] about helix, and it says the following. i asked back there, but didn't get any response. What are those three ways? And what does following configuration setting does? > use this esc binding there are three ways to 'escape' in helix, this makes it one way. it's a great keybinding for beginners > \- Helix, by [Luke Pighetti][video] [video]: https://www.youtube.com/watch?v=i_qsYALaFVo&t=3m13s
goyalyashpal commented 1 year ago

I don't think neovim has this shortcut either?

- @ sudo rm rf bin at https://github.com/helix-editor/helix/issues/3162#issuecomment-1195149552

aah yes, found it:

1. Special keys                     *ins-special-keys*

... MORE ...

char        action  ~
-----------------------------------------------------------------------
... MORE ...
                        *i_META* *i_ALT*
        ALT (|META|) may act like <Esc> if the chord is not mapped.
        For example <A-x> acts like <Esc>x if <A-x> does not have an
        insert-mode mapping.
ALT (META) key-chords always work in Nvim
 ...
 Nvim 0.3 mimics the Vim behavior while still fully supporting ALT mappings. See `:help i_ALT`.

trail & links: found via following links from helix's documentation itself πŸ˜† https://github.com/neovim/neovim/blob/4aec442b5af5a1a7c3aa47626fee09452117575e/runtime/doc/insert.txt#L41-L44 * <-- `help :i_ALT` < `nvim` * <-- Neovim FAQ: [`esc`-in-tmux] * <-- Helix Troubleshooting: [hitting-escape] * <-- helix README.MD
goyalyashpal commented 1 year ago

third reference: Iterm2 (again, found from helix documentaion itself)

Ensure that you have mapped the Option key to ESC+ ... - https://github.com/helix-editor/helix/wiki/FAQ#alt--key-combinations-do-not-work-on-macos-iterm2

Q: How do I make the option/alt key act like Meta or send escape codes? A: For most users, Esc+ will be the best choice. - iterm2.com/faq

goyalyashpal commented 1 year ago

hey helix team members! can you please add just this one feature?? i humbly request you to please consider this 😒

this is like the only thing stopping me from using helix - rest everything can be overlooked one time or the other; but this - switching mode - is as fundamentally repeating operation as any manual interaction in helix can get;

easing that operation would make a huuge difference

goyalyashpal commented 1 year ago
pascalkuthe commented 6 months ago

you can map this if you want but we are not going to change the default mapping