How to keep selection selected

275 views
Skip to first unread message

BML

unread,
Dec 26, 2007, 10:29:15 AM12/26/07
to v...@vim.org
In visual mode, if I select 10 lines and then shift them right, they are
automatically unselected. How do I keep this selection selected?

BML

sc

unread,
Dec 26, 2007, 10:42:49 AM12/26/07
to vim...@googlegroups.com

put the following three lines in your .vimrc:

" move text and rehighlight -- vim tip_id=224
vnoremap > ><CR>gv
vnoremap < <<CR>gv

that should do what you want

--
sc

Tim Chase

unread,
Dec 26, 2007, 10:48:51 AM12/26/07
to vim...@googlegroups.com
> In visual mode, if I select 10 lines and then shift them right, they are
> automatically unselected. How do I keep this selection selected?


Well, depending on what you want, there are a couple ideas. If you just
want to continue to reindent them, you can just use the period "repeat
the last action" command which will indent them another line.

If you know how many 'shiftwidth's you want to indent, you can prefix
them with the count

3>

to indent 3 'shiftwidth's.

You can also use the "gv" command to restore the last selection no
matter what the action. If you commonly use the shifting and want to
restore, you can create mappings:

:vnoremap > >gv
:vnoremap <lt> <lt>gv

to restore visual mode after shifting.

-tim

BML

unread,
Dec 27, 2007, 9:21:12 AM12/27/07
to vim...@googlegroups.com
Thanks for the input. I was only giving the shifting as an example. I can't think of any operation on selected text where I WOULDN'T want the text to REMAIN selected.

So knowing the 'gv' command will help a lot (didn't know this one). Is there not an option in VIM to keep selected text selected after an operation? That would be the best thing for me.

Tony Mechelynck

unread,
Dec 27, 2007, 9:48:14 AM12/27/07
to vim...@googlegroups.com
BML wrote:
[...]

> Thanks for the input. I was only giving the shifting as an example. I
> can't think of any operation on selected text where I WOULDN'T want the
> text to REMAIN selected.
[...]

I can, because:

- As long as visual mode remains active, the cursor can only be at one end of
the selection.
- You cannot use operator-motion or operator-object sequences in Visual mode
(not even something as simple as dd [delete line]) because the operator (such
as d) will operate on the selection instead of on the motion or object.
- I usually want successive Visual-mode operations to operate on different
selections.
- After yanking a selection, I usually want to put that yank elsewhere: this
requires moving to some other location, then using p, P or :put in non-visual
Normal mode.

And the clincher:
- I can't see how the text could usefully remain selected after a "delete"
operation. Or do you mean further cursor movements should create a new
selection extending from the deletion to the cursor?


Best regards,
Tony.
--
"I want to buy a husband who, every week when I sit down to watch `St.
Elsewhere', won't scream, `FORGET IT, BLANCHE ... IT'S TIME FOR "HEE
HAW"!!'"
-- Berke Breathed, "Bloom County"

A.Politz

unread,
Dec 29, 2007, 6:49:30 PM12/29/07
to vim...@googlegroups.com
BML wrote:

No there isn't. If you absolutely want this
kind of feature, you can simulate it with an
autocommand.


"---------------------------
let g:autovis_enabled = 0

"Setting updatetime to this low values is
"ok, but can lead to problems with plugins,
"which, for example jump between windows.
set updatetime=100

augroup AutoVis
au!
au CursorHold * if g:autovis_enabled | exec 'normal gv' | endif
augroup END

com! -bar AutoVisOn let g:autovis_enabled = 1
com! -bar AutoVisOff let g:autovis_enabled = 0

noremap <C-V> :AutoVisOn<cr><C-V>
noremap v :AutoVisOn<cr>v
noremap V :AutoVisOn<cr>V
vnoremap <ESC> :<C-U>AutoVisOff<cr><ESC>
"---------------------------

-ap

--
Ich hab geträumt, der Krieg wär vorbei.

Reply all
Reply to author
Forward
0 new messages