是否有用于编辑的视觉闪光效果? [英] Is there visual flash effect for editing?
问题描述
我们正在寻找的是在正常模式下直观地显示 vim 编辑的受影响区域.例如编辑时
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
}
如果我们在//要删除的行
上做dd
,这个受影响的区域应该在删除前闪烁,我们可以用Vd
代码>.我们正在寻找与使用 dd
的 Vd
相同的效果.这应该适用于所有编辑操作,如 c
、y
等.
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.
我们尝试用 nnoremap dd Vd
映射它来测试单行,但没有运气.甚至不确定,我们是否应该这样映射.
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 搜索没有找到任何令人满意的结果.有没有已知的插件?任何可以插入vim的代码也会很棒
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.
您可以使用 :redraw
和 :sleep
在函数执行过程中暂时绘制选择.
You can use :redraw
and :sleep
to draw the selection for a moment during the execution of a function.
这是一个带有 dd
的例子:
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
可以带范围调用,例如:3dd
.
It can be called with a range, for example : 3dd
.
对于有动作的命令,有点棘手,但你可以接近对于所需的行为,以下是 c
命令的示例:
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
最后一个例子不处理范围,所以 3cw
不会工作(但 c3w
会工作).
This last example doesn't handle ranges, so 3cw
will not work (but c3w
will work).
有关映射运算符的帮助,请参阅 :h g@
.
See :h g@
for help about mapping an operator.
但是这会导致一些新问题:例如,.
不再适用于这些命令.另一个例子是:标准的 cw
命令不会删除单词后的任何空格,但我的例子会.
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.
这篇关于是否有用于编辑的视觉闪光效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!