Remove vim-templates from submodules (unnecessary and problematic).

This commit is contained in:
Bill Niblock 2015-07-08 14:43:23 -04:00
parent f7ebf203eb
commit 1a490f7c81
10 changed files with 163 additions and 4 deletions

3
.gitmodules vendored
View file

@ -16,6 +16,3 @@
[submodule "dotbot"]
path = dotbot
url = https://github.com/anishathalye/dotbot
[submodule "vim/vim/bundle/vim-templates"]
path = vim/vim/bundle/vim-templates
url = https://github.com/ap/vim-templates.git

@ -1 +0,0 @@
Subproject commit d3682469538340454d1e11d143735683cc75a13a

View file

@ -0,0 +1,4 @@
/plugin/templates.vim export-subst
/.gitattributes export-ignore
/README.md export-ignore
/LICENSE export-ignore

View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Aristotle Pagaltzis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,23 @@
This is a Vim plugin for providing filetype-dependent templates for new files, using a simple but effective mechanism.
Usage
-----
When you start a fresh buffer, setting a `filetype` on it will load the corresponding template. E.g. open Vim and issue
:setf html
You should find a skeleton HTML file, ready to fill in.
One new command has been added for convenience: it is called `:New` and takes exactly one argument. It will open a new empty window and set the filetype for it to the argument given.
A handful of templates are included, but the real purpose of the plugin is to allow you to easily create your own.
Creating templates
------------------
Templates are kept in `.vim/templates`. The template filename must be equal to the `filetype`. So when you set the filetype of an empty buffer to `html`, `.vim/templates/html` will be loaded. It's that simple.
In the templates, you can use a `cursorline` directive to specify a position for the cursor after loading the template. Such a cursorline works much like a modeline: the word `cursor:` must appear, followed by one or two numbers and opionally the word `del`, all separated by whitespace. The first number specifies the line the cursor will be placed in. The second, if present, specifies a column. The optional word `del` directs the script to remove the cursorline at load time. Take a look at the templates supplied in the package, it should be fairly self-explanatory.

View file

@ -0,0 +1,62 @@
" Vim global plugin for providing templates for new files
" Licence: The MIT License (MIT)
" Commit: $Format:%H$
" {{{ Copyright (c) 2015 Aristotle Pagaltzis <pagaltzis@gmx.de>
"
" Permission is hereby granted, free of charge, to any person obtaining a copy
" of this software and associated documentation files (the "Software"), to deal
" in the Software without restriction, including without limitation the rights
" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
" copies of the Software, and to permit persons to whom the Software is
" furnished to do so, subject to the following conditions:
"
" The above copyright notice and this permission notice shall be included in
" all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
" THE SOFTWARE.
" }}}
if exists( 'g:loaded_template' ) | finish | endif
let g:loaded_template = 1
augroup template
autocmd!
autocmd FileType * if line2byte( line( '$' ) + 1 ) == -1 | call s:loadtemplate( &filetype ) | endif
augroup END
function! s:globpathlist( path, ... )
let i = 1
let result = a:path
while i <= a:0
let result = substitute( escape( globpath( result, a:{i} ), ' ,\' ), "\n", ',', 'g' )
if strlen( result ) == 0 | return '' | endif
let i = i + 1
endwhile
return result
endfunction
function! s:loadtemplate( filetype )
let templatefile = matchstr( s:globpathlist( &runtimepath, 'templates', a:filetype ), '\(\\.\|[^,]\)*', 0 )
if strlen( templatefile ) == 0 | return | endif
silent execute 1 'read' templatefile
1 delete _
if search( 'cursor:', 'W' )
let cursorline = strpart( getline( '.' ), col( '.' ) - 1 )
let y = matchstr( cursorline, '^cursor:\s*\zs\d\+\ze' )
let x = matchstr( cursorline, '^cursor:\s*\d\+\s\+\zs\d\+\ze' )
let d = matchstr( cursorline, '^cursor:\s*\d\+\s\+\(\d\+\s\+\)\?\zsdel\>\ze' )
if ! strlen( x ) | let x = 0 | endif
if ! strlen( y ) | let y = 0 | endif
if d == 'del' | delete _ | endif
call cursor( y, x )
endif
set nomodified
endfunction
command -nargs=1 New new | set ft=<args>

View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>FIXME</title>
<!--
<link rel="stylesheet" type="text/css" href="FIXME">
<script type="text/javascript" src="FIXME"></script>
<style type="text/css">
</style>
-->
</head>
<body>
</body>
</html>
# cursor: 15 del

View file

@ -0,0 +1,6 @@
#!/usr/bin/env perl
use 5.014;
use warnings;
# cursor: 5 del

View file

@ -0,0 +1,27 @@
---
layout:
tabtitle:
title:
tags:
---
<article>
<h1></h1>
<br /><h4>[Bill Niblock][<date>][<category>]</h4>
</article>
<!-- ================================= -->
<!-- ================================= -->
<!-- Notes
-->
<!-- ================================= -->
<!-- ================================= -->
<!-- cursor: 11 -->

View file

@ -0,0 +1,4 @@
#!/bin/bash
set -eu
# cursor: 3 del