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
|
" Joiner. Ability to join lines in a text object.
if ! exists('g:joiner_include_bindings')
let g:joiner_include_bindings = 1
endif
if ! exists('g:joiner_leader')
let g:joiner_leader = '<leader>+'
endif
function! s:join_text_literal(yanked, yankedtype) abort
if !exists('g:joiner_join_text')
let g:joiner_join_text = ' '
endif
return join(a:yanked, g:joiner_join_text)
endfunction
function! s:join_text_collapse(yanked, yankedtype) abort
let changed = []
if !exists('g:joiner_join_text')
let g:joiner_join_text = ' '
endif
for y in a:yanked
call add(changed, substitute(y, '^\s\+', '', 'g'))
endfor
return join(changed, g:joiner_join_text)
endfunction
function! s:joiner_do(type, ...) abort
if a:0
psilent exe "norm! gvy"
elseif a:type == 'line'
" yank the text described by the motion
silent exe "norm! '[V']y"
else
silent exe "norm! `[v`]y"
endif
let yanked = getreg('"', 1, v:true)
let yankedtype = getregtype('"')
if !exists('g:joiner_join_text')
let g:joiner_join_text = ' '
endif
let changed = [g:JoinerJoinText(yanked, yankedtype)]
call setreg('"', changed, yankedtype)
norm gvp
" Reset the yanked text to what it was originally.
call setreg('"', yanked, yankedtype)
endfunction
noremap <Plug>(joiner-leader)
\ :<C-u>let g:JoinerJoinText=function("<SID>join_text_collapse")<cr>
\:<C-u>let g:joiner_join_text=' '<cr>
\:<C-u>set operatorfunc=<SID>joiner_do<cr>
\g@
vnoremap <Plug>(joiner-leader)
\ :<C-u>let g:JoinerJoinText=function("<SID>join_text_collapse")<cr>
\:<C-u>let g:joiner_join_text=' '<cr>
\gv:<C-u>call joiner_do(visualmode(), 1)<cr>
if g:joiner_include_bindings
exec printf('nmap %s <Plug>(joiner-leader)', g:joiner_leader)
exec printf('vmap %s <Plug>(joiner-leader)', g:joiner_leader)
endif
|