GithubHelp home page GithubHelp logo

aperezdc / vim-template Goto Github PK

View Code? Open in Web Editor NEW
371.0 11.0 153.0 184 KB

Simple templates plugin for Vim

C 5.77% CSS 2.81% Fortran 4.12% Haskell 3.64% HTML 2.36% Java 7.04% Julia 2.15% JavaScript 8.15% Lua 2.53% OCaml 2.27% PHP 3.28% Perl 15.01% Python 2.70% Ruby 2.44% Shell 4.59% TeX 2.81% XSLT 4.62% CMake 9.10% PLSQL 11.18% Rust 3.44%
vim-plugin neovim-plugin templates template

vim-template's Introduction

Simple Vim templates plugin

Author

Adrian Perez <[email protected]>

This is a simple plugin for Vim that will allow you to have a set of templates for certain file types. It is useful to add boilerplate code like guards in C/C++ headers, or license disclaimers.

Installation

The easiest way to install the plugin is to install it as a bundle. For example, using Pathogen:

  1. Get and install pathogen.vim. You can skip this step if you already have it installed.
  2. cd ~/.vim/bundle
  3. git clone git://github.com/aperezdc/vim-template.git

Bundle installs are known to work fine also when using Vundle. Other bundle managers are expected to work as well.

Important

If you use Fish as your shell, you will need to add set shell=/bin/sh to your ~/.vimrc — the plugin relies on the setting pointing to a Bourne-compatible shell.

Documentation

The documentation can be browsed directly in Vim:

:help template.txt

Alternatively, you can also read it in your browser.

Updating

Manually

In order to update the plugin, go to its bundle directory and use Git to update it:

  1. cd ~/.vim/bundle/vim-template
  2. git pull

With Vundle

Use the :BundleUpdate command provided by Vundle, for example invoking Vim like this:

% vim +BundleUpdate

vim-template's People

Contributors

aperezdc avatar arnidagur avatar brandonocasey avatar bstin avatar chenjianlong avatar dimkarakostas avatar disoul avatar facundoacevedo avatar freed-wu avatar gmg137 avatar ikcalb avatar infmagic2047 avatar jagu-sayan avatar jpmv27 avatar lyude avatar m-wells avatar muff1nman avatar muse avatar ogarcia avatar olshevskiy87 avatar pgraham avatar raimondi avatar rharriso avatar ronanguilloux avatar shadow53 avatar shlomif avatar timhughes avatar toransahu avatar ycflame avatar ynonp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-template's Issues

Plugin not working on SunOS 5

This plugin is not working on our system (SunOS 5.10)

This is the output I get when I try to apply a template (with templates_debug=1)

:Template *.c
Executing `find -L '' -maxdepth 1 -type f -name '.vim-template:*'`
No template found
Executing `find -L '/hdrs/goss/.vim/bundle/vim-template/templates/' -maxdepth 1 -type f -name '=template=*'`
No template found

The cause seems to be the find command. Apparently the version of find on this system doesn't support the -maxdepth option. If I manually run that command without the -maxdepth option, the templates are found.

Not sure if this is a common scenario. I've been using this plugin on other systems (Windows and Linux) without this issue.

Unexpected behavior when loading templates

When using TLoadCmd with a non-empty file, the file contents are not replaced with the new template, rather the template is inserted at the top of the file and then the last line is deleted of the current contents. You can see this in action just by repeating TLoadCmd several times.

I would think that a more expected result would be for the entire file to be replaced. Thoughts?

Cannot use userdefined function returning regex-unsafe characters

The following function returns a path with slash characters, unsafe for regex expansion.

let g:templates_user_variables = [['FULLPATH', 'GetFullPath']]
function GetFullPath()
    return expand('%:p')
endfunction

Although this feature was introducted with #58, it looks like there was a preexisting bug with the replacing mechanism.

Incompatable colon character for OSX systems

The colon is an invalid character for the Mac OS X systems. I cannot create any file with : in Finder. g:templates_name_prefix does not resolve the for vim-template/templates

Recommended layout to imply variable behavior

" Global lookup
let g:templates_name_prefix='=template=' 
" Immediate or parent folder lookup
let g:templates_local_name_prefix='=template=' 

This variable rearrangement would break legacy template lookups, however it would be the last as the now the global variable is now manageable by the user.


Issue Scenario

Finder list of vim-templates/templates

