Implement 'set relativenumber' in IDE vi mode


#1

Can we have set relativenumber in addition to set number please? Very useful when you need to quickly jump to a line using [count]k or [count]j.


#2

This can be done using the following init script

var renderRelativeNumbers = {
    getText: function(session, row) {
        return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9 ? "\xb7" : ""))) + "";
    },
    getWidth: function(session, lastLineNumber, config) {
        return session.getLength().toString().length * config.characterWidth;
    },
    update: function(e, editor) {
        editor.renderer.$loop.schedule(editor.renderer.CHANGE_GUTTER);
    },
    attach: function(editor) {
        var old = editor.renderer.$gutterLayer.$renderer;
        if (old == this) return;
        if (old) old.detach(editor);
        editor.renderer.$gutterLayer.$renderer = this;
        editor.on("changeSelection", this.update);
    },
    detach: function(editor) {
        editor.off("changeSelection", this.update);
        editor.renderer.$gutterLayer.$renderer = null;
    }
};
services.tabManager.once("ready", function() {
    services.tabManager.getTabs().forEach(function(tab) {
        var ace = tab.path && tab.editor.ace;
        if (ace) {
            renderRelativeNumbers.attach(tab.editor.ace);
        }
    });
    var attach = renderRelativeNumbers.attach.bind(renderRelativeNumbers);
    services.ace.on("create", function(e) {
        e.editor.on("createAce", attach, plugin);
    }, plugin);
    plugin.addOther(function() {
        services.tabManager.getTabs().forEach(function(tab) {
            var ace = tab.path && tab.editor.ace;
            if (ace) {
                renderRelativeNumbers.detach(tab.editor.ace);
            }
        });
    });
});

please try it and let us know if it needs some reworking before becoming a setting in the ide.