Skip to content

Instantly share code, notes, and snippets.

@YasuakiHirano
Last active January 22, 2016 07:40
Show Gist options
  • Save YasuakiHirano/937063bff18f6e18eca8 to your computer and use it in GitHub Desktop.
Save YasuakiHirano/937063bff18f6e18eca8 to your computer and use it in GitHub Desktop.
"-nargas = 0 引数なし
"-nargas = 1 1個の引数
"-nargas = * 複数
"-nargas = ? 0 or 1
command! -nargs=0 JsTemp call s:JsTemp()
command! -nargs=0 ClangTemp call s:ClangTemp()
command! -nargs=0 PhpTemp call s:PhpTemp()
command! -nargs=* SqlTemp call s:SqlTemp(<f-args>)
" @brief:Jsテンプレ出力
function! s:JsTemp()
set paste
let input = "<html>\n".
\" <head>\n".
\" <meta charset='utf-8' />\n".
\" <script>\n".
\" function main(){\n".
\" }\n".
\" </script>\n".
\" </head>\n".
\" <body onload='main()'>\n".
\" </body>\n".
\"</html>"
let pos = getpos(".")
execute ":normal a" . input
call setpos('.', pos)
set nopaste
endfunction
" @brief:Cテンプレ出力
function! s:ClangTemp()
set paste
let input = "#include<stdio.h>\n".
\"\n".
\"int main(void){\n".
\" printf('hello');\n".
\" return 0;\n".
\"}\n"
let pos = getpos(".")
execute ":normal a" . input
call setpos('.', pos)
set nopaste
endfunction
" @brief:PHPテンプレ出力
function! s:PhpTemp()
set paste
let input = "<?php\n".
\" echo 'hello'; \n".
\"\n"
let pos = getpos(".")
execute ":normal a" . input
call setpos('.', pos)
set nopaste
endfunction
" @brief:SQL文を引数から作成してくれる
" @param: str 文字列
" @param: num 最大値
function! s:SqlTemp(case, ...)
set paste
let input = ""
if a:case == "s"
"a:0 に引数の数が入る
if 1 == a:0
let input = "select * from ".a:1." where column1 = 1 \n"
else
if 2 == a:0
let input = "select * from ".a:1." where ".a:2." \n"
else
let input = "select * from hoge where column1 = 1 \n"
endif
endif
endif
if a:case == "u"
if 1 == a:0
let input = "update ".a:1." set column1 = '' where column2 = 1 \n"
else
if 2 == a:0
let input = "update ".a:1." set ".a:2." where column2 = 1 \n"
else
if 3 == a:0
let input = "update ".a:1." set ".a:2." where ".a:3." \n"
else
let input = "update hoge set column1 = '' where column2 = 1 \n"
endif
endif
endif
endif
if a:case == "d"
if 1 == a:0
let input = "delete from ".a:1." where column2 = 1 \n"
else
if 2 == a:0
let input = "delete from ".a:1." where ".a:2." \n"
else
let input = "delete from hoge where column2 = 1 \n"
endif
endif
endif
let pos = getpos(".")
execute ":normal a" . input
call setpos('.', pos)
set nopaste
endfunction
" @brief:文字列に連番を付ける
" @param: str 文字列
" @param: num 最大値
function! s:StrCnt(str, num)
let i = 0
let input = ""
while i < a:num
let input .= a:str.i."\n"
let i = i + 1
endwhile
let pos = getpos(".")
execute ":normal a" . input
call setpos('.', pos)
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment