Arrow keys in edit mode

0 views
Skip to first unread message

juner

unread,
Dec 8, 2008, 11:17:29 PM12/8/08
to vim_use
Is there a way to make the arrow keys in vim/gvim act exactly like
gedit or other typical windows editors? What I want are:

1. When I press the left key, the cursor will of course move left; but
when it reach the beginning of a line, it stops, and it won't move to
the above line. Sometimes this can be quite inconvenient. However,
this problem can be partly solved by setting "set whichwrap
+=<,>,h,l" . By "partly solved", I mean this only applies to wrapped
lines; when the cursor reaches the beginning of a vim "true" line, it
won't move any more.

2. I always set vim to wrap lines automatically, which means a long
line will appear several lines in the editor. When I press the
"up"/"down" key, the cursor will move to the above or the below line.
Here the word "line" means the vim "true" line, not the apparent lines
shown on the screen. This is inconvenient to me. Even if I have set
"set whichwrap+=<,>,h,l", the performance won't change.

Is is there some settings or plugins to work this out? Thanks!

Gary Johnson

unread,
Dec 9, 2008, 2:01:57 AM12/9/08
to vim...@googlegroups.com
On 2008-12-08, juner wrote:
> Is there a way to make the arrow keys in vim/gvim act exactly like
> gedit or other typical windows editors? What I want are:
>
> 1. When I press the left key, the cursor will of course move left; but
> when it reach the beginning of a line, it stops, and it won't move to
> the above line. Sometimes this can be quite inconvenient. However,
> this problem can be partly solved by setting "set whichwrap
> +=<,>,h,l" . By "partly solved", I mean this only applies to wrapped
> lines; when the cursor reaches the beginning of a vim "true" line, it
> won't move any more.

It works fine for me using vim 7.2.22. If I execute

:set ww+=<,>

and move the cursor to any of the lines in your preceding paragraph,
the left arrow will move the cursor to the beginning of the line and
then to the end of the preceding line.

Try starting vim like this:

vim -N -u NONE -c 'set ww+=<,>' some_text_file

The left and right arrow keys should behave as you want. If they
don't, tell us which version of vim you're using, on which platform,
and exactly what behavior you're observing. If they do, then you
have something in your ~/.vimrc or in a plugin that's interfering
with the behavior of those keys.

> 2. I always set vim to wrap lines automatically, which means a long
> line will appear several lines in the editor. When I press the
> "up"/"down" key, the cursor will move to the above or the below line.
> Here the word "line" means the vim "true" line, not the apparent lines
> shown on the screen. This is inconvenient to me. Even if I have set
> "set whichwrap+=<,>,h,l", the performance won't change.

Try this:

nmap <Up> gk
nmap <Down> gj

Regards,
Gary

juner

unread,
Dec 9, 2008, 2:34:50 AM12/9/08
to vim_use
Thank you very much! I am glad that you can understand my English (I
am not an English speaker).

Your suggestions works perfectly in normal mode. However, what I
really care is the "Edit" mode (or "Insert" mode), in which case the
cursor stops at the beginning of a line when I hold down the left
arrow key. Your second suggestion reminds me to use "imap <Up>
<Esc><Esc>gkli " to make the "up" key act the way I expected.

I am using gvim 7.3.314 in ubuntu 8.10 . Maybe I need to try a new
version.

juner

unread,
Dec 9, 2008, 3:06:18 AM12/9/08
to vim_use
A mistake in my previous post: my gvim edition is 7.1.314 .

After some trial, I get the following solution:

set ww+=<,>
imap <Left> <Esc><Left>a
imap <Right> <Esc><Right>a
imap <Up> <Esc>gka
imap <Down> <Esc>gja

Maybe this looks awkward. But it seems work right now.
Thanks.

fritzophrenic

unread,
Dec 9, 2008, 9:50:54 AM12/9/08
to vim_use


On Dec 9, 2:06 am, juner <fujun...@gmail.com> wrote:
> A mistake in my previous post: my gvim edition is 7.1.314 .
>
> After some trial, I get the following solution:
>
> set ww+=<,>
> imap <Left> <Esc><Left>a
> imap <Right> <Esc><Right>a
> imap <Up> <Esc>gka
> imap <Down> <Esc>gja
>
> Maybe this looks awkward. But it seems work right now.

One suggestion:

Use <C-O> or <C-\><C-O> instead of <Esc>...a to execute the following
normal-mode command and return to insert mode automatically.

:help i_CTRL-O

Tony Mechelynck

unread,
Dec 9, 2008, 11:48:24 AM12/9/08
to vim...@googlegroups.com, Bram Moolenaar
On 09/12/08 05:17, juner wrote:
> Is there a way to make the arrow keys in vim/gvim act exactly like
> gedit or other typical windows editors? What I want are:
>
> 1. When I press the left key, the cursor will of course move left; but
> when it reach the beginning of a line, it stops, and it won't move to
> the above line. Sometimes this can be quite inconvenient. However,
> this problem can be partly solved by setting "set whichwrap
> +=<,>,h,l" . By "partly solved", I mean this only applies to wrapped
> lines; when the cursor reaches the beginning of a vim "true" line, it
> won't move any more.

