20 Feb 2013

tl;dr Google Docs + Vim = Yay.

Ah, the grail. Vim everywhere. Once Vim’s got its claws in you, you can’t settle for anything else. Every other editor is frustrating and second-class.

But for for Google Docs I’m forced to make an exception. It’s my ideal way to work with normal people1. Especially when it’s changing a lot. Google Docs is user-friendly, it’s got all the features we need, and no-one ever stops the conference call to say, “Wait - did I email you the latest version?”

But I still don’t want to give up Vim. How could we connect the two? The way I see it, there are three possible solutions.

Vim talks to Google.

We could build a plugin for Vim that connects to the Google Docs server. Ever since Google Wave came & went, there has been plenty of information available on how to build a collaborative document-editing system. We can assume that Google Docs approaches the problem along these lines. The problem I think, wouldn’t be with the protocol, but with Vim itself.

Vim is single-threaded, so it’s not going to lend itself well to listening asynchronously for changes from the central server. We could probably work around that by reaching out from Vim into Python or Ruby, but that instantly puts us into the realms of, “If this plugin doesn’t work, simply re-compile your copy of Vim.” Yuck.

Also, Vim has a strictly text-only display. Even if we could happily listen for changes, displaying them is going to be tricky. We could use some syntax-highlighting tricks to simulate multiple cursors, but I think it’s always going to look like a hack.

I don’t think building Google Docs collaborative editing into Vim is impossible2, but I’m certain it would be swimming against the tide. Getting it to work well would be a mammoth project.

Maybe Emacs?

Emacs has a very good Vim-emulation mode, and copes well will multiple processes and displaying text-with-extras3. It would be possible. In fact, I’ve built a prototype myself, and whilst it’s not releasable, it certainly proves the concept. But it puts us in an even worse position: “To install this plugin, just install Emacs.” I can’t see any Vim user accepting that as a solution4.

that would give some clues.

Some other collaboration service.

Another way forward would be to bypass both Vim & Google Docs for something Vim-like and Google Docs-like, that’s better suited to the task. There are a few online editors that offer collaboration, and several of them are based on CodeMirror5, which has a passable Vi-emulation mode.

This is probably the shortest path to a solution, but it still suffers from our opening problem: You have to turn to your non-technical colleagues and say, “Can we switch from Google Docs just so I can use Vim?”, and they look at you like you’re an alien. No, the right solution won’t involve having to change an existing team’s behaviour just to accommodate our preferences.

Google Docs becomes Vim-like.

So the last solution, and I think the only viable one, is to graft a Vim-like input system on top of Google Docs. If we do that, we don’t have to disturb existing users, we ought to get live collaboration & display for free, and we just have to worry about one key problem: How much Vim do we need? How much would we have to implement before we felt at home in Google Docs?

Naive Vim extensions rarely seem to get much beyond ESC, h, j, k, l before they think they’ve got the essence of Vim. We know there’s much more to it. With that in mind, here’s my list of what we’d need, and a few things I think we can leave out:

Requirements

  • Vim-like editing for Google Documents, without disturbing ordinary users.
  • Support for:
    • Modal editing. (Normal, insert and visual modes).
    • First-class motions & text objects. d5j should delete 5 lines. ci( should change all the text in the current parentheses.
    • Ex commands. Not a direct translation of the Vim ones, but something like :wordcount should trigger the word-count box. :help should trigger the Google Docs help.
    • Custom keyboard mappings. Some equivalent to nnoremap.
    • Windowing commands remapped to switch between main, comment and sharing panes.

Non-requirements

  • Plugins. Not for v1 at least.

Conclusion

I think it would be the right approach. I think it would be a reasonably-sized project. I think it would make the world a better place. So I’m putting the idea out into the world. What do you think?

  1. Normal people. Non-geeks. People whom, I accept, shouldn’t be expected to learn Vim. 

  2. I should note that it’s possible to edit Google Documents with Vim using the Google Command Line tool. But that approach struggles with translating between gDocs’ format and plain text, and it doesn’t work collaboratively at all. 

  3. multiple cursors project 

  4. As I’ve written, these days Emacs is one of my favourite versions of Vim. But I don’t expect to convert anyone. (Hell, I’m not even certain I’d want to.) But if you like Vim & Lisp, it’s worth taking a look at Evil-mode

  5. CodeMirror’s Vim-mode is far from perfect, but it wouldn’t be hard to make it much, much better. And the same thing goes for all the browser-based Vim emulations: Not good enough, but a good start. 

comments powered by Disqus