Vim distraction free mode

In a distraction free mode, all the UI elements of the editor are gone, the menus, the status bar, the line number, and the text is centered right in the middle of the screen. Its a productivity boost if you need to focus on writing your content, without need to reach the functionalities of your editor, this is sometimes desirable.

The Sublime and Emacs both supported it, Sublime has built in support, while in Emacs you need to install a plugin. See how to do it in Emacs: Easy Emacs distraction free mode.

In my opinion , every editor should support it right out of the box, because its such an useful and ingenious feature.

The biggest reason I want a distraction free mode is when reading code in fullscreen mode, the code all goes to the left side of the monitor, it can be uncomfortable when you have a wide LED display. I like it to be in the center of the screen.

There are quite a few choices for Vim editor out there, I tried some of them, and here are some reviews about them.


The first plugin I tried is Vimroom, to install it, goto the vimfiles directory and execute

wget --no-check-certificate

Now you need to restart Vim, by default the toggle key is bind to <Leader>V, that is press \ and then V. But looks its not compatible with my Vim 7.4, when I use a dark theme for example slate and go fullscreen, the Vimroom display like this

Obviously there are something goes wrong here, lets see an alternative Goyo.


The second one is Goyo, this one has no problem with my VIM 7.4 on Win8.

Quick installation, just download two vim files to plugin and autoload directory with wget command as following

C:\bin\Vim\vimfiles\plugin>wget --no-check-certificate
C:\bin\Vim\vimfiles\autoload>wget --no-check-certificate

And then restart VIM and execute :Goyo, its simple and easy way to go.

Vim distraction free mode

Something I don't like about Goyo: there is some kind of padding top and padding bottom, the height is not 100% even I set it to 100% with command :Goyo x100%, second is the :q command didn't quit VIM but quit Goyo, I need execute :q two times to quit VIM.

I don't know anything about vim script, but the Goyo.vim is a simple one, with the ingenious echom method, I figured out how to solve the problem, for the padding problem. Goyo actually use some kind of hidden window as padding of top left bottom and right, and our distraction free window will be in the center. So there are actually five windows out there in distraction free mode. But in VIM, even a window is invisible, it still occupy at least two lines of space, thats why when you set the height to 100%, there is still a padding on the top and bottom.

The solution is do not create the top and bottom window, open the autoload\goyo.vim and search for code below and comment out them

"  let t:goyo_pads.t = s:init_pad('') " s:init_pad('topleft new')
"  let t:goyo_pads.b = s:init_pad('') " s:init_pad('botright new')
"  call s:setup_pad(t:goyo_pads.t, 0, top, 'j')
"  call s:setup_pad(t:goyo_pads.b, 0, bot, 'k')

Now the height will be always the full vertical length of the window, and you will not be able to adjust the window height of the distraction free mode, but you may never need it anyway.

The second problem can be solved by provide a different goyo_off function, because when you execute :q, the actually called method is goyo_off, just use a different method, for example

function! s:goyo_offquit()
  let b:quitting_bang = 0
  cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
  if b:quitting_bang

Since we want to quit VIM, so we don't care about anything except checking for unsaved changes. And search for the calling place and replace it

function! s:blank(repel)
  if bufwinnr(t:goyo_pads.r) <= bufwinnr(t:goyo_pads.l) + 1
    \ || bufwinnr(t:goyo_pads.b) <= bufwinnr(t:goyo_pads.t) + 3
    call s:goyo_offquit()
  execute 'wincmd' a:repel