Change navigation bindings in vim mode


#1

I use the Dvorak Keyboard Layout and would like to change vim default navigation bindings (hjkl). It doesn’t really work with standard vim.map in the init file, because when I remap this way vim.map('h', '<Down>'), <Left> (the Left Arrow) gets also remapped to <Down>.

I think it’s because of https://github.com/c9/c9.ide.ace.keymaps/blob/e8d5eedc3761e2258eb795e81a74eeb050704c8b/vim/keymap.js#L64

exports.treeKeyboardHandler = new HashHandler();
exports.treeKeyboardHandler.bindKeys({
    "k": "goUp",
    "j": "goDown",
    "h": "levelUp",
    "l": "levelDown"
});

Is it possible to change treeKeyboardHandler.bindKeys in my init file?


#2

I’ve figured it it out. It’s not because of the treeKeyboardHandler. The treeKeyboardHandler is just a handler for the directory tree, obviously. The problem is in the way the remapping in C9 works. It’s not possible to remap some default keys, only assign additional key to the same command, for instance motion.

I’ve figured out a work around in the init file, but vim.map should be improved.

Here is a dirty workaround if somebody needs it:

require(['plugins/c9.ide.ace.keymaps/vim/keymap'], function(vim) {
    var handler = require('ace/keyboard/vim').handler;
    var newDefaultKeymap = [
        {'lhs': 'd', 'rhs': 'h'},
        {'lhs': 'h', 'rhs': 'j'},
        {'lhs': 't', 'rhs': 'k'},
        {'lhs': 'n', 'rhs': 'l'},
 
        {'lhs': 'l', 'rhs': 't'},
        {'lhs': 'L', 'rhs': 'T'},
        {'lhs': 'k', 'rhs': 'n'},
        {'lhs': 'K', 'rhs': 'N'},
        {'lhs': 'j', 'rhs': 'd'},
    ];

    for (let key of handler.defaultKeymap) {
        // two loops are used because of break (for more readability)
        // consider to pack to one loop
        for (let keymap of newDefaultKeymap) {
            if (key.keys == keymap.rhs) {
                key.keys = keymap.lhs;
                break;
            }
        }
        for (let keymap of newDefaultKeymap) {
            if (key.toKeys == keymap.rhs) {
                key.toKeys = keymap.lhs;
                break;
            }
        }
    }
    
    vim.map('qq', '<Esc>', 'insert');
    
    vim.treeKeyboardHandler.bindKeys({
        't': 'goUp',
        'h': 'goDown',
        'd': 'levelUp',
        'n': 'levelDown'
    });
});

#3

what command do you use in vim to remap keys in this way?


#4

There is a command :noremap in vim.

:noremap d h

http://vimdoc.sourceforge.net/htmldoc/map.html#:noremap