template/*.c
template/*.c++
template/*.cc
template/*.cmake
template/*.cpp
template/*.css
template/*.cxx
template/*.GNUmakefile
template/*.h

Bash list of vim-templates/templates

template:*.GNUmakefile 
template:*.cmake       
template:*.hs   
template:*.lhs         
template:*.mm          
template:*.robots.txt  
template:*.xml

configuration confusion

Hi! I'm trying to setup vim-template for use with vimwiki files, but I'm somewhat confused about the configuration, it's not working yet..

I would like to create

vim ~/.task/project/foo.project.wiki

with template file

~/.vim/template/project.template

and so far .vimrc config

let g:templates_directory = '~/.vim/template'
let g:templates_name_prefix = '.template.'
let g:templates_global_name_prefix = 'template:'
let g:templates_fuzzy_start = 1

with no success.. what am I doing wrong?

vim crashes when creating new files

I'm having a strange issue where anytime I try to create a new file vim crashes. For instance, when I type vim foobarnew.sh I get:

"foobarnew.sh" [New File]
[11]+  Stopped                 vim foobarnew.sh

and then if I follow it up with exit I get There are stopped jobs.
When I move vim-template out of the .vim/bundle directory everything works (except of course vim-template). I haven't added any new packages and haven't modified my vimrc for a while so I have no idea what is going on.

Just to clarify, this doesn't just happen with *.sh files, this happens with any filename, even when I don't provide an extension.

cpp templates are not working

Hi,

The cpp templates are not loaded automatically. The c works fine.

I installed the plugin using vundle and I verified that the link from "c template " to "cpp template" is not broken. If I replace the link with a copy of the file, it works perfectly.

I also tried (for checking) the command ":Template *.c" , which is working. But ":Template *.cpp" is not working.

Separate the base templates from the plugin itself

I like this plugin. Thanks for the great effort.

It would be nice if I can separate the base templates from the plugin itself so that I can change them without git conflicts when updating the plugin.

How about ~/.vim-template for the base template directory?

Different Template for same extension

Is there any configuration, to choose between different templates for same extension?
For example, when I am writing office code (say *.js), the template header should contain my office mail-id, but when I am working on my side-project it should display my personal mail-id.
This is just the case with the mail-id, I want to change many other fields.

Not work in Win7 64bit

Hi, bro, I use this plugin in Win7 64bit with Gvim7.4, a few month ago, it works very well, and then i update plugins using command :BundleUpdate, now it not work.
In dir vim-template/templates there was no files, i tried to create a new file named "=template=.c", but Win7 tells that "" was not legal in file name, so is this the reason? if so, how can i make it work?

template not recognized

There's a folder ~/.config/templates that contains a file .sh and the following vim-template setup

  let g:templates_directory = empty($XDG_CONFIG_HOME) ? expand('$HOME') . '/.config/templates' : expand('$XDG_CONFIG_HOME') . '/templates'
let g:templates_global_name_prefix = ''
let g:templates_debug = 1

However, :e t.sh gives

No template found
No template found
No template found
template: /home/enno/.config/templates/article.tex got scored: 0
template: /home/enno/.config/templates/beamer.tex got scored: 0
template: /home/enno/.config/templates/html got scored: 0
template: /home/enno/.config/templates/letter.tex got scored: 0
template: /home/enno/.config/templates/poster.tex got scored: 0
template: /home/enno/.config/templates/report.tex got scored: 0
template: /home/enno/.config/templates/tex got scored: 0
template: /home/enno/.config/templates/xml got scored: 0
template: /home/enno/.config/templates/zsh got scored: 0
No template found
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.bash got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.c got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.c++ got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.cc got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.cmake got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.cpp got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.css got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.cxx got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.f got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.f90 got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.h got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.hs got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.html got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.humans.txt got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.java got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.jl got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.js got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.lhs got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.lua got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.m got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.mk got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.ml got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.mm got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.php got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.pl got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.pls got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.pm got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.pro got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.py got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.rb got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.robots.txt got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.rs got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.sh got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.sql got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.tex got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.txt got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.xml got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.xsl got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=.zcml got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=GNUmakefile got scored: 0
template: /home/enno/.config/.vim/plugged/vim-template/templates/=template=Makefile got scored: 0
No template found

Error when load template plugin with VIM version smaller than 7.3.465

I am using Ubuntu 1204 lts with vim version.

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled May  4 2012 04:25:35)
Included patches: 1-429

I met an error to load this plugin.

Error detected while processing function <SNR>26_TLoad..<SNR>26_TFind..<SNR>26_TSearch..<SNR>26_TDirectorySearch:
line    5:
E118: Too many arguments for function: glob
E15: Invalid expression: glob(a:path . a:template_prefix . "*", 0, 1)
line    6:
E121: Undefined variable: l:templates
E15: Invalid expression: l:templates
Error detected while processing function <SNR>26_TLoad..<SNR>26_TFind..<SNR>26_TSearch..<SNR>26_TSearch..<SNR>26_TDirectorySearch:

After some googling, I found this is a same issue as tobyS/skeletons.vim#2, which is caused by glob() function updated in VIM 7.3.465.

Following diff helps to make the plugin work with old VIM. Not sure if it shall be changed for backward compatibility. I log it here if anyone else meets the same issue.

diff --git a/plugin/templates.vim b/plugin/templates.vim
index 8b441c4..3070262 100644
--- a/plugin/templates.vim
+++ b/plugin/templates.vim
@@ -169,7 +169,7 @@ function <SID>TDirectorySearch(path, template_prefix, file_name)
        let l:picked_template_score = 0

        " All template files matching
-       let l:templates = glob(a:path . a:template_prefix . "*", 0, 1)
+       let l:templates = split(glob(a:path . a:template_prefix . "*"), "\n")
        for template in l:templates
                " Make sure the template is readable
                if filereadable(template)

Unable to use custom templates

I am using Vundle to load the plugin. I am also setting the following two variables (tried setting both before and after loading of the plugin):

let g:templates_no_builtin_templates=1 <-- because I don't want it to spend time looking there
let g:templates_directory='~/.vim/code_templates' <-- this is where my templates are

In .vim/code_templates, I have a python template '=template=:.py' . When I create a new test.py file, I get these messages from debug:

Executing `find '~/.vim/code_templates/' -maxdepth 1 -type f -name '=template=*'`
template: ~/.vim/code_templates/=template=:.py got scored: 0
No template found

Also, is there a way to make it not look in current directory and parent directories? I want the plugin to look only in "g:templates_directory" that I provide. Can such a configuration option be provided?

More control over global template file name prefixes

I want to be able to have access to the shipped templates in your plugin, but I'd also like to have my own global templates that look like ~/.vim/templates/ of the form template.ext instead of =template=.ext. I just changed. For me it works fine to just change g:templates_global_name_prefix to g:templates_name_prefix on line 516 and just change g:templates_name_prefix in my .vimrc, but it might be better to just prevent g:templates_global_name_prefix from setting the expected prefix for the shipped templates since we don't need to change file names of your shipped templates.

Filename globbing has issues with extensions that have multiple matches

Basically, the current filename globbing we use doesn't handle matches well when one match is a longer string that contains another match at the end. This issue can be seen with the .txt template and the .robots.txt template. Attempting to create a new text file with:

vim foo.txt

Results in the following errors:

Error detected while processing function <SNR>61_TLoad:
line   12:
E77: Too many file names

I'll see if I can fix this when I get the chance but if someone else could I'd really appreciate it.

Missing last line in an old file

When I use ':Template *.sh' in a file, I missing last line of it.

vim a.sh

echo 'first line'
#something
echo 'last line'

Input :Template *.sh, the file will chang to this:

#! /bin/sh
#
# a.sh
# Copyright (C) 2014 john <[email protected]>
#
# Distributed under terms of the MIT license.
#

 echo 'first line'
 #something

Where is my last line?

template comments

Is there some way that a template file could have comments, that were there for development or explanation of the template, but that was never translated to the generated file.

either a vim-style comment (which might not work great for vim-files where the commented part is desirable)

" a vim-style in-line comment

or something hopefully unique to vim-template, like

%%% this is a vim-template comment

or maybe a block-comment style, like this;

%COMMENT_START%
These are template comments,
and won't be included in the transformation
%COMMENT_END%

About search path

I'm wondering about in the current order of searching the template, if possible, one can have a more option:

old:

  1. current directory or top directory ---> 2) default temples directory in the plugin

new:

  1. current directory or top directory --->

1.5 ) one directory specify by the user, e.g. ~/.vim/mytemplates.

  1. default temples directory in the plugin

So people can change the default templates and put there and have higher rank than the default one. The way users can leave the official templates unchanged, which is easy for updating later by version control system.

Thanks,

Quan

Better method of storing per-project templates?

The whole =template.* naming scheme is a bit strange, and doesn't really make much sense. When working with certain shells, it becomes more of a pain to work with the files since you have to escape each =. I'd like to suggest different naming schemes:
.template.* makes much more sense on *nix systems since files starting with . are automatically hidden.
Or even better, including a templates or .templates folder in a project's directory. This way all of the template files can simply be stored in a single folder, making things a bit more organized and easier to manage.

trouble with too many, or too few, name elements

I'm having great success with vim-template for my primary purpose; templated taskwiki files named "foo.project.wiki", works great applying "~/.vim/templates/template.project.wiki".

what's not working, and I can't figure out why, is in making index files for that wiki, named "index.wiki". The template "template.index.wiki" isn't generating for the new file "index.wiki", I guess because the name is all suffix..

on the other side of the coin, taskwarrior sub-projects are "." delimited, like "project:foo.bar"
and so I'd like to create sub-project files
named "foo.bar.project.wiki"
and have %FILE% = 'foo.bar'
but that isn't working, generates %FILE% = 'foo', which isn't surprising, just not what I'm after..

any suggestions appreciated, thanks

integrate vim :r[ead] command with %R_file|exe%

I'm no vim expert, but it seems to me that the function of the vim :r[ead] command is similar to expanding a template variable. It would open up a whole world of "expandables", and considering vim-templete uses.. well.. vim, it only seems natural.

replace ":r" with "%R_"

The Foo File
%R_~/files/foo.txt%

is the tip of the iceberg!

Licenses

I was thinking of creating the "license" variable.

What do you think?

Update readme

Not sure how it got out of date, but it needs to be put back in date.

Plugin doesn't seem to be loaded

Hi there!

I'm getting the same issue as in #49, however the suggested fix does not seem to work for me.

When I open a new file - say, blah.c - no template is created. When I try to manually invoke the command :Template *.c, I get the following error:

E492: Not an editor command: Template *.c

The output of :echo exists(":Template") is 0.

I've also tried with other file-types, such as *.py and *.sh, but with no luck.

I've installed the plugin via Vundle, and ~/.vim/bundle/vim-template most certainly exists.

As per the above thread, I also ran vim +BundleInstall +qall.

Any suggestions on why the plugin might not be loading?

I've attached my ~/.vimrc file, as well as the output of vim --version.

Thanks in advance :)

Ben

vim_version.txt
vimrc.txt

Error detected while processing vim-template, Command too recursive

When I reload my vimrc I receive an error from template.vim

Error:

Error detected while processing /home/john/.vim/bundle/vim-template/syntax/vim-template.vim:
line   11:
E169: Command too recursive

Troubleshooting:

Reinstalling the vim-template does not resolve the issue.

cd ~/.vim/bundle
git clone git://github.com/aperezdc/vim-template.git

Commenting out lines 10-14 in vim-template/syntax/vim-template.vim will stop the vimrc reload from throwing the error

if b:vim_template_subtype != ""
    execute "runtime! syntax/" . b:vim_template_subtype . ".vim"
    unlet b:current_syntax
endif

b:vim_template_subtype is vim-template on load

Defining a New Template Directory Raises 'Illegal Variable Name' Error

When I attempt to define a new template directory using the newest version of the plugin (e.g. let g:templates_directory='~/.vim/templates' in .vimrc), I get the following error message:

Error detected while processing ~/.vim/bundle/vim-template/plugin/templates.vim:
line  455:
E461: Illegal variable name: l:directory
Press ENTER or type command to continue

I believe that this error is being caused because the variable l:directory is scoped as a local function variable when it doesn't exist in the scope of a function. Changing the scoping of this variable to be local to the script (i.e. to s:directory) fixes this error and properly sets the template directory.

Is this actually an error or am I just setting the templates directory incorrectly? If it is an error, would you like me to submit a pull request or would you rather make the correction? If not, what is the proper way to set a new templates directory?

Thanks in advance for your help.

Combining vim-template and nautilus document templates naming conventions

I am trying to unify the template files used by vim-template and those available with Nautilus "New document" context menu. I have pointed both vim-template and Nautilus to the same folder when looking for template files, but I haven't found a way of merging both naming conventions.

Nautilus wants filed to be named R\ file.R to show as "R file" in the context menu, but vim-template expects a common filename and only different extensions, say file.R.

Is there any way of specifying g:templates_global_name_prefix to achieve this? Would I need to modify every time this variable is used to create the right string by pasting the extension and a space before g:templates_global_name_prefix?

File endings in templates/, should they be .template instead?

My vim do not like to edit some files in templates/, because some addons thinks the file name determine file type. Eclim are by far the worst offender for this in my setup, making editing =template=.java very tedious. Can the files be named "c.template", instead of "template.c"?

expand %$ENV_VAR%

Here's an idea: why not make all available environment variables available for expansion, with a magic "$"?

new variable: %FDAY%

This variable transforms to the full-word day-of-the-week, ie. Wednesday.
This would be extra-good for vimwiki diary templates.

"Set default templates"

Is there a way to use only certain templates, ie: only php/html/js, on new files without deleting the other template files?

Thanks and congratulations, great plugin!

Not an editor command

I install the plugin with Vundle.But when I load *.sh template with command :Template *.sh.
vim prompt this: :Not an editor command : Template *.sh.

How to solve it?

Problem with expanding wildcards.

I installed vim-template on both OS X and Ubuntu and my Vim version is 7.4.
However, Vim cannot find the template files.
I find that the command "find -L ..." cannot be executed correctly in Vim:
2015-12-01 22 25 57
But this command is working well in my shell, so it might be Vim's problem.

So, I modify the templates.vim to disable the use of "find" and now it works temporarily.
Is there something wrong with my Vim? I think there should be another way to solve this problem.

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.