gvim makes you strong

After moving to an all-Linux workplace, I quickly learned to love the gvim text editor for its extensibility and ubiquity.  These are some of the tweaks I’ve found most useful.

This one is easy, but using bang to call shell commands is a nice time saver so you don’t have to switch windows:

:!ls .

You can use the % operator to refer to the currently open file:

:!ls -l %

If it is a long command string that you use frequently, you define functions in vimscript within ~/.vim/plugin:

fu! Cmd()
    let file = expand('%')
    execute '!ls -l '.file

fu! CmdWithArgs(arg1, arg2)
    echo a:arg1.' '.a:arg2

command Cmd call Cmd()
command -nargs=* CmdWithArgs call CmdWithArgs(<f-args>)

You can then call these functions via:

:CmdWithArgs one two

I use this all the time for commits, pushes, and pulls in git.  This is also handy when using <cfile>, which grabs the path currently under the cursor and can be used to quickly view images or other formats using command line tools.  For text files, this functionality is available out of the box; typing gf (goto file) with the cursor over a filepath will open the file in the same window, and <ctrl>-w gf will open it in a tab (gt to toggle between them).

You can inline python in vimscript:

python << EOF

import sys


You can also move a visual block of text (defined with <ctrl>-v) from one file to another:

:w>> path | '[,']d

I’m bad about keeping code to 80 characters a line, so this suggestion for some subtle highlighting in ~/.vimrc for when I run over is a nice reminder:

highlight OverLength ctermbg=#1F0A0A ctermfg=white guibg=#1F0A0A
match OverLength /\%79v.\+/

Other .vimrc additions that I always use are highlighting all search results:

set hlsearch
hi Search guibg=LightGreen ctermbg=LightGreen

and changing statusbar colors based on normal or insert mode:

set laststatus=2
au InsertEnter * hi StatusLine ctermbg=LightRed guibg=LightRed
au InsertLeave * hi StatusLine ctermbg=Black guibg=Black

I really like Todd Werth’s ir_black color scheme with taglist (for providing a list of function definitions) and pyflakes (a useful passive syntax checker for python).

For further reading, check out Andrew Scala’s Five Minute Vimscript or Steve Losh’s comprehensive Learn Vimscript the Hard Way.

Hello World

As I sit on the precipice of another shift in my career, I once again find myself taking inventory of what I have learned and where I want to go next.  While the latter is yet to be determined, the former is rich with knowledge gleaned from working side by side world-class engineers and artists.

With each successive gig, I find the collection of these lessons learned more and more unwieldy.  I am starting this blog to (finally) index and re-share the tidbits I have found particularly useful, since I find myself frequently searching for (and usually reinventing) solutions that have long been misplaced.  In addition, I have wanted to take a more serious ownership of my own work, and with this site I hope to do so: discussing influences, cataloging progress and failure, and presenting it in the hopes that it will inspire as I have been inspired.

So here it goes.  Hold on to your butts…