mattn / vim-sonictemplate

Easy and high speed coding method
http://mattn.github.com/vim-sonictemplate
340 stars 42 forks source link

error - Template is not exists #44

Open p00f opened 4 years ago

p00f commented 4 years ago

I have created a custom template base-kickstart.java in ~/.config/nvim/templates:

import java.util.Scanner;

public class {{_name_}}{
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int T = Integer.parseInt(input.nextLine());
        for (int ks = 1; ks <= T; ks++) {
            {{_cursor_}}
        }
    input.close();
  }
}

and added

let g:sonictemplate_vim_template_dir='~/.config/nvim/templates'

to init.vim. When I create a new file (:e test.java) and then :Template and press tab, I get kickstart in the tab completion.

However when I select it, I get Template kickstart is not exists.

p00f commented 4 years ago

Copying the templates to ~/.config/nvim/plugged/vim-sonictemplate/template/java/ works fine

glepnir commented 4 years ago

This should be work let g:sonictemplate_vim_template_dir='~/.config/nvim/template' because the folder must be called template https://github.com/mattn/vim-sonictemplate/blob/ccba4d71ed2d7603542ff94643b31e1781503cba/autoload/sonictemplate.vim#L17

p00f commented 4 years ago

Nope that doesn't work

glepnir commented 4 years ago

It works for me .

yabeenico commented 3 years ago

b4acf10 2021-10-07T18:56:39+0900 Yasuhiro Matsumoto Add cmake

$ pwd
/home/myuser/.vim/sonictemplate/sh

$ ls
snip-cd.sh

$ cat snip-cd.sh
cd -P $(dirname $0)

$ vim foo.sh # not works
:echo g:sonictemplate_vim_template_dir
['~/.vim/sonictemplate']
:Template cd
Template cd is not exists.
:q

$ mv snip-cd.sh file-cd.sh

$ vim foo.sh # works?
:Template cd
cd -P $(dirname $0) 
ghost commented 2 years ago

Probably, You have to expand() like below let g:sonictemplate_vim_template_dir = expand(~/.config/nvim/templates')

ogaken-1 commented 2 years ago

I had the same error, but it solved by put template into g:sonictemplate_vim_template_dir .. '/java/'

mattn commented 2 years ago

Directory structure should be

.
└── template
    ├── _
    │   ├── file-LICENSE-apache.txt
    │   ├── file-LICENSE-mit.txt
    │   ├── file-LICENSE-pd.txt
    │   └── file-LICENSE-zlib.txt
    ├── c
    │   ├── base-main-gtk.c
    │   ├── base-main.c
    │   ├── base-socket-server.c
    │   ├── snip-comment-block.c
    │   ├── snip-for.c
    │   ├── snip-win32-formaterror.c
    │   └── wrap-if.c
    ├── changelog
    │   ├── base-section
    │   └── snip-section
    ├── clojure
    │   ├── base-main.clj
    │   └── file-project-base.clj
    ....