Created
September 11, 2013 09:16
-
-
Save venthur/6521228 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
This script recursively searches the current directory for .vimrc files | |
and counts the number of times an option has been modified. | |
It currently only uses lines that start with 'set ', 'setlocal', 'let', | |
etc. are ignored. | |
""" | |
import os | |
mappings = { | |
'ai' : 'autoindent', | |
'aw' : 'autowrite', | |
'bg' : 'background', | |
'bs' : 'backspace', | |
'cc' : 'colorcolumn', | |
'ch' : 'cmdheight', | |
'cin' : 'cindent', | |
'cst' : 'cscopetag', | |
'csto' : 'cscopetagorder', | |
'efm' : 'errorformat', | |
'enc' : 'encoding', | |
'et' : 'expandtab', | |
'fencs' : 'fileencodings', | |
'ff' : 'fileformat', | |
'fdc' : 'foldcolumn', | |
'fdm' : 'foldmethod', | |
'ffs' : 'fileformats', | |
'fo': 'fold', | |
'ft' : 'filetype', | |
'gcr': 'guicursor', | |
'gfn': 'guifont', | |
'hid' : 'hidden', | |
'hls' : 'hlsearch', | |
'isk' : 'iskeyword', | |
'lbr': 'linebreak', | |
'ls' : 'laststatus', | |
'lz' : 'lazydraw', | |
'mat' : 'matchtime', | |
'noai': 'noautoindent', | |
'nocp': 'nocompatible', | |
'nohls' : 'nohlsearch', | |
'novb' : 'novisualbel', | |
'nu' : 'number', | |
'rtp': 'runtimepath', | |
'sb' : 'splitbelow', | |
'shm' : 'shortmess', | |
'si' : 'smartindent', | |
'spr' : 'plitright', | |
'sw' : 'shiftwidth', | |
'tenc' : 'termencoding', | |
'ts' : 'tselect', | |
'tw' : 'textwidth', | |
'vb' : 'visualbell', | |
've' : 'virtualedit', | |
'wcm' : 'wildcharm', | |
'wm' : 'wrapmargin', | |
'wmh' : 'winminheight', | |
'ws' : 'wrapscan', | |
'ww' : 'whichwrap', | |
} | |
# get the paths of configfiles | |
cfiles = [] | |
for root, dirs, files in os.walk('.'): | |
for f in files: | |
if f == '.vimrc': | |
cfiles.append(root+'/'+f) | |
# read each file and count the number of times an option was modified | |
counter = {} | |
for f in cfiles: | |
with open(f) as fh: | |
for line in fh.readlines(): | |
line = line.strip() | |
if line.startswith('set '): | |
line = line.split(' ')[1].strip() | |
line = line.split('"')[0].strip() | |
line = line.split('=')[0].strip() | |
line = line.split('+')[0].strip() | |
line = line.split('-')[0].strip() | |
counter[line] = counter.get(line, 0) + 1 | |
# look for shortcut options and count their values to the long option | |
for m in mappings: | |
if counter.get(m) is not None: | |
counter[mappings[m]] = counter.get(mappings[m], 0) + counter[m] | |
counter.pop(m) | |
# print the sorted result | |
for option, nr in sorted(counter.items(), key=lambda x: x[1]): | |
print "%5d %s" % (nr, option) | |
print "Out of %d .vimrcs" % len(cfiles) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment