#!/usr/bin/env python # align a section in vertical columns 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)