How to move cursor in insert mode?

146 views
Skip to first unread message

Ouyang Jiannan

unread,
Apr 7, 2009, 6:53:29 AM4/7/09
to vim...@googlegroups.com
Do I have to change to normal mode and use hjkl?
Thank you~

Tim Chase

unread,
Apr 7, 2009, 8:15:01 AM4/7/09
to vim...@googlegroups.com
> Do I have to change to normal mode and use hjkl?

Depending on the terminal/environment the answer is "probably
not". On a terminal session where your $TERM doesn't support
arrow keys then yes, you have to escape to normal mode and use
hjkl. However, if you're using gvim or a computer/TERM made
after the mid-80's, you should be able to use the arrow keys in
insert-mode. ;-)

Some gross movements (such as by word or screen) can be done in
insert-mode as well (control+left/right, home/end, pgup/dn)
though some may be limited to gvim. For some of the other
vim-specific movements, you can also use control+o ("oh", not
"zero") to temporarily enter normal mode to issue one normal-mode
command such as "%" to move to the matching paren/brace/bracket
or ")" to move to the next sentence. All your typical motions
should work here.

:help i_CTRL-O
:help motion.txt

-tim

pansz

unread,
Apr 7, 2009, 8:34:14 AM4/7/09
to vim...@googlegroups.com
Ouyang Jiannan 写道:
> Do I have to change to normal mode and use hjkl?
> Thank you~
>
> >

you can use Arrow keys: up, down, left and right.

Gene Kwiecinski

unread,
Apr 7, 2009, 11:39:12 AM4/7/09
to vim...@googlegroups.com
>Do I have to change to normal mode and use hjkl?

Uhh, yeah. Unless you actually want to *enter* [hjkl] as text...

How would you expect 'vim' to tell the difference?

Gene Kwiecinski

unread,
Apr 7, 2009, 11:44:53 AM4/7/09
to vim...@googlegroups.com
>>Do I have to change to normal mode and use hjkl?

>Uhh, yeah. Unless you actually want to *enter* [hjkl] as text...
>How would you expect 'vim' to tell the difference?

Actually, I may have misunderstood your question, do you *not* have
arrow keys on your keyboard?

If you don't, then absolutely, you need to escape to normal mode and
[hjkl] it.

If you *do*, and want to know how to use [hjkl] *instead* of arrow keys
(the question *has* come up here on several occasions, and *still*
bewilders me why someone'd ask), then no, you're out of luck. Unless
you want to 'imap' them to cursor-movements and not be able to ever type
[hjkl] as text.

The control equivalents (^H/^J/^K/^L) should still always work, 'though
I admit I haven't tried them in all modes.

Tim Chase

unread,
Apr 7, 2009, 1:15:05 PM4/7/09
to vim...@googlegroups.com
> The control equivalents (^H/^J/^K/^L) should still always work, 'though
> I admit I haven't tried them in all modes.


Just a word of caution, ^H in many consoles is the backspace, so
remapping this can cause unexpected weirdnesses.

Assuming your terminal supports alt/meta correctly, you might use
Alt/Meta + hjkl instead.

-tim

Tony Mechelynck

unread,
Apr 7, 2009, 8:38:59 PM4/7/09
to vim...@googlegroups.com

...at least if you never need accented letters.

č (small e-grave) will trigger the mapping for Alt-h
ę (small e-circumflex) will trigger the mapping for Alt-j
ë (small e-diaeresis) will trigger the mapping for Alt-k
ě (small i-grave) will trigger the mapping for Alt-l

and in general, the mapping for the Alt counterpart of any key will be
triggered by any key which produces its upper-ascii counterpart: to Vim,
Alt+nn and (nn+0x80) [where nn is a byte value, 0x00-0x7F] are synonymous.


Best regards,
Tony.
--
Any resemblance between the above views and those of my employer, my
terminal,
or the view out my window are purely coincidental. Any resemblance between
the above and my own views is non-deterministic. The question of the
existence of views in the absence of anyone to hold them is left as an
exercise for the reader. The question of the existence of the reader is
left
as an exercise for the second god coefficient. (A discussion of
non-orthogonal, non-integral polytheism is beyond the scope of this
article.)
(Ralph Jennings)

Ouyang Jiannan

unread,
Apr 8, 2009, 2:27:59 AM4/8/09
to vim...@googlegroups.com
Thanks to you all~
That's my first time to ask question here, and all of you are very nice

I'm sorry about representing my question unclear. Actually, I do have narrow keys, but I'm
wandering how to do that quickly without move my hands.

From the answering above, I think I get several solutions
1) change to normal mode, move with hjkl
2) stay in insert mode, use narrow keys and home/end, pg up/ pg dn...
3) ctrl+o in insert mode, and then input a normal mode command
4) remapping

Am I correct? I think solution 3 is handful... I'll learn that first

