" Map db and dB to using the function
" Allows a smarter db
nnoremap db :call DeleteBackWord(0)<CR>
" Allows a smarter dB
nnoremap dB :call DeleteBackWord(1)<CR>
function! DeleteBackWord(capital_mode)
" Gets the character after the cursor
let l:next_char = getline(".")[col(".")]
" Check if it's a whitespace
if l:next_char !~# '\S'
" whitespace, delete around word
if a:capital_mode == 0
call feedkeys('daw', 'n')
else
call feedkeys('daW', 'n')
endif
else
" NOT whitespace, go 1 char right, then delete backward
if a:capital_mode == 0
call feedkeys('ldb', 'n')
else
call feedkeys('ldB', 'n')
endif
endif
endfunction