Skip to content

Commit 55b6f70

Browse files
committed
Add autoload function
1 parent 88f8d6d commit 55b6f70

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

autoload/pasta.vim

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
" pasta.vim - Pasting with indentation adjusted to paste destination"
2+
" Author: Marcin Kulik <http://ku1ik.com/>
3+
" Version: 0.2
4+
5+
" Public API {{{1
6+
7+
function! pasta#normal_paste(p) "{{{2
8+
return s:NormalPasta(a:p)
9+
endfunction
10+
"}}}
11+
12+
function! pasta#visual_paste() "{{{2
13+
return s:VisualPasta()
14+
endfunction
15+
"}}}
16+
17+
function! pasta#setup() "{{{2
18+
return s:SetupPasta()
19+
endfunction
20+
"}}}
21+
22+
"}}}
23+
24+
" Private {{{1
25+
26+
function! s:NormalPasta(p)
27+
execute 'normal! ' . v:count1 . '"' . v:register . a:p
28+
29+
if getregtype() isnot# 'V'
30+
return
31+
endif
32+
33+
normal! '[V']=
34+
endfunction
35+
36+
function! s:VisualPasta()
37+
" workaround strange Vim behavior (""p is no-op in visual mode)
38+
let reg = v:register == '"' ? '' : '"' . v:register
39+
let regtype = getregtype()
40+
exe "normal! gv" . v:count1 . reg . g:pasta_paste_after_mapping
41+
42+
if visualmode() isnot# 'V' &&
43+
\regtype isnot# 'V'
44+
return
45+
endif
46+
47+
normal! '[V']=
48+
endfunction
49+
50+
function! s:SetupPasta()
51+
if exists("g:pasta_enabled_filetypes")
52+
if index(g:pasta_enabled_filetypes, &ft) == -1
53+
return
54+
endif
55+
elseif exists("g:pasta_disabled_filetypes") &&
56+
\ index(g:pasta_disabled_filetypes, &ft) != -1
57+
return
58+
endif
59+
60+
if get(g:, 'pasta_no_default_key_mappings', 0)
61+
return
62+
endif
63+
64+
if !get(g:, 'pasta_no_default_normal_key_mappings', 0)
65+
exe "nmap <buffer> " . g:pasta_paste_before_mapping . " <Plug>BeforePasta"
66+
exe "nmap <buffer> " . g:pasta_paste_after_mapping . " <Plug>AfterPasta"
67+
endif
68+
69+
if !get(g:, 'pasta_no_default_visual_key_mappings', 0)
70+
exe "xmap <buffer> " . g:pasta_paste_before_mapping . " <Plug>VisualPasta"
71+
exe "xmap <buffer> " . g:pasta_paste_after_mapping . " <Plug>VisualPasta"
72+
endif
73+
endfunction
74+
75+
"}}}
76+
77+
" vim:set sw=2 sts=2:

0 commit comments

Comments
 (0)