Firmware Engineer, Minimalist, Improving Runner

My .Vimrc Configuration

VIM is my favorite text editor. It's powerful, customizable, and available on all platforms (default on unix-systems, gvim/macvim on pc/osx-systems). Most importantly, it allows me to get my work done in an efficient manner. Once you learn the movements and power commands, your hands rarely have to leave the keyboard when editing.

The .vimrc is the configuration file. I consider my .vimrc pretty basic and a good starting point for beginners to VIM. I would suggest to anyone editing their .vimrc to understand each setting before using them. Here are a few of my favorite settings:

Remap Command Mode

nnoremap ; :

The nnoremap setting remaps : to ; in normal mode and thus, saves a key stroke (shift + ;) when entering command mode. It seems trivial, but when a file is saved a 100 times in a day, it adds up.

Remap <esc> to jj

inoremap jj 

Similar to the setting above, this setting remaps the often-used <esc> key to jj key press combo. It's pretty rare for code or text to contain the letters "jj" in succession. Now, a simple jj tap will bring VIM out of insert mode.

Map <leader> key

let mapleader = ","

The <leader> key is your own personal modifier key and is default as . This setting allows for easier usage of macros.

Map NERDTree toggle to <leader>

map n :NERDTreeToggle

This allows me to map the <leader> key in conjunction with n to quickly toggle NERDTree. NERDTree is a VIM plugin used to navigate and control the files in a workspace easier.

Add Google Search to VIM command line

function! Google()
   call inputsave()
   let searchterm = input('Google: ')
   call inputrestore()
   return searchterm
map g :! /usr/bin/open -a "/Applications/Google" ''

With this macro, typing <leader>g brings up the prompt "Google:". Once a search string is entered, a web browser will open (or tab if one is already opened) with a Google search of the string. This is great for those moments when I want to quickly look something up without having to locate my web browswer.

Toggle VIM Blog Mode

" macro for blog writing
function ToggleBlog()
  if &wrap
    echo "Blog OFF"
    setlocal nowrap
    set virtualedit=all
    setlocal lines=50 columns=200
    color desert
    setlocal guifont=menlo:h11
    silent! nunmap  k
    silent! nunmap  j
    silent! nunmap  0
    silent! nunmap  $
    silent! iunmap  k
    silent! iunmap  j
    silent! iunmap  0
    silent! iunmap  $
    echo "Blog ON"
    setlocal wrap linebreak nolist
    set virtualedit=
    setlocal display+=lastline
    setlocal lines=50 columns=90
    color morning
    setlocal guifont=menlo:h14
    noremap   k gk
    noremap   j gj
    noremap   0 g0
    noremap   $ g$
noremap  b :call ToggleBlog()

Finally, this last macro allows me to toggle between my coding sessions and my writing sessions. When writing, I prefer a lighter colorscheme (color morning) and smaller width window for readability (columns=90). I also set my text to wrap (setlocal wrap) so my text doesn't run off the window. Since wrap is enabled, the movement keys don't work as intuitively, so gk, gj, g0, and g$ allow the cursor to move similarly to before.

All in all, my favorite .vimrc settings increase the comfort of using the editor and add a little fun utility for the lazy side in me. I've found them extremely useful and hope they can be the same for you.