Skip to content

Allow ESC to be binded to custom action, when not in tab complete, at least when nothing being inputed #990

Description

@guyuming76

I am using reedline in my rfm file manager, to let user manipulate files shown in GUI with commands in terminal emulator. But i cannot keybind ESC to my custom code, it's said that ESC is used by reedline. I see that when i use tab completion and menu, ESC can cancel the menu. But at least when i start a new readline call and nothing has being inputted, i see nothing happens with ESC. I just need ESC for my custom action here: I want to use ESC to cancel the file selection in file manager GUI. Without this, i have to switch focus to the GUI window, ESC to cancel file selection and switch focus back. Currently, i am using ALT+E keybinding as an alternative, but it's not easy to remember as ESC.

Activity

  1. fdncred commented on Dec 28, 2025

    @fdncred
    Contributor

    It seems to work in nushell. I've had this set as a keybinding for a very long time. ESC clears the command line buffer.

      {
        name: clear
        modifier: none
        keycode: esc
        mode: [emacs vi_normal vi_insert]
        event: { edit: clear }
      }
  2. guyuming76 commented on Jan 3, 2026

    @guyuming76
    Author

    i use something like what follows, ESC key works with my custom host command. But, when i use tab complete, and after the menu show up, i cannot use ESC key to cancel the completion menu. I don't want my ESC keybinding to override its default behavior in completion menu.

    ...
        keybindings.add_binding(KeyModifiers::NONE, KeyCode::Esc,                                                             
            ReedlineEvent::ExecuteHostCommand("esc".to_string())); 
    ...
        let engine = match history_result {                                                                                   
            Ok(history) => Reedline::create().use_bracketed_paste(true)                                                       
                .with_completer(Box::new(CombinedCompleter::new(CCompleter::new(rfm_functions, None)))) 
    				       .with_menu(ReedlineMenu::EngineCompleter(completion_menu))                        
                                            .with_history(Box::new(history))                                                  
                                            .with_validator(Box::new(AlwaysIncompleteValidator))   
                                            .with_edit_mode(Box::new(Emacs::new(keybindings)))            
                                            .with_quick_completions(true) 
                                            .with_hinter(Box::new(CwdAwareHinter::default().with_style(Style::new().italic().\
    fg(Color::LightGray)).with_min_chars(2))),                                                                                
            Err(e) => {                                                                                                       
                warn!("History load error: {}", e);                                                                           
                Reedline::create().with_completer(Box::new(CombinedCompleter::new(CCompleter::new(rfm_functions, None)))) 
                                            .with_menu(ReedlineMenu::EngineCompleter(completion_menu))                        
                                            .with_validator(Box::new(AlwaysIncompleteValidator)) 
                                            .with_edit_mode(Box::new(Emacs::new(keybindings)))  
                                            .with_quick_completions(true) 
            }                                                                                                                 
        };           
    
    
  3. guyuming76 commented on Jan 12, 2026

    @guyuming76
    Author

    i solved this issue by customize nushell/reedline:

    guyuming76@68ef690

    https://gitee.com/guyuming76/reedline/commit/68ef690146fc680cf2294ec2a9249a34dddcf805

    I need to customize because i use UntilFound as follows, but code in engine.rs always return "handled", and my code never get executed.

    keybindings.add_binding(KeyModifiers::NONE, KeyCode::Esc,
            ReedlineEvent::UntilFound(vec![ReedlineEvent::Esc, ReedlineEvent::ExecuteHostCommand("esc".to_string())]));
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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions