Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change the default ESC to exit insert mode in LightTable's Vim?

Tags:

vim

lighttable

I'm posting this question largely to provide the answer I've arrived at (because I found nothing elsewhere online and see no questions asking how to do this), to hopefully save future LightTable vim users a bit of time. But I'd also like to hear about any other solutions people have found to this problem, or vim LightTable problems in general.

I've fallen in love with LightTable, but at least minimal vim support is a must before I even consider an IDE. LightTable has that. Currently, though, you're largely stuck with the default vim options and little ability to alter configuration. I would be very interested in hearing about what the future plans are in this area (you out there Chris?). Exposing a .vimrc in a local config directory, even if highly limited in functionality, would be simply awesome, but I realize its very early yet in development and largely depends on what CodeMirror can provide.

One thing I can't tolerate is having to send my pinky way up and to the left to hit the ESC key to exit insert mode. That is way too slow and requires your left fingers to leave the home row, which is never good. The way I normally handle this in vim is to map ii to exit insert mode in .vimrc. Another alternative that is there by default is to hit CTRL-[. That's better, but to me that's entering emacs chording territory and for some reason my right pinky finger almost always flubs hitting either of the bracket keys.

This is a bit of hack, but it's a tolerable work-around until better vim support comes along in LightTable/CodeMirror. I've only tested it on the latest LightTable (0.4.9), so I'm not sure how applicable it is to earlier versions (which you probably shouldn't be on anyways), or, for that matter, later versions that will come along.

There is a command option called "Vim: toggle vim mode". This turns vim on and off in an editor (or instarepl). You can bind this command to a hot-key combination via the "Settings: Change key bindings/shortcuts" command. This will open up a new tab where you can enter new key bindings on the left. The current key bindings are shown on the right.

I use SHIFT-i, within a context of :editor.keys.normal. (This means I can't use capital "I" directly in the text, but in actual practice with program editing - especially clojure - this almost never causes a problem, and if it does you can just use lower-case i and then back up and do a replace char.) This effectively makes "II" (SHIFT-i SHIFT-i) the means of exiting insert mode. The first SHIFT-i exits vim and puts you in the normal, WYSIWYG editor. The next SHIFT-i puts you back in vim, but in command mode. Voila! You've went from vim insert mode to vim command mode.

Hope this helps other LightTable vim users.

like image 745
zenshade Avatar asked Mar 23 '23 22:03

zenshade


2 Answers

Update: I think the latest LightTable release supports this. Someone please comment if adding the following to their user.behaviors file works (user behaviors is accessible via the command pane (ctrl-space)):

[:editor :lt.plugins.vim/set-options {"enableInsertModeEscKeys" true, 
                                      "insertModeEscKeys" "jk", 
                                      "insertModeEscKeysTimeout" 200}]

Old answer:

The latest LT plugin source supports this, but has not been released yet.

To easily install it do the following:

  1. Open your LT plugins folder, e.g. on OSX ~/Library/Application Support/LightTable/plugins/Vim/
  2. (Optional) Save a backup of the Vim (plugin) folder somewhere else
  3. Delete the Vim folder
  4. Download https://github.com/LightTable/Vim/archive/master.zip
  5. Unzip it, rename the unzipped folder to just Vim, and move/copy it to your LT Plugins folder (i.e. it is replacing the official Vim plugin that you just deleted)
  6. Add the following options in the :editor section of your user.behaviors file: (:lt.plugins.vim/set-options {"enableInsertModeEscKeys" true, "insertModeEscKeys" "jk" "insertModeEscKeysTimeout" 200})
  7. Restart LT and you should be able to use jk (or whatever keys you set in insertModeEscKeys) to exit insert mode
like image 88
JobJob Avatar answered Apr 06 '23 13:04

JobJob


CodeMirror's API is designed in such a way that it's not very complicated to add key bindings but adding support for a configuration file and extending the default key bindings to cover a larger part of Vim's feature set doesn't exactly sound like a trivial task to me. And, considering the fact that LT doesn't even have search/replace, probably something that is near the bottom of their TODO list.

That, and CodeMirror is a third party "library" on which the LT team probably doesn't have much leverage.

like image 37
romainl Avatar answered Apr 06 '23 13:04

romainl