Turning Vim into a Writing Productivity Powerhouse

Vim has many benefits. It’s powerful, it’s easily extensible, it runs entirely in your terminal so you look like a 1337 hacker every time you use it. One downside, however, is that out-of-the-box it isn’t a fantastic environment to write long-form text in. Vim is very busy, it doesn’t wrap lines by default, and the commands for showing word count and other useful metrics aren’t obvious. I’m currently writing my thesis in LaTeX, and I wanted a better way to write in Vim.

Simple configuration

First off—addressing the line width issue. Vim by default doesn’t wrap lines, and you have to turn that on. I like to use:

set fo+=t
set tw=79

The tw option (textwidth) sets the text width to 79 characters, and to use Vim’s fo options (formatoptions) to do so. We also add the t flag to fo, ensuring that words are auto-wrapped to the test-width.

See more format options at the fo-table documentation.

Keybinds

There are only two keybinds that matter now: gw and g^g. gw + a motion allows for automatically wrapping text. I use gwip frequently, which autowraps the inner paragraph your cursor is on. g^g prints the current word count as long as some other information down at the statusline.

Plugins

The next problem to address is the visual clutter. I find it much easier to write when there are no distracitnos on the screen. The two plugins I rely on most here are Junegunn Choi’s absolutely fabulous Goyo and Limelight. Goyo clears out all visual clutter (gutters, statusline, etc.) and centers your window, while Limelight takes it a step further by only highlighting the paragraph you are working on and dimming the rest.

They can be easily installed with vim-plug:

Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'

Even better, you can wire Limelight to activate when Goyo activates, making for an easier experience:

autocmd! User GoyoEnter Limelight
autocmd! User GoyoLeave Limelight!

Note that depending on your terminal you may need to set the Limelight concealment color manually:

let g:limelight_conceal_ctermfg = 'gray'

Custom Config

Remembering all those is a pain! Why not just stick these in your .vimrc (or init.vim)?

" Writing configuration
command WriteMode set tw=79 | set fo+=t | Goyo 85 | echo "Write mode enabled."
command WriteModeDisable set fo-=t | Goyo | echo "Write mode disabled."
let g:limelight_conceal_ctermfg = 'gray'
autocmd! User GoyoEnter Limelight
autocmd! User GoyoLeave Limelight!

This lets you enable writing mode with :WriteMode, and disable it with :WriteModeDisable. I also like to override W to act as w, because I fatfinger :W a lot and that would activate writing mode rather than no-op. That’s a very easy one-liner:

command W w

Command Completion

One last thing: adding command completion for Vim makes for a very ergonomic experience, especially when writing LaTeX. I like coc.nvim which is a very good LSP implementation for Vim8/Neovim. Unlike other completion engines, it is easily installed with:

Plug 'neoclide/coc.nvim'

Once installed, you should be able to install a server for LaTeX easily with :CocInstall coc-texlab!

Demo

Putting it all together, you get:

vim screenshot

Pretty cool, right?