Spent a frustrating weekend working on / learning facebook applications, and mucking around with jquery selectors for another project... So I blew some steam off and wrote a vim script using the python bindings to vertically align selected text, which let's me turn junk like:
dictionary = { one_dang_thing : 1, two_umms : 'tweeee', apricot : 'fish', }Into prettier junk ;)
dictionary = { one_dang_thing : 1, two_umms : 'tweeee', apricot : 'fish', }
python << EOF import vim, re def align(start, end): indent = "" indent_re = re.compile(r'^(\s*)') for m in indent_re.finditer( vim.current.buffer[start] ): indent = m.group(1) columns = [ ] for line in vim.current.buffer[start-1:end]: for i, word in enumerate(line.split()): if i >= len(columns): columns.append( 0 ) if len(word) > columns[i]: columns[i] = len(word) for index in range(start-1,end): words = [] for i, word in enumerate(vim.current.buffer[index].split()): words.append ( word + " " * ( columns[i] - len(word) ) ) vim.current.buffer[index] = indent + " ".join(words) EOF command! -nargs=0 -range Align :py align(<line1>, <line2>)
I still haven't figured out why I don't like using user-generated vim plugins. ;)