-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpasta.vim
80 lines (67 loc) · 2.42 KB
/
pasta.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
" pasta.vim - Pasting with indentation adjusted to paste destination"
" Author: Marcin Kulik <http://ku1ik.com/>
" Version: 0.2
if exists("g:loaded_pasta") || &cp || v:version < 700
finish
endif
let g:loaded_pasta = 1
function! s:NormalPasta(p, o)
if (getregtype() ==# "V")
exe "normal! " . a:o . "\<space>\<bs>\<esc>" . v:count1 . '"' . v:register . ']p'
" Save the `[ and `] marks (point to the last modification)
let first = getpos("'[")
let last = getpos("']")
normal! k"_dd
" Compensate the line we have just deleted
let first[1] -= 1
let last[1] -= 1
call setpos("'[", first)
call setpos("']", last)
else
exe "normal! " . v:count1 . '"' . v:register . a:p
endif
endfunction
function! s:VisualPasta()
if (visualmode() ==# "V")
if (getregtype() ==# "V")
exe "normal! gv\"_c\<space>\<bs>\<esc>" . v:count1 . '"' . v:register . ']pk"_dd'
else
exe "normal! gv\"_c\<space>\<bs>\<esc>" . v:count1 . '"' . v:register . ']p'
endif
else
" workaround strange Vim behavior (""p is no-op in visual mode)
let reg = v:register == '"' ? '' : '"' . v:register
exe "normal! gv" . v:count1 . reg . "p"
endif
endfunction
function! s:SetupPasta()
if exists("g:pasta_enabled_filetypes")
if index(g:pasta_enabled_filetypes, &ft) == -1
return
endif
elseif exists("g:pasta_disabled_filetypes") &&
\ index(g:pasta_disabled_filetypes, &ft) != -1
return
endif
exe "nmap <buffer> " . g:pasta_paste_before_mapping . " <Plug>BeforePasta"
exe "xmap <buffer> " . g:pasta_paste_before_mapping . " <Plug>VisualPasta"
exe "nmap <buffer> " . g:pasta_paste_after_mapping . " <Plug>AfterPasta"
exe "xmap <buffer> " . g:pasta_paste_after_mapping . " <Plug>VisualPasta"
endfunction
if !exists("g:pasta_disabled_filetypes")
let g:pasta_disabled_filetypes = ["python", "coffee", "markdown",
\"yaml", "slim", "nerdtree", "netrw", "startify", "ctrlp"]
endif
if !exists("g:pasta_paste_before_mapping")
let g:pasta_paste_before_mapping = 'P'
endif
if !exists("g:pasta_paste_after_mapping")
let g:pasta_paste_after_mapping = 'p'
endif
nnoremap <silent> <Plug>BeforePasta :<C-U>call <SID>NormalPasta('P', 'O')<CR>
nnoremap <silent> <Plug>AfterPasta :<C-U>call <SID>NormalPasta('p', 'o')<CR>
xnoremap <silent> <Plug>VisualPasta :<C-U>call <SID>VisualPasta()<CR>
augroup vim_pasta
au FileType * call <SID>SetupPasta()
augroup END
" vim:set sw=2 sts=2: