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
|
" Function for the operatorfunc with joiner.
function! joiner#do(type, ...) abort
if a:0
silent 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('"')
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
function! joiner#join_with_string(yanked, yanktype) abort
let join_string = input('> ')
return join(map(a:yanked, "substitute(v:val, '^\\s\\+', '', '')"), join_string)
endfunction
function! joiner#join_with_string_literal(yanked, yanktype) abort
let join_string = input('> ')
return join(a:yanked, join_string)
endfunction
function! joiner#default_join(yanked, yanktype) abort
return join(map(a:yanked, "substitute(v:val, '^\\s\\+', '', '')"), ' ')
endfunction
|