Thank you again

On Wed, Apr 8, 2009 at 8:38 AM, Tony Mechelynck <antoine.m...@gmail.com> wrote:

On 07/04/09 19:15, Tim Chase wrote:
>
>> The control equivalents (^H/^J/^K/^L) should still always work, 'though
>> I admit I haven't tried them in all modes.
>
>
> Just a word of caution, ^H in many consoles is the backspace, so
> remapping this can cause unexpected weirdnesses.
>
> Assuming your terminal supports alt/meta correctly, you might use
> Alt/Meta + hjkl instead.
>
> -tim

...at least if you never need accented letters.

è (small e-grave) will trigger the mapping for Alt-h
ê (small e-circumflex) will trigger the mapping for Alt-j

ë (small e-diaeresis) will trigger the mapping for Alt-k
ì (small i-grave) will trigger the mapping for Alt-l

Abhishek Gupta

unread,
Apr 8, 2009, 2:44:23 AM4/8/09
to vim...@googlegroups.com
Hi,
 
I'm sorry about representing my question unclear. Actually, I do have narrow keys, but I'm
wandering how to do that quickly without move my hands.

You could also map something like jj to <ESC>.
This would get you back to normal mode without moving your hands too much.
And then you can use h,j,k,l to move around :)

For e.g. I have the following in my vimrc:
imap jj <ESC>

Regards,
Abhishek

Ouyang Jiannan

unread,
Apr 8, 2009, 2:47:14 AM4/8/09
to vim...@googlegroups.com
imap jj <ESC>

I like it!!

Jason Axelson

unread,
Apr 8, 2009, 2:54:25 AM4/8/09
to vim...@googlegroups.com
On Tue, Apr 7, 2009 at 8:47 PM, Ouyang Jiannan <jalle...@gmail.com> wrote:
> imap jj <ESC>
>
> I like it!!

Another common binding for esc (I believe it is fully portable) is ctrl-[

Jason

Ouyang Jiannan

unread,
Apr 8, 2009, 2:58:10 AM4/8/09
to vim...@googlegroups.com
yes, I've try the ctrl+[
I didn't know it before...
Thanks

bill lam

unread,
Apr 8, 2009, 3:14:08 AM4/8/09
to vim...@googlegroups.com
On Wed, 08 Apr 2009, Ouyang Jiannan wrote:
> yes, I've try the ctrl+[
> I didn't know it before...
> Thanks
>
> On Wed, Apr 8, 2009 at 2:54 PM, Jason Axelson <boston...@gmail.com>wrote:

I swap the caplock with the esc key but not sured if it works for you.

Btw this list discourages top posting.

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩221 薛逢 宮詞
十二樓中盡曉妝 望仙樓上望君王 鎖銜金獸連環冷 水滴銅龍晝漏長
雲髻罷梳還對鏡 羅衣欲換更添香 遙窺正殿簾開處 袍褲宮人掃御床

Tony Mechelynck

unread,
Apr 8, 2009, 8:43:38 PM4/8/09
to vim...@googlegroups.com
On 08/04/09 08:27, Ouyang Jiannan wrote:
> Thanks to you all~
> That's my first time to ask question here, and all of you are very nice
>
> I'm sorry about representing my question unclear. Actually, I do have
> narrow keys, but I'm
> wandering how to do that quickly without move my hands.
>
> From the answering above, I think I get several solutions
> 1) change to normal mode, move with hjkl
> 2) stay in insert mode, use narrow keys and home/end, pg up/ pg dn...
> 3) ctrl+o in insert mode, and then input a normal mode command
> 4) remapping
>
> Am I correct? I think solution 3 is handful... I'll learn that first
>
> Thank you again

Yes, you are. Solution 3 is mostly useful when you only need to do one
Normal-mode command (or just a few); it applies to any (single)
Normal-mode command including : / and ?. Of course repeating Ctrl-O h or
Ctrl-O k several times can become a chore, but then Solution 1 comes
into play.

Solution 2 is IMHO the most useful for simple movements or combinations
of them (left/right by characters or to end of page, up/down a line, a
screenful etc.). Its drawback is that you have to move your right hand
to use it.

Solution 1 is the best if you have many Normal-mode commands to do, or
complex ones.

Solution 4 is useful if you're going to often use a given combination of
commands in the future. Due care should be given to which keys (or key
sequences) to use as the {lhs} of your mapping. In Insert mode, I
recommend F keys; in Normal mode, any key on your keyboard which
generates a character above 0x7F can also be used.

Personally I use all four, but not in the same circumstances (and not
all of them for plain left/down/up/right movements).


Best regards,
Tony.
--
The District of Columbia has a law forbidding you to exert pressure on
a balloon and thereby cause a whistling sound on the streets.

Reply all
Reply to author
Forward
0 new messages