aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--autoload/sonictemplate.vim17
-rw-r--r--plugin/sonictemplate.vim10
3 files changed, 19 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index df9d88d..d5ed5af 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,7 @@ remove-zip:
-rm sonictemplate-vim.zip
sonictemplate-vim.zip: remove-zip
+ find template -type f -exec -print | xargs dos2unix --d2u
zip -r sonictemplate-vim.zip autoload plugin doc template
release: sonictemplate-vim.zip
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim
index 26c3674..730d318 100644
--- a/autoload/sonictemplate.vim
+++ b/autoload/sonictemplate.vim
@@ -1,7 +1,7 @@
"=============================================================================
" sonictemplate.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
-" Last Change: 02-Nov-2011.
+" Last Change: 08-Nov-2011.
let s:save_cpo = &cpo
set cpo&vim
@@ -12,12 +12,12 @@ else
let s:tmpldir = expand('<sfile>:p:h:h') . '/template/'
endif
-function! sonictemplate#select() abort
+function! sonictemplate#select(mode) abort
let name = input(':Template ', '', 'customlist,sonictemplate#complete')
if name == ''
return
endif
- silent! call sonictemplate#apply(name)
+ call sonictemplate#apply(name, a:mode)
endfunction
function! sonictemplate#complete(lead, cmdline, curpos) abort
@@ -28,7 +28,7 @@ function! sonictemplate#complete(lead, cmdline, curpos) abort
endif
endfunction
-function! sonictemplate#apply(name) abort
+function! sonictemplate#apply(name, mode) abort
let buffer_is_not_empty = search('[^ \t]', 'wn')
if search('[^ \t]', 'wn')
let fs = split(globpath(join([s:tmpldir, &ft], '/'), 'snip-' . a:name . '.*'), "\n")
@@ -89,8 +89,13 @@ function! sonictemplate#apply(name) abort
silent! put! = c
endif
if stridx(c, '{{_cursor_}}') != -1
- silent! call search('{{_cursor_}}\zs', 'w')
- silent! exe "normal a".repeat("\<bs>", 12)
+ if a:mode == 'n'
+ silent! call search('\zs{{_cursor_}}', 'w')
+ silent! exe "normal ".repeat("x", 12)
+ else
+ silent! call search('{{_cursor_}}\zs', 'w')
+ call feedkeys(repeat("\<bs>", 12))
+ endif
endif
endfunction
diff --git a/plugin/sonictemplate.vim b/plugin/sonictemplate.vim
index 3a0f916..c8f320c 100644
--- a/plugin/sonictemplate.vim
+++ b/plugin/sonictemplate.vim
@@ -1,7 +1,7 @@
"=============================================================================
" File: sonictemplate.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
-" Last Change: 02-Nov-2011.
+" Last Change: 08-Nov-2011.
" Version: 0.06
" WebPage: http://github.com/mattn/sonictemplate-vim
" Description: Easy and high speed coding method
@@ -21,8 +21,12 @@ let s:save_cpo = &cpo
set cpo&vim
command! -nargs=1 -complete=customlist,sonictemplate#complete Template call sonictemplate#apply(<f-args>)
-nnoremap <c-y>t :call sonictemplate#select()<cr>
-inoremap <c-y>t <space><bs><c-\><c-o>:call sonictemplate#select()<cr>
+
+nnoremap <plug>(sonictemplate) :call sonictemplate#select('n')<cr>
+inoremap <plug>(sonictemplate) <space><bs><c-o>:call sonictemplate#select('i')<cr>
+
+nmap <unique> <c-y>t <plug>(sonictemplate)
+imap <unique> <c-y>t <plug>(sonictemplate)
let &cpo = s:save_cpo
unlet s:save_cpo