vim is my preferred editor. It works wonderfully in xterms and in screen and tmux sessions.

Using another favorite tool, ssh, I use vim on lots of machines. Some of them have, um, interesting defaults.

Here’s a simple vi function to toggle back and forth between dark and light background colors. The function also enables syntax highlighting, so leave out the syntax on line if you want to stick with monochrome.

" verify syntax is available and there are terminal colors available
if has("syntax") && &t_Co > 2
  set background=dark
  syntax on    " Defaults to no syntax highlighting
endif

I can call the function from the vim command line with :call Switch_background(), but that’s a lot of typing.

Instead I mapped ..bg to call the function and toggle back and forth.

map ,,bg :call Switch_background()<CR>

I use comma comma (,,) because it’s easy to type and doesn’t conflict with other keypatterns I use.

Nothing complex once you know about it, but it’s been useful for me.