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

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

Closed
goyalyashpal opened this issue Jul 23, 2022 · 16 comments
Closed

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

goyalyashpal opened this issue Jul 23, 2022 · 16 comments

Comments

@goyalyashpal
Copy link
Contributor

goyalyashpal commented Jul 23, 2022

Details

  • alt + key or say Alt-<key> in insert mode should perform the
  • ... equivalent of esc > key or say Esc <key> i.e. esc to exit, then key
  • ... if alt + key "does not have an insert-mode mapping."

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 + $
  • > means then i.e. leave the previous key
  • + means keep previous key pressed
  • note: in nvim, it doesn't return to insert mode, and stays in command mode after this action too

Reference:

Question for achieving this via config: #3162 (comment)

Quoting/citations for this behaviour from other editors

Title and Summaries:

alternate rephrasals of the issue:

  • Support Alt key-chords to act like ESC (ref: Neovim/Emacs)
  • Support Alt key-chords to act like Esc
  • Provide "Meta character" support for the two-character sequences starting with ESC like Nvim/emacs
  • alt modifier to function as a modifier to escape edit mode similar to neovim
@the-mikedavis
Copy link
Member

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
Copy link
Member

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
Copy link
Contributor Author

goyalyashpal commented Jul 26, 2022

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 goyalyashpal changed the title alt shift to function as escape similar to neovim alt modifier to function as a modifier to escape edit mode similar to neovim Aug 21, 2022
@goyalyashpal
Copy link
Contributor Author

goyalyashpal commented Aug 21, 2022

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

offtopic Prasies:

  • thanks a lot for making the system clipboard to work out of the box.
  • and also showing the popup completion lists when in command mode, and minor modes
    or i guess it shows up in normal mode too (like in the bottom right corner when i press [ or ])
  • nice to know that the bash's emacs styled shortcuts work in the command mode 😆
none but this issue very few issues remains so far:
  • this above issue
  • Update: soft wrap Support soft wrap #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

@goyalyashpal

This comment was marked as outdated.

@the-mikedavis
Copy link
Member

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

This comment was marked as outdated.

@geometryolife
Copy link

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

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

@goyalyashpal
Copy link
Contributor Author

goyalyashpal commented Nov 27, 2022

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 <key> (escape then key) and M-<key> (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:

@goyalyashpal goyalyashpal changed the title alt modifier to function as a modifier to escape edit mode similar to neovim Provide "Meta character" support for the two-character sequences starting with ESC like Nvim/emacs Dec 6, 2022
@goyalyashpal
Copy link
Contributor Author

The keys in the description can be bound with config:
- @ the-mikedavis #3162 (comment)

# ~/.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
Copy link
Contributor Author

goyalyashpal commented Dec 25, 2022

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.

# ~/.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

@goyalyashpal
Copy link
Contributor Author

goyalyashpal commented Dec 27, 2022

I don't think neovim has this shortcut either?

- @ sudo rm rf bin at #3162 (comment)

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

@goyalyashpal goyalyashpal changed the title Provide "Meta character" support for the two-character sequences starting with ESC like Nvim/emacs Support Alt key-chords to act like ESC (ref: Neovim/Emacs) Dec 27, 2022
@goyalyashpal goyalyashpal closed this as not planned Won't fix, can't repro, duplicate, stale Jan 21, 2023
@goyalyashpal goyalyashpal reopened this Jan 21, 2023
@goyalyashpal
Copy link
Contributor Author

goyalyashpal commented Jan 23, 2023

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 goyalyashpal changed the title Support Alt key-chords to act like ESC (ref: Neovim/Emacs) Support Alt+<key> to act as ESC <key> (ref: Emacs/Neovim/Iterm2) Jan 23, 2023
@goyalyashpal
Copy link
Contributor Author

goyalyashpal commented Jul 23, 2023

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
Copy link
Contributor Author

@pascalkuthe
Copy link
Member

pascalkuthe commented Apr 3, 2024

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

@pascalkuthe pascalkuthe closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2024
@helix-editor helix-editor locked as resolved and limited conversation to collaborators Apr 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants