[email protected] schrieb:
> Andy Wokula <[email protected]> [09-11-09 18:13]:
>> [email protected] schrieb:
>>> Hi,
>>>
>>> is it possible to make a visual selection permament
>>> that way, that only a specific command will un-visual
>>> the block?
>>>
>>> Currently the visual block is unhighlighted after one has
>>> -- for example -- entered the wrong :s//-command.
>>>
>>> Would be nice, if the block remains highlighted after
>>> such an error... ;)
>>>
>>> Best regards,
>>> mcc
>> The following code lets the ":" command remember if Visual mode was
>> active. The next c_<Enter> will then restore the Visual area just
>> before (!) executing the Command-line.
>>
>> This is the first version. The code could be greatly simplified by just
>> deciding if "<CR>gv" or "<CR>" is to be executed, but then the Visual
>> area will not be restored after an error (produced by the Ex command).
>>
>>
>> " map ":" and "c_<CR>":
>> map : <Plug>KeepVisAreaSave
>> ounmap :
>> sunmap :
>> cmap <CR> <Plug>KeepVisAreaRestore
>>
>> let s:wasvisual = 0
>>
>> " Save:
>> no <expr> <Plug>KeepVisAreaSave <sid>RememberVisual(mode())
>>
>> func! <sid>RememberVisual(mode)
>> let s:wasvisual = a:mode =~ "[vV\<C-V>]"
>> return ":"
>> endfunc
>>
>> " Restore:
>> cno <expr><script> <Plug>KeepVisAreaRestore
>> \ getcmdtype()==":" ? "<SID>ExpandAbbr<SID>DoGv<CR>" : "<CR>"
>>
>> cmap <SID>ExpandAbbr <Space><BS>
>> cno <silent> <SID>DoGv <C-R>=<sid>DoGv()<CR>
>>
>> func! <sid>DoGv()
>> if s:wasvisual
>> normal! gv
>> endif
>> return ""
>> endfunc
> Thank you for the scripts! I will test them and see what I can use!
> Thanks a lot!
> Kind regards,
> mcc
Improved (and shorter) version:
xmap : <Plug>KeepVisArea
vno <script> <Plug>KeepVisArea :<SID>DoGv
cno <silent> <SID>DoGv <C-R>=<sid>DoGv()<CR>
func! <sid>DoGv()
normal! gv
if line(".") != line("'>")
normal! o
endif
return ""
endfunc
Makes sure the cursor is at the end of the selection before executing an
Ex-command (otherwise maybe only one line will be left selected
afterwards).
Now even c_<Esc> will keep the Visual area.
Will still not work if a command leaves the cursor at the start of the
Visual selection (but that is unlikely).
--
Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---