From 723053afd9e28b6e43e6461438ca305f9966f410 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 9 Nov 2014 12:14:44 -0500 Subject: autoload/auditory.vim: Add custom `d` operator Create a custom delete operator that plays the delete sound. NOTES: * Doesn't do `dd` * I just looked at the tcomment plugin source and realised that I should be using plugin mappings so these can be more easily overridden. Make a note to look into that. --- autoload/auditory.vim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'autoload') diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 8886ed2..cec02df 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -158,6 +158,33 @@ function! auditory#ToggleGalaxyFarFarAway() endfunction +" Operators +" ========= +nnoremap d :set opfunc=Deleteg@ +vnoremap d :call Delete(visualmode(), 1) + +function! s:Delete(type, ...) + let sel_save = &selection + let &selection = "inclusive" + let reg_save = @@ + + call auditory#Play('/Resources/Normal_Mode/Delete.wav') + + if a:0 " Invoked from Visual mode, use '< and '> marks. + silent exe "normal! `<" . a:type . "`>d" + elseif a:type == 'line' + silent exe "normal! '[V']d" + elseif a:type == 'block' + silent exe "normal! `[\`]d" + else + silent exe "normal! `[v`]d" + endif + + let &selection = sel_save + let @@ = reg_save +endfunction + + " Normal mode " =========== -- cgit v1.2.3