What we are looking for is to visually flash briefly the affected areas of vim editing in normal mode. For example, when editing
if (true) {
//line to be deleted
}
if we do dd
on //line to be deleted
, this affected area should be flashed before deleting, the same we can do using Vd
. What we are looking is the same effect as that of Vd
using dd
. This should work for all editing operations like c
, y
etc.
We tried mapping it with nnoremap dd Vd
to test for a single line, no luck. Not even sure, if we should map like this.
Google search did not turn up anything satisfactory. Is there any known plugin out there? Any code which can be plug into vim will be also be great
There are many things to tweak in the examples I give, but they may be a good start to solve your problem.
You can use :redraw
and :sleep
to draw the selection for a moment during the execution of a function.
Here is an example with dd
:
nmap <silent> dd :call Com_dd()<cr>
function! Com_dd() range
" Enter visual mode:
normal! V
" Select multiple lines, when there's a range:
let morelines = a:lastline - a:firstline
if morelines != 0
exe "normal! ".morelines."j"
endif
" Redraw the screen so we can see the selection:
redraw
" Sleeps 200ms:
sleep 200 m
" Delete the selected lines:
normal! d
endf
It can be called with a range, for example : 3dd
.
For commands with motions, it's a bit more tricky, but you can get close
to the desired behaviour, here is an example for the c
command:
nmap <silent> c :set opfunc=Com_c<cr>g@
function! Com_c(type)
let curpos = getpos('.')
if a:0 " Invoked from Visual mode, use gv command.
silent exe "normal! gv"
elseif a:type == 'line'
silent exe "normal! '[V']"
else
silent exe "normal! `[v`]"
endif
redraw
sleep 200 m
normal! d
startinsert
call setpos('.', curpos)
endf
This last example doesn't handle ranges, so 3cw
will not work (but c3w
will work).
See :h g@
for help about mapping an operator.
But it leads to some new problems : the .
doesn't work anymore with these commands, for example.
Another example is : the standard cw
command doesn't delete any space after the word, but my example does.
You may find some solutions about these new problems, but I don't have any, now.