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

ctrl+left/right doesn't work correctly in vim #193

Closed
Tyriar opened this issue Jul 19, 2016 · 4 comments
Closed

ctrl+left/right doesn't work correctly in vim #193

Tyriar opened this issue Jul 19, 2016 · 4 comments
Labels
type/bug Something is misbehaving

Comments

@Tyriar
Copy link
Member

Tyriar commented Jul 19, 2016

ctrl+left doesn't jump over words and ctrl+right erases everything to the right of the cursor

Details

  • Browser and browser version: Chrome 51
  • OS version: Ubuntu 16.04
  • xterm.js version: dc17f0d

Steps to reproduce

  1. Type the following:

    vim
    i
    abc
    

    image

  2. ctrl+left
    image

  3. ctrl+right
    image

@jerch
Copy link
Member

jerch commented Jul 19, 2016

xterm uses a bitmap to handle shift, alt and ctrl status. See here.
The bit settings are directly usable for the triggered escape code, though it gets tricky for different emulation models.

NOTE: There is no meta anymore nowadays, which makes it somewhat hard to adopt.

The closest I was able to get for vt1xx emulation was the following:
var modifiers = evt.shiftKey << 0 | evt.altKey << 1 | evt.ctrlKey << 2 | evt.metaKey << 3;

and feeding the modifiers state back into this key function:

var KEYS = {
            'page up'   : ['\u001b[5~',  ['\u001b[5;', '~']],
            'page down' : ['\u001b[6~',  ['\u001b[6;', '~']],
            'end'       : ['',           ['\u001b[1;', 'F']],
            'home'      : ['',           ['\u001b[1;', 'H']],
            'left'      : ['',           ['\u001b[1;', 'D']],
            'up'        : ['',           ['\u001b[1;', 'A']],
            'right'     : ['',           ['\u001b[1;', 'C']],
            'down'      : ['',           ['\u001b[1;', 'B']],
            'insert'    : ['\u001b[2~',  ['\u001b[2;', '~']],
            'delete'    : ['\u001b[3~',  ['\u001b[3;', '~']],
            'F1'        : ['\u001bOP',   ['\u001b[1;', 'P']],
            'F2'        : ['\u001bOQ',   ['\u001b[1;', 'Q']],
            'F3'        : ['\u001bOR',   ['\u001b[1;', 'R']],
            'F4'        : ['\u001bOS',   ['\u001b[1;', 'S']],
            'F5'        : ['\u001b[15~', ['\u001b[15;', '~']],
            'F6'        : ['\u001b[17~', ['\u001b[17;', '~']],
            'F7'        : ['\u001b[18~', ['\u001b[18;', '~']],
            'F8'        : ['\u001b[19~', ['\u001b[19;', '~']],
            'F9'        : ['\u001b[20~', ['\u001b[20;', '~']],
            'F10'       : ['\u001b[21~', ['\u001b[21;', '~']],
            'F11'       : ['\u001b[23~', ['\u001b[23;', '~']],
            'F12'       : ['\u001b[24~', ['\u001b[24;', '~']]
        };

        function key(identifier, modifiers, normal, modified) {
            if (!normal)
                normal = KEYS[identifier][0];
            if (!modified)
                modified = KEYS[identifier][1];
            return (modifiers) ? modified.join(modifiers + 1) : normal;
}

@parisk parisk added the type/bug Something is misbehaving label Jul 20, 2016
@parisk
Copy link
Contributor

parisk commented Jul 20, 2016

Unfortunately I won't have access to a Linux machine until tomorrow to try this out and Ctrl + / won't work here as they are used by host.

It would help if you could provide us with the code sent by xterm.js when hitting Ctrl + in plain bash, compared with the code in Vim (which should have applicationKeypad set to true).

@jerch
Copy link
Member

jerch commented Jul 20, 2016

The modifier state will be added to the escape sequence as the second parameter (right before the final character) like this:
--> CSI D (normal mode with bash) or SS3 D (application mode with vim)
Ctrl+--> CSI 1;5 D
Shift+--> CSI 1;2 D
There is no normal/application mode distinction with a pressed modifier key, they are all sent with CSI. The '1' is there to indicate the other number as second parameter. No clue if it has any other meaning.
Btw the modifier keys are respected for all the keys listed above by xterm.

Modifier states

  Code     Modifiers
---------+---------------------------
   2     | Shift
   3     | Alt
   4     | Shift + Alt
   5     | Control
   6     | Shift + Control
   7     | Alt + Control
   8     | Shift + Alt + Control
   9     | Meta
   10    | Meta + Shift
   11    | Meta + Alt
   12    | Meta + Alt + Shift
   13    | Meta + Ctrl
   14    | Meta + Ctrl + Shift
   15    | Meta + Ctrl + Alt
   16    | Meta + Ctrl + Alt + Shift
---------+---------------------------

When I get my hand on a linux machine I can create you a complete list of the sequences.

@jerch
Copy link
Member

jerch commented Jul 20, 2016

These are the arrow key sequences (xterm treats home and end as arrow keys):

// normal mode
ARROWS = {
    'left': '\x1b[D',
    'right': '\x1b[C',
    'up': '\x1b[A',
    'down': '\x1b[B',
    'home': '\x1b[H',
    'end': '\x1b[F',
    'page up': '\x1b[5~',
    'page down': '\x1b[6~'
}
// application mode
ARROWS_CKM = {
    'left': '\x1bOD',
    'right': '\x1bOC',
    'up': '\x1bOA',
    'down': '\x1bOB',
    'home': '\x1bOH',
    'end': '\x1bOF',
    'page up': '\x1b[5~',
    'page down': '\x1b[6~'
}

// replace %s with the modifier state
ARROWS_MOD = {
    'left': '\x1b[1;%sD',
    'right': '\x1b[1;%sC',
    'up': '\x1b[1;%sA',
    'down': '\x1b[1;%sB',
    'home': '\x1b[1;%sH',
    'end': '\x1b[1;%sF',
    'page up': '\x1b[5;%s~',
    'page down': '\x1b[6;%s~'
}

(copied from a python testscript)

Note: Not all combinations are supported by some keyboards (e.g. my laptop keyboard cant use shift+page up while ctrl and alt works).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is misbehaving
Projects
None yet
Development

No branches or pull requests

3 participants