Last Updated: December 30, 2020
·
36.43K
· zombiecalypse

Editing Google Docs with vim

Google docs is great, but also somewhat annoying in that you can't use your favourite text editor to make changes. Well, not any more.

Google offers GoogleCL to interact with their services on the command line. You could for example use

google docs edit --title "Title of your document" --editor vim

to modify a pure text version of your document with vim. This will lose all your formatting however. You can also modify html with

google docs edit --title "Title of your document" --editor vim --format htm

but this is just horrible to manipulate.

Instead, we can use pandoc to convert from and to just about any format we like.

Now to the gist of it:

Setup

sudo apt-get install googlecl pandoc

Then create somewhere in your path vim-html-markdown with this content:

#!/bin/sh

file=$1
markdown=`tempfile --suffix=.mdown`

## Convert to markdown with pandocs
pandoc "$file" -f html -t markdown -o $markdown

## Edit the markdown file
vim $markdown

## And convert it back to html, which can be uploaded to Google Docs
pandoc $markdown -f markdown -t html -o "$file"

Using it

google docs edit --title "Title of your document" --editor vim-html-markdown --format htm

The file will automatically be uploaded and have the correct formatting.

Modifying it

If you like emacs better, just replace vim with emacs, if you prefer reStructuredText, just replace markdown with rst.

Related protips:

Basic Vim commands - For getting started

5 Responses
Add your response

Not much development is going on with the Google code repository for googlecl. Here (https://github.com/vinitkumar/googlecl) is a googlecl fork that has some more activity on it.

over 1 year ago ·

This seems really useful. Thanks for the tip!

over 1 year ago ·

@epicdavi: Thanks, I modified the link!

over 1 year ago ·

Seems to not work anymore (at last on OS X, even after installing gdata-python-client from sources):

"Editing documents is not supported for gdata-python-client < 2.0"

over 1 year ago ·

I've been looking for a solution like this for very long!
However I cannot get it to work. I'm getting the error Unable to obtain OAuth request token: 307.
With which GoogleCL version did you get this working exactly and when? It seems to be broken both in Fedora (sudo dnf install googlecl) and in pip (pip2 install google_cl).

over 1 year ago ·