Thursday, 7 April 2011

Vim as fullscreen, distraction free editor

Distraction-free editors such a Writeroom, Darkroom, JDarkroom and others are very popular nowadays. I like them too, writing is much more productive when you can dim the colors and remove all the bells and whistles from the user interface and focus on the text.

Unfortunately, I have a slight problem. I have trained my fingers and brain to use Vim keybindings, and it is fairly painful to try to edit something using classical keybindings. This prompted me to check if I can convert my trusty Vim to simple full-screen editor.

Experimentation

I typically do my writing on Mac OS X laptop, and this means that I usually use MacVim with my customized configuration. I started the process by checking out the MacVim capabilities, and lo'and behold - MacVim supports fullscreen mode (using CMD+SHIFT+F keybinding).

Next step is to see what font would look nice on the full screen mode. When programming, smaller fonts are very useful to keep as much information as possible on the screen, but they also strain eyes which is undesirable when writing text. After a quick test, I settled (for now) to Menlo, 18pt font. It can be set on MacVim using following command:


:set guifont=Menlo:h18

I did not really want to have 16:10 screen to be filled with text from left to right, so I tested narrowing the display, and finally settled to 90 columns. MacVim automatically centers the view in full screen mode, which was very pleasant surprise.


:set columns=90

Next step in my experimentation was to find a suitable colorscheme. I decided to use for now the rubyblue theme (available here).


:colorscheme rubyblue

Basic distraction-free environment is now done, but there are still some tweaks that can be done. For example, the color scheme I have chosen is maybe a bit too bright, and status bar is visible. Also, since I have just typed the commands to vim, I need to retype the commands every time I start the editor - quite fatal flaw indeed.

Small iterative improvements

First, I'll see if I can hide the statusbar. Unfortunately, not everything can be hidden, but Ubuntuforums provided following tip:


:set laststatus=0

I think this is good enough.

Next, I'll try to find a nicer color scheme. I prefer dark color schemes, since I've noticed that the white background strains eyes (the backlight). I downloaded the vim color sampler pack and browsed the online gallery a bit.

I settled down with color scheme named dante:


:colorscheme dante

I also want to undo some configuring I have done for programming work (cursor line highlighting, visible whitespace):


:set nocursorline :set nolist

I'd also like vim to go to full screen mode when I load the settings. This is possible using following command:


:set fu

When I open a markdown file, all sections are automatically folded, since I have markdown bundle installed. This is quite irritating, but can be disabled with following command:


:set nofoldenable

Making profile

I created a file called ~/.gvimrc.fullscreen and put following contents to it:


" Include defaults source ~/.vimrc source ~/.gvimrc set guifont=Menlo:h18 set columns=90 set laststatus=0 colorscheme dante set nocursorline set nolist set nofoldenable set fu " Finally, clear hightlight noh

The settings can now be taken use with command:


:source ~/.gvimrc.fullscreen

Final tweaks

Keyboard shortcuts are quite easy to add in vim. Following command automatically loads the full screen profile, when F3 is pressed:


:nmap <F3> :so ~/.gvimrc.fullscreen<CR>

Switching back to normal profile can also be mapped as easily:


:nmap <F2> :so ~/.gvimrc<CR>

Note: both setting-files must overwrite the same settings in order for this to work.

Spell checking is always nice thing to have. Fortunately, Vim7 has built-in spell checker which can be enabled with command:

:set spell

Final version

The final version of my config (in ~/.gvimrc.fullscreen) is following:


" Include defaults source ~/.vimrc source ~/.gvimrc set guifont=Menlo:h18 set columns=90 set laststatus=0 colorscheme dante set nocursorline set nolist set nofoldenable set fu nmap <F2> :so ~/.gvimrc<CR> nmap <F3> :so ~/.gvimrc.fullscreen<CR> " Finally, clear highlight which for some reason goes on noh

I have also made following additions to my regular ~/.gvimrc:


<...> " Full screen mode nmap <F2> :so ~/.gvimrc<CR> nmap <F3> :so ~/.gvimrc.fullscreen<CR> set nofu <...>

That's it. Happy vimming!

No comments:

Post a Comment