summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-05 00:37:54 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-05 00:37:54 -0500
commit9d67654713f4ea3f07c8d24994064770c6e226e2 (patch)
tree771a452cc9c9116bc5790532d7ccbe10763a1d05
downloadvim-skeletons-9d67654713f4ea3f07c8d24994064770c6e226e2.tar.gz
vim-skeletons-9d67654713f4ea3f07c8d24994064770c6e226e2.zip
separate out my skeleton stuff from my vimrc
-rw-r--r--skeleton.vim39
1 files changed, 39 insertions, 0 deletions
diff --git a/skeleton.vim b/skeleton.vim
new file mode 100644
index 0000000..dd338f1
--- /dev/null
+++ b/skeleton.vim
@@ -0,0 +1,39 @@
+function s:read_skeleton(pattern)
+ set modifiable
+ " the skeleton file should be a file in ~/.vim/skeletons that matches the
+ " glob pattern of files that it should be loaded for
+ let skeleton_file = glob("~/.vim/skeletons/".a:pattern)
+ " read leaves a blank line at the top of the file
+ exe "silent read ".skeleton_file." | normal ggdd"
+ let lines = getline(1, "$")
+ normal ggdG
+ for line in lines
+ " sigh... this is *so* dumb
+ let remove_extra_line = 0
+ if line('$') == 1 && col('$') == 1
+ let remove_extra_line = 1
+ endif
+ " lines starting with :: will start with a literal :
+ if line =~ '^::'
+ call append(line('$'), strpart(line, 1))
+ normal G
+ if remove_extra_line
+ normal ggdd
+ endif
+ " lines not starting with a : will just be appended literally
+ elseif line !~ '^:'
+ call append(line('$'), line)
+ normal G
+ if remove_extra_line
+ normal ggdd
+ endif
+ else
+ exe line
+ endif
+ endfor
+ redraw
+endfunction
+
+function Skeleton(pattern)
+ exe "autocmd BufNewFile ".a:pattern." silent call s:read_skeleton(\"".a:pattern."\")"
+endfunction