Solution (?) to selection bug Vim tip #38

0 views
Skip to first unread message

Marcel Korpel

unread,
Jan 11, 2008, 6:37:23 AM1/11/08
to vim...@googlegroups.com
Hello all,

As someone stated on October 13, 2006, there is a bug when using Vim
tip #38. When moving around text in 'wrap' mode using the cursor keys
like described in tip #38, you do not get out of select mode when
pressing the up/down-arrows. I think I kind of solved this problem,
but want to let someone look at it before posting it to the Wiki.

I left 'behave mswin' out of my .vimrc and made this behaviour myself:

inoremap <S-Up> <C-O>vgk
vnoremap <S-Up> gk
inoremap <S-Down> <C-O>vgj
vnoremap <S-Down> gj
inoremap <S-Left> <C-O>vh
vnoremap <S-Left> h
inoremap <S-Right> <C-O>vl
vnoremap <S-Right> l
inoremap <C-S-Left> <C-O>v<C-S-Left>
vnoremap <C-S-Left> <C-S-Left>
inoremap <C-S-Right> <C-O>v<C-S-Right>
vnoremap <C-S-Right> <C-S-Right>
inoremap <S-Home> <C-O>vg<Home>
vnoremap <S-Home> g<Home>
inoremap <S-End> <C-O>vg<Home>
vnoremap <S-End> g<End>

then I ensured we get out of select mode when pressing keys without the 'shift':

noremap <buffer> <silent> <Up> <Esc>gki
noremap <buffer> <silent> <Down> <Esc>gji
noremap <buffer> <silent> <Left> <Esc>hi
noremap <buffer> <silent> <Right> <Esc>li
noremap <buffer> <silent> <Home> <Esc>g<Home>i
noremap <buffer> <silent> <End> <Esc>g<End>i
noremap <buffer> <silent> <C-Left> <Esc><C-Left>i
noremap <buffer> <silent> <C-Right> <Esc><C-Right>i
inoremap <buffer> <silent> <Up> <C-o>gk
inoremap <buffer> <silent> <Down> <C-o>gj
inoremap <buffer> <silent> <Home> <C-o>g<Home>
inoremap <buffer> <silent> <End> <C-o>g<End>

The only drawback is that I always get in insert mode after pressing
one of the arrow keys. Moreover, this looks way too cumbersome to me,
but I can't think of something better (I'm not a programmer).

So, what do you think of this workaround? Any tips?

Thanks in advance!

Marcel

Ben Schmidt

unread,
Jan 11, 2008, 6:59:38 AM1/11/08
to vim...@googlegroups.com

It looks to me like you are confusing 'select' mode and 'visual' mode a bit here.
IMHO, when you push shift and an arrow in normal mode, you should go to visual
mode. When you push shift and an arrow in insert mode, you should go to select
mode. When you push a non-shift arrow in visual mode, you should go to normal
mode. When you push a non-shift arrow in select mode, you should go to insert
mode. There are map types tha can deal with all these different modes, and I think
you need them: xnoremap for visual only, and hnoremap for select only, and
nnoremap (note extra 'n') for normal only.

> The only drawback is that I always get in insert mode after pressing
> one of the arrow keys.

Mmm. I really think this is no good; much better to redo the mappings so they work
properly for all the modes.

> Moreover, this looks way too cumbersome to me,
> but I can't think of something better (I'm not a programmer).

If they are completely consistent you could conceivably write a loop to define
them for you. But my suspicion is that you'll need some tweaks, e.g. to handle
things at ends of lines, and to avoid the cursor moving left due to use of i and
<Esc>. In the end, they are a bunch of different functions, and although, yes,
perhaps cumbersome, listing them all individually may actually be the best bet.

> So, what do you think of this workaround? Any tips?

I think it would need to be more solid and honour the modes more to be truly useful.

Great work so far!

Cheers,

Ben.


Send instant messages to your online friends http://au.messenger.yahoo.com

Tony Mechelynck

unread,
Jan 11, 2008, 7:15:19 AM1/11/08
to vim...@googlegroups.com
Ben Schmidt wrote:
[...]

> It looks to me like you are confusing 'select' mode and 'visual' mode a bit here.
> IMHO, when you push shift and an arrow in normal mode, you should go to visual
> mode. When you push shift and an arrow in insert mode, you should go to select
> mode. When you push a non-shift arrow in visual mode, you should go to normal
> mode. When you push a non-shift arrow in select mode, you should go to insert
> mode. There are map types tha can deal with all these different modes, and I think
> you need them: xnoremap for visual only, and hnoremap for select only, and
> nnoremap (note extra 'n') for normal only.
[...]

That depends on the setting of the 'selectmode' option: I have it set to
"mouse,key" so that mouse-dragging and shift-arrows produce Select mode. For
Visual mode I hit v V or Ctrl-V

It's s[nore]map for Select-only. On ":hmap" I get:

E492: Not an editor command: hmap

See ":help map-overview".


Best regards,
Tony.
--
Numeric stability is probably not all that important when you're
guessing.

Ben Schmidt

unread,
Jan 11, 2008, 8:07:58 AM1/11/08
to vim...@googlegroups.com
> That depends on the setting of the 'selectmode' option: I have it set to
> "mouse,key" so that mouse-dragging and shift-arrows produce Select mode. For
> Visual mode I hit v V or Ctrl-V

Ah, OK. I rarely use arrows, and never use shift-arrows (in Vim) so am really
quite unaware of the ins and outs.

> It's s[nore]map for Select-only. On ":hmap" I get:

Thanks for the correction, Tony.

It seems I really should have slept last night.

Or not written emails until I'm a bit more lucid!

Grins,

Reply all
Reply to author
Forward
0 new messages