[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
--
Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---