autocmd FileType cpp nnoremap <buffer> C ct;
autocmd FileType cpp nnoremap <buffer> D dt;
These two are quite useful, but sometimes there is no ;
after the cursor and then D
doesn't do anything. And then I have to press 3 keys to delete t$
. (!)
How to check if the last action (i.e. Dt;
) didn't change anything, and in that case, execute something else (Dt$
)?
or
How how to check if there's a semicolon after the cursor and do Dt;
, otherwise Dt$
?
D
instead ofd$
; it's alllmost possible to do withd/;\|$
but the end-of-line matching is a bit weird. "Delete to end of line" does exactly that, "delete to (search end of line)" leaves the last character. – TessellatingHeckler Jul 9 '16 at 17:24x
to the mapping after the search, it will delete the last character, too. And, in order not to delete the;
, if matched, you'll use lookahead. I think you should write this as an answer. – Al.G. Jul 9 '16 at 18:02