Hm. In my gvim 7.2.68, when 'whichwrap' includes "h,l", hitting the h
key repeatedly moves from the start of one line to the end of the
previous one, but even when it includes "<,>", it doesn't when using
<Left> (neither in Normal nor Insert modes). OTOH, with <Right> and > it
works.

This looks like a bug to me. (Bram, what do you think?)

I checked that gvim correctly sees my left-arrow key: in Insert mode,
Ctrl-K followed by left-arrow inserts <Left> into the buffer.

>
> 2. I always set vim to wrap lines automatically, which means a long
> line will appear several lines in the editor. When I press the
> "up"/"down" key, the cursor will move to the above or the below line.
> Here the word "line" means the vim "true" line, not the apparent lines
> shown on the screen. This is inconvenient to me. Even if I have set
> "set whichwrap+=<,>,h,l", the performance won't change.
>
> Is is there some settings or plugins to work this out? Thanks!

Here, I use the following

map <Up> gk
map <Down> gj
imap <Up> <C-O>gk
imap <Down> <C-O>gj

to have <Up> and <Down> move by screen lines in both Normal and Insert
modes. In Normal mode, j and k still move by file lines.

See
:help map-overview
:help gj
:help gk
:help i_CTRL-O


Best regards,
Tony.
--
"To whoever finds this note -
I have been imprisoned by my father who wishes me to marry
against my will. Please please please please come and rescue me.
I am in the tall tower of Swamp Castle."
SIR LAUNCELOT's eyes light up with holy inspiration.
"Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD

Tony Mechelynck

unread,
Dec 9, 2008, 12:11:15 PM12/9/08
to vim...@googlegroups.com, Bram Moolenaar
On 09/12/08 17:48, Tony Mechelynck wrote:
[...]

> Hm. In my gvim 7.2.68, when 'whichwrap' includes "h,l", hitting the h
> key repeatedly moves from the start of one line to the end of the
> previous one, but even when it includes "<,>", it doesn't when using
> <Left> (neither in Normal nor Insert modes). OTOH, with<Right> and> it
> works.
>
> This looks like a bug to me. (Bram, what do you think?)
[...]

I had a spurious mapping from <Left> to <BS>, possibly set by some
plugin (but in a former session, so I don't know which plugin: ":verbose
map <Left>" answered that it was set in ~/Session.vim). Removing that
mapping cures the problem.


Best regards,
Tony.
--
"Life would be much simpler and things would get done much faster if it
weren't for other people"
-- Blore

fritzophrenic

unread,
Dec 9, 2008, 6:17:40 PM12/9/08
to vim_use
Aha!

Try :set ww=<,>,[,]

(Mine is actually set to include all the options listed at :help 'ww'
except for "~", and I do not see the problem in Windows).

< and > only work for normal and visual modes, as it says in the help.

[ and ] are the equivalent options for insert and replace modes.

Tony Mechelynck

unread,
Dec 9, 2008, 6:52:13 PM12/9/08
to vim...@googlegroups.com

I have

:set ww?
whichwrap=<,>,[,],~,s

*As I said*, I had a spurious mapping of <Left> to <BS> and unmapping
that (with no other change) cured the problem. Alternately, I could
probably have used :set ww+=b instead.


Best regards,
Tony.
--
There are three ways to get something done:
(1) Do it yourself.
(2) Hire someone to do it for you.
(3) Forbid your kids to do it.

Matt Wozniski

unread,
Dec 9, 2008, 7:10:53 PM12/9/08
to vim...@googlegroups.com
On Tue, Dec 9, 2008 at 11:48 AM, Tony Mechelynck wrote:
>
> Hm. In my gvim 7.2.68, when 'whichwrap' includes "h,l", hitting the h
> key repeatedly moves from the start of one line to the end of the
> previous one, but even when it includes "<,>", it doesn't when using
> <Left> (neither in Normal nor Insert modes). OTOH, with <Right> and > it
> works.
>
> This looks like a bug to me. (Bram, what do you think?)
>
> I checked that gvim correctly sees my left-arrow key: in Insert mode,
> Ctrl-K followed by left-arrow inserts <Left> into the buffer.

'whichwrap' needs to include "<,>" for arrow keys in normal mode, and
also needs "[,]" for arrow keys in insert mode. After doing :set
ww+=<,>,[,] it works fine for me, on vim 7.2.49 - are you sure that
you don't have some other map that's interfering?

~Matt

Matt Wozniski

unread,
Dec 9, 2008, 7:19:41 PM12/9/08
to vim...@googlegroups.com

Oops, I see that you've figured it out. GMail's threading is usually
pretty good, but the change of subject when you solved your problem
confused it, so my effort to read the full thread before replying
backfired... :)

~Matt

Tony Mechelynck

unread,
Dec 9, 2008, 8:26:51 PM12/9/08
to vim...@googlegroups.com
On 10/12/08 01:19, Matt Wozniski wrote:
[...]

> Oops, I see that you've figured it out. GMail's threading is usually
> pretty good, but the change of subject when you solved your problem
> confused it, so my effort to read the full thread before replying
> backfired... :)
>
> ~Matt

Ah, sorry. I get my mail from gmail by POP, and SeaMonkey had no problem
keeping the thread together.


Best regards,
Tony.
--
Jesus was killed by a Moral Majority.

Reply all
Reply to author
Forward
0 new messages