/good_shit

Shit I have found useful and would like to reference

Good Shit

Shit I have found useful, recorded for future reference. Focused on tools and workflows I like to use. Feel free to open a PR if you have a good trick, too!

extending vim's command language

Verb Meaning
gc (cm?) comment
cx exchange
gr go replace (from register)
gs go sort
gt titlecase NOTE: not mapped as such because of tabs
cp system clipboard
Text Object Meaning
ae entire file
i contiguous indent level
l line, ignoring leading whitespace

Type a literal tab character in vim

<C-v><Tab>

Get rid of incorrect HTML-escaping on Pro Git

Fire up the console and copy-paste. &gt; is but one of many, but it's the most common one I've run into.

$('pre').each(function(idx, pre) {
  $(pre).text($(pre).text().replace(/&lt;/g, '<'))
  $(pre).text($(pre).text().replace(/&gt;/g, '>'))
  $(pre).text($(pre).text().replace(/&amp;/g, '&'))
})

Change a variable name project-wide

  1. In project root dir: $ vim $(ack 'bad_variable_name' -l)
  2. In vim: :argdo %s/bad_variable_name/good_variable_name/gc | update

Step 1: open every file containing bad_variable_name in vim.

Step 2: argdo applies the command to every file given as an argument; c flag can be left off, but then make sure to git add -p; piping to update saves each file after making all substitutions. If you don't do the ack bit at first, add an e flag to the :%s to suppress any errors from files without a match.

Convert Ruby hash syntax from 1.8-style to 1.9-

s/o https://robots.thoughtbot.com/convert-ruby-1-8-to-1-9-hash-syntax

In vim, one file:
:%s/:\([^ ]*\)\(\s*\)=>/\1:/g
In terminal, whole project:
perl -pi -e 's/:([\w\d_]+)(\s*)=>/\1:/g' **/*.rb