0

In my shell I can move around in a long command line by jumping to the previous or next word delimiter by typing Esc- and Esc-, using Esc as a prefix to replace the Alt key. The key bindings are likely the following:

$ bindkey | grep -a -- -word
(...)
"^[^[[D"       -> backward-word
"^[^[[C"       -> forward-word
(...)

However, when I press the Alt+ key combination the special code is not recognised and two letters "3D" printed:

$echo longcommand longcommand longcommand longcommand
(pressing at the end of the line at this point)
$echo longcommand longcommand longcommand longcommand3D

Alt+ will give "3C".

xev shows the same KeyPress event for key the with and without Alt (using left Alt here).

How can I get the Alt variants to work when the Esc prefix variants already work?

This happens in xfce4-terminal, in xterm the key combination works.

1 Answer 1

1

xfce4-terminal uses the vte library for all of the relevant features. In this case, that would be the meta feature in xterm (see altIsNotMeta and altSendsEscape, as well as metaSendsEscape). vte doesn't implement that. If it did, it (to imitate xterm properly) it should also recognize an escape sequence for switching meta mode off/on. It doesn't do that, either.

Since VTE is undocumented, you have to read its source-code to gain an understanding of its features.

Checking my reading of the source-code with xfce4-terminal 0.8.9.2 and vte 0.62.1, the latter partially implements this sequence (private mode 1036), in vte.cc:

 Ps = 1 0 3 6  ⇒  Send ESC   when Meta modifies a key, xterm.
      This enables the metaSendsEscape resource.

but it omits the treatment of special keys (which your question is about). A comment before that block says

/* If we got normal characters, send them to the child. */

The special keys use the modifiers as derived in widget.cc:

    /* Read the modifiers. See bug #663779 for more information on why we do this. */
    auto mods = GdkModifierType{};
    if (!gdk_event_get_state(event, &mods))
            return 0;

    #if 1
    /* HACK! Treat META as ALT; see bug #663779. */
    if (mods & GDK_META_MASK)
            mods = GdkModifierType(mods | GDK_MOD1_MASK);
    #endif

Bug report #663779 goes into some detail about the way the vte developers hard-coded part of xterm's behavior in this area . The part that they're talking about is for special keys (such as Alt+arrow, combined with alt or meta). That appears to be this chunk, in vte.cc:

        _vte_keymap_map(keyval, m_modifiers,
                                    m_modes_private.DEC_APPLICATION_CURSOR_KEYS(),
                                    m_modes_private.DEC_APPLICATION_KEYPAD(),
                &normal,
                &normal_length);
        /* If we found something this way, suppress
         * escape-on-alt. */
                    if (normal != NULL && normal_length > 0) {
            suppress_alt_esc = TRUE;
        }
1
  • Wow, thanks a lot, that's pretty detailed, will need to put in some work to understand that all. TL;DR: It won't work unless source code is changed? (No config options?!) Commented Nov 19, 2020 at 18:34

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.