Skip to content

Commit 8fa9590

Browse files
committed
DeleteTo command
1 parent a6a01f2 commit 8fa9590

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

plugin/deleteto.vim

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,37 @@ if (exists ('g:loaded_deleteto') || &cp || (v:version < 700))
1010
endif
1111
let g:loaded_deleteto = 1
1212

13-
function! s:delete_to (start, stop, count, char)
13+
function! s:delete_to (start, stop, char, count)
1414
let l:esc_char = escape (a:char, '!\')
1515
let l:cmd = a:start . ',' . a:stop . 's!\V\^\(\[^' . l:esc_char . ']\*' . l:esc_char . '\)\{,' . a:count . '\}!!'
1616
execute l:cmd
1717
endfunction
1818

19-
function! s:go (...)
19+
function! s:go_map (...)
2020
if (a:0 == 2)
2121
let [l:start, l:stop] = [a:1, a:2]
2222
else
2323
let [l:start, l:stop] = [line ('''['), line (''']')]
2424
endif
2525

2626
let l:char = nr2char (getchar())
27-
call s:delete_to (l:start, l:stop, v:count1, l:char)
27+
call s:delete_to (l:start, l:stop, l:char, v:count1)
28+
endfunction
29+
30+
function! s:go_command (...)
31+
if (a:0 == 3)
32+
let num = 1
33+
else
34+
let num = a:4
35+
endif
36+
call s:delete_to (a:1, a:2, a:3, num)
2837
endfunction
2938

3039
function! s:set_up_mappings()
31-
nnoremap <silent> <Plug>DeleteToA :<C-U>call <SID>go (1, line ('$'))<CR>
32-
nnoremap <silent> <Plug>DeleteToL :<C-U>call <SID>go (line ('.'), line ('.'))<CR>
33-
nnoremap <silent> <Plug>DeleteToM :<C-U>set opfunc=<SID>go<CR>g@
34-
xnoremap <silent> <Plug>DeleteToV :<C-U>call <SID>go (line ('''<'), line ('''>'))<CR>
40+
nnoremap <silent> <Plug>DeleteToA :<C-U>call <SID>go_map (1, line ('$'))<CR>
41+
nnoremap <silent> <Plug>DeleteToL :<C-U>call <SID>go_map (line ('.'), line ('.'))<CR>
42+
nnoremap <silent> <Plug>DeleteToM :<C-U>set opfunc=<SID>go_map<CR>g@
43+
xnoremap <silent> <Plug>DeleteToV :<C-U>call <SID>go_map (line ('''<'), line ('''>'))<CR>
3544
3645
" Four mappings for the commands
3746
" DeleteToA all the file
@@ -49,3 +58,5 @@ endfunction
4958

5059
call s:set_up_mappings()
5160

61+
command! -range=% -nargs=+ DeleteTo call <SID>go_command (<line1>, <line2>, <f-args>)
62+

0 commit comments

Comments
 (0)