]>
code.delx.au - dotfiles/blob - .vim/abbrs2vim.py
3 import time
, os
, os
.path
, sys
6 macros
["YDATE"] = lambda: time
.strftime("%Y-%m-%d")
7 macros
["YEAR"] = lambda: time
.strftime("%Y")
8 macros
["NAME"] = lambda: "Put your name in ~/.vim/abbrs2out.vim"
9 macros
["EMAIL"] = lambda: "Then run that script"
12 vimdir
= os
.path
.join(os
.environ
.get("HOME"), ".vim")
14 outfilename
= os
.path
.join(vimdir
, "abbrsout.vim")
15 outfile
= open(outfilename
, "w")
17 print >> sys
.stderr
, "Couldn't open output file for writing: %s" % outfilename
20 abbrsdir
= os
.path
.join(vimdir
, "abbrs")
21 if not os
.path
.isdir(abbrsdir
):
22 print >> sys
.stderr
, "Could not find directory with abbreviations: %s" % abbrsdir
25 for abbrfile
in os
.listdir(abbrsdir
):
26 abbr
= open(os
.path
.join(abbrsdir
, abbrfile
), "r").read()
27 for macro
in macros
.keys():
28 if abbr
.find(macro
) >= 0:
29 abbr
= abbr
.replace(macro
, macros
[macro
]())
30 abbr
= abbr
.replace("\n", "\r")
31 # Put into paste mode and take out of paste mode
32 abbr
= "iab %s \x1b:set paste\ri%s\x1b:set nopaste\r" % (abbrfile
.rsplit('.', 1)[0], abbr
)
33 if abbr
.find("___") >= 0:
34 # Then search for ___ to place the cursor there
35 abbr
+= "gg\r/___\x1b:nohlsearch\n"
37 # Leave the cursor in insert mode