In [1]:
from IPython.html.widgets import *
from IPython.display import display, display_javascript
h = HTMLWidget(value="""<script>
$.getScript("/static/components/codemirror/keymap/vim.js");
$.getScript("/static/components/codemirror/keymap/emacs.js");
$.getScript("/static/components/codemirror/keymap/sublime.js");
IPython.CodeCell.options_default.cm_config.keyMap = 'vim';
IPython.keyboard_manager.edit_shortcuts.remove_shortcut('Esc');
(function(){
var cells = IPython.notebook.get_cells();
var i;
for(i in cells) {cells[i].cm_config.keyMap='vim';
                 if(i==0)
                     cells[i].code_mirror.setSize(null, 0); 
                 else
                     cells[i].code_mirror.setSize(null, 300); 
                 }
})();
</script>""")
display(h)
def vim_interact(height, fixed_height, HideMySource, keymap):
    h.value = """<script>
    (function(){
IPython.CodeCell.options_default.cm_config.keyMap = "%s";
var cells = IPython.notebook.get_cells();
var i;
for(i in cells) {
                %s
                 cells[i].code_mirror.setSize(null, %s); 
                 cells[i].cm_config.keyMap='%s';
                 }
})();
</script>"""%(keymap,
"if (i==0) cells[i].code_mirror.setSize(null, 0); else" if HideMySource else "", 
height if fixed_height else "'auto'", 
keymap)
    
interact(vim_interact, height=IntSliderWidget(min=10, max=1000, step=20, value=300),
         fixed_height = True,  HideMySource = True, keymap = DropdownWidget(values=['default','emacs','vim','sublime'], value='vim', Description="keymap:")         
         )

In [10]:
# attempt to override the chrome developer console, not finished yet
from IPython.html.widgets import *
from IPython.display import display, display_javascript
h = HTMLWidget(value=r"""
<script type='text/javascript'>//<![CDATA[ 


// based on http://jsfiddle.net/Glutamat/jW7jp/show/
(function(){
var console_callbacks = {
/*input: function() {console.log('input');console.log(arguments)},*/
iopub: {
clear_output: function() {console.log('clear_output');console.log(arguments)},
output: function(o) {console.log(o.content.data)}
},
shell: {
payload: {page: function() {console.log('page');console.log(arguments)}, set_next_input: function() {console.log('set_next_input');console.log(arguments)}  },
reply: function() {/*console.log('reply');console.log(arguments)*/}
}
}
if(!window.webkitURL) __debug=function(){console.log.apply(this,arguments);};
else __debug=function(){};

if (window.webkitURL) {

var ish, _eval, _call = Function.prototype.call        
    Function.prototype.call = function () {       
        if (arguments.length > 0 && this.name === "evaluate") {
                ish = arguments[0];
                _eval = ish.evaluate;                
                Function.prototype.call = _call;                
                ish.evaluate = function (expr) {
                    var newExpr, rawExpr;
                    expr = expr || "";
                    exprx = expr.split("\n") 
                    if(expr.substring(0,6)=="with (" && expr.indexOf("commandLineAPI") > -1 && exprx.length >=3){                        
			    rawExpr = exprx.slice(1,-1).join("\n")			
                            __debug(rawExpr)
			    if(rawExpr != "this"){	
                            if(rawExpr == "help") return  "Type help() for interactive help, or help(object) for help about object."
                IPython.notebook.kernel.execute(rawExpr, console_callbacks, {silent:false, store_history: false})
                return ">>>"
			    newExpr = __BRYTHON__.py2js(rawExpr, "__main__").to_js() 
			    
			    result =  _eval.call(this, newExpr)
			    if(result == None) return;
				      try{
							//if(result.__repr__) return result.__repr__()
							    if(result.value) return result.value                       
					    }
					      catch(e){
					      }
		                  return result
			    }
                    }                    
                    return _eval.apply(this, arguments);
                };           
            return _call.apply(this, arguments);
        }
    };    
} else {
   console.log ("Fortunately this works only with Webkit");
}
})();
//]]>  
</script>
""")
display(h)
In [ ]:
%%javascript
/* Use Ctrl-Enter to execute this cell, automatically clear output */
(function(){
var idx = IPython.notebook.get_selected_index();
if(idx >0)
setTimeout(function(){IPython.notebook.clear_output(idx-1);}, 100);
setTimeout(function(){IPython.notebook.clear_output(idx);}, 100);
$.getScript("/static/components/codemirror/keymap/vim.js");
IPython.CodeCell.options_default.cm_config.keyMap = 'vim';
IPython.keyboard_manager.edit_shortcuts.remove_shortcut('Esc');
setTimeout(function(){
var cells = IPython.notebook.get_cells();
var i;
for(i in cells) {cells[i].cm_config.keyMap='vim';
                 cells[i].code_mirror.setSize(null, 300); 
                 }
}, 100);
setTimeout(function(){IPython.notebook.clear_output(idx);}, 100);
if(idx>0)
setTimeout(function(){IPython.notebook.clear_output(idx-1);}, 100);
})();
In [ ]:
# this will failed to load the output
from IPython.display import Javascript, HTML
display(HTML( """<script>
console.log('start');
$.getScript("/static/components/codemirror/keymap/vim.js");
IPython.CodeCell.options_default.cm_config.keyMap = 'vim';
IPython.keyboard_manager.edit_shortcuts.remove_shortcut('Esc');
(function(){
var cells = IPython.notebook.get_cells();
var i;
for(i in cells) {cells[i].cm_config.keyMap='vim';
                 cells[i].code_mirror.setSize(null, 300); 
                 }
})();
console.log('end');
</script>
"""))