diff --git a/.gitmodules b/.gitmodules index 5b268ac..e85d93a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/vim/vim/bundle/vim-templates b/vim/vim/bundle/vim-templates deleted file mode 160000 index d368246..0000000 --- a/vim/vim/bundle/vim-templates +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d3682469538340454d1e11d143735683cc75a13a diff --git a/vim/vim/bundle/vim-templates/.gitattributes b/vim/vim/bundle/vim-templates/.gitattributes new file mode 100644 index 0000000..2700f94 --- /dev/null +++ b/vim/vim/bundle/vim-templates/.gitattributes @@ -0,0 +1,4 @@ +/plugin/templates.vim export-subst +/.gitattributes export-ignore +/README.md export-ignore +/LICENSE export-ignore diff --git a/vim/vim/bundle/vim-templates/LICENSE b/vim/vim/bundle/vim-templates/LICENSE new file mode 100644 index 0000000..287af79 --- /dev/null +++ b/vim/vim/bundle/vim-templates/LICENSE @@ -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. diff --git a/vim/vim/bundle/vim-templates/README.md b/vim/vim/bundle/vim-templates/README.md new file mode 100644 index 0000000..5590c19 --- /dev/null +++ b/vim/vim/bundle/vim-templates/README.md @@ -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. diff --git a/vim/vim/bundle/vim-templates/plugin/templates.vim b/vim/vim/bundle/vim-templates/plugin/templates.vim new file mode 100644 index 0000000..04f5d92 --- /dev/null +++ b/vim/vim/bundle/vim-templates/plugin/templates.vim @@ -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 +" +" 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= diff --git a/vim/vim/bundle/vim-templates/templates/html b/vim/vim/bundle/vim-templates/templates/html new file mode 100644 index 0000000..e2c2bcf --- /dev/null +++ b/vim/vim/bundle/vim-templates/templates/html @@ -0,0 +1,16 @@ + + + +FIXME + + + + + + +# cursor: 15 del diff --git a/vim/vim/bundle/vim-templates/templates/perl b/vim/vim/bundle/vim-templates/templates/perl new file mode 100644 index 0000000..24eb976 --- /dev/null +++ b/vim/vim/bundle/vim-templates/templates/perl @@ -0,0 +1,6 @@ +#!/usr/bin/env perl +use 5.014; +use warnings; + + +# cursor: 5 del diff --git a/vim/vim/bundle/vim-templates/templates/post b/vim/vim/bundle/vim-templates/templates/post new file mode 100644 index 0000000..d35e5cc --- /dev/null +++ b/vim/vim/bundle/vim-templates/templates/post @@ -0,0 +1,27 @@ +--- + layout: + tabtitle: + title: + tags: +--- + +
+

+ + + +

[Bill Niblock][][]

+ +
+ + + + + + + + + diff --git a/vim/vim/bundle/vim-templates/templates/sh b/vim/vim/bundle/vim-templates/templates/sh new file mode 100644 index 0000000..001412d --- /dev/null +++ b/vim/vim/bundle/vim-templates/templates/sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -eu + +# cursor: 3 del