zsh-users
 help / color / mirror / code / Atom feed
* vi command line editing
@ 1998-03-24 15:14 Stephen Marley
  1998-03-24 15:46 ` Andrew Main
  0 siblings, 1 reply; 14+ messages in thread
From: Stephen Marley @ 1998-03-24 15:14 UTC (permalink / raw)
  To: zsh-users

How can I get vi command line editing to start in command mode rather
than insert mode after moving in the history with the arrow keys?  I am
using 3.0.5. 

-- 
stephen@memex.com


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: vi command line editing
  1998-03-24 15:14 vi command line editing Stephen Marley
@ 1998-03-24 15:46 ` Andrew Main
  1998-03-24 16:26   ` Stephen Marley
  0 siblings, 1 reply; 14+ messages in thread
From: Andrew Main @ 1998-03-24 15:46 UTC (permalink / raw)
  To: Stephen Marley; +Cc: zsh-users

Stephen Marley wrote:
>How can I get vi command line editing to start in command mode rather
>than insert mode after moving in the history with the arrow keys?  I am
>using 3.0.5. 

Use the arrow keys while in command mode.

-zefram


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: vi command line editing
  1998-03-24 15:46 ` Andrew Main
@ 1998-03-24 16:26   ` Stephen Marley
  1998-03-24 17:06     ` Andrew Main
  0 siblings, 1 reply; 14+ messages in thread
From: Stephen Marley @ 1998-03-24 16:26 UTC (permalink / raw)
  To: zsh-users

Quoting Andrew Main (zefram@tao.co.uk):
> Stephen Marley wrote:
> >How can I get vi command line editing to start in command mode rather
> >than insert mode after moving in the history with the arrow keys?  I am
> >using 3.0.5. 
> 
> Use the arrow keys while in command mode.

I really want to avoid having to remember to type <ESC> before issuing
some vi commands. This causes me enormous grief after years of using zsh
as I'm never sure which mode I'm in so I find myself typing 'B' or 'cw'
or 'i' when I'm in already in insert mode. It does my head in!

You see, my fingers are tuned to using the older vi's (eg SunOS's) where
movement using the arrow keys doesn't work in insert mode. To stop
spurious A's and D's (from the arrow keys escape sequences) appearing in
my text I have always map!ed the arrow keys to <esc>l or <esc>k etc so
that they take me into command mode and then move. 

Even now that I use Vim 5 I still keep these mappings because I am so
used to being in command mode after moving with the arrow keys however
there seems to be no way to make zsh behave like this.

My current bindings for the arrow keys are:

"^[[A"  history-search-backward
"^[[B"  history-search-forward
"^[[C"  forward-char
"^[[D"  backward-char

So I what I would really like, for example, is that my first typed up
arrow takes me into command mode and then does history-search-backward
regardless of my current mode. Is there any way to achieve this?

-- 
stephen@memex.com


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: vi command line editing
  1998-03-24 16:26   ` Stephen Marley
@ 1998-03-24 17:06     ` Andrew Main
  1998-03-24 18:04       ` Stephen Marley
  0 siblings, 1 reply; 14+ messages in thread
From: Andrew Main @ 1998-03-24 17:06 UTC (permalink / raw)
  To: Stephen Marley; +Cc: zsh-users

Stephen Marley wrote:
>You see, my fingers are tuned to using the older vi's (eg SunOS's) where
>movement using the arrow keys doesn't work in insert mode.

Arrow keys don't properly `work' in insert mode in *any* vi, since there
is no such thing as an insert `mode'.

>        I have always map!ed the arrow keys to <esc>l or <esc>k etc so
>that they take me into command mode and then move. 

You can do much the same thing with zsh:

bindkey -s "^[[A" "^[k"
bindkey -s "^[[B" "^[j"
bindkey -s "^[[C" "^[l"
bindkey -s "^[[D" "^[h"

bindkey -s acts like vi's map command.  The recent betas can do this
in a slightly better way, but I think this is exactly the functionality
you're looking for.

-zefram


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: vi command line editing
  1998-03-24 17:06     ` Andrew Main
@ 1998-03-24 18:04       ` Stephen Marley
  1998-03-24 18:35         ` Andrew Main
  0 siblings, 1 reply; 14+ messages in thread
From: Stephen Marley @ 1998-03-24 18:04 UTC (permalink / raw)
  To: zsh-users

Quoting Andrew Main (zefram@tao.co.uk):
> Stephen Marley wrote:
> >You see, my fingers are tuned to using the older vi's (eg SunOS's) where
> >movement using the arrow keys doesn't work in insert mode.
> 
> Arrow keys don't properly `work' in insert mode in *any* vi, since there
> is no such thing as an insert `mode'.

Why are you being so pedantic?  Should I have said `input' rather than
`insert'?  Why is it then that if I do :se showmode it says `insert'?
What's wrong with saying movement doesn't `work'?

What terminology could I have used that wouldn't have irked you? 

Anyway, there is such a thing as an insert `mode', I have the sources
from Bill Joy and Mark Horton's ex version 3 and there are plenty of
references to insert mode (it's a terminal attribute) and the Vim
sources use this term in exactly the way I do. So there! (sticks out
tongue).

Thanks for the help anyway.

-- 
stephen@memex.com


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: vi command line editing
  1998-03-24 18:04       ` Stephen Marley
@ 1998-03-24 18:35         ` Andrew Main
  1998-03-24 18:57           ` Thomas Koehler
  0 siblings, 1 reply; 14+ messages in thread
From: Andrew Main @ 1998-03-24 18:35 UTC (permalink / raw)
  To: Stephen Marley; +Cc: zsh-users

Stephen Marley wrote:
>Why are you being so pedantic?  Should I have said `input' rather than
>`insert'?  Why is it then that if I do :se showmode it says `insert'?
>What's wrong with saying movement doesn't `work'?
>
>What terminology could I have used that wouldn't have irked you? 

Sorry, I didn't mean it to be taken as a complaint.  While there can
be said to be an insert mode, it is an input-reading mode, not really
comparable to the command mode.  Movement *can't* work in insert mode,
because the insert mode is merely where a long command argument is
being read.  The versions of vi that I've seen map arrow keys in insert
mode to "^[ka" and so on, which of course doesn't work with repeat counts.

-zefram


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: vi command line editing
  1998-03-24 18:35         ` Andrew Main
@ 1998-03-24 18:57           ` Thomas Koehler
  1998-03-24 19:38             ` Andrew Main
  0 siblings, 1 reply; 14+ messages in thread
From: Thomas Koehler @ 1998-03-24 18:57 UTC (permalink / raw)
  To: zsh-users

On Tue, Mar 24, 1998 at 06:35:32PM +0000, Andrew Main wrote:

> The versions of vi that I've seen map arrow keys in insert
> mode to "^[ka" and so on,

Then you haven't seen vim yet (:-)

> which of course doesn't work with repeat counts.

How should it work with repeat counts anyways? If you enter a number in
input mode, it is inserted as text...

(anyways, in vim, you can hit ^O<count>[hjkl] for movements - in
general, you can use ^O<commandmode-command> in insertmode in vim, and
you are back in insertmode afterwards)

> -zefram

CU,
Thomas [always vimming]

-- 
    Thomas Köhler    Email:     jean-luc@picard.franken.de
        <><           WWW:    http://home.pages.de/~jeanluc/
                      IRC:               jeanluc
      LCARS --- Linux for Computers on All Real Starships


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: vi command line editing
  1998-03-24 18:57           ` Thomas Koehler
@ 1998-03-24 19:38             ` Andrew Main
  1998-03-24 20:30               ` Thomas Koehler
  0 siblings, 1 reply; 14+ messages in thread
From: Andrew Main @ 1998-03-24 19:38 UTC (permalink / raw)
  To: Thomas Koehler; +Cc: zsh-users

Thomas Koehler wrote:
>> The versions of vi that I've seen map arrow keys in insert
>> mode to "^[ka" and so on,
>
>Then you haven't seen vim yet (:-)

Ah, but vim is not vi.  Not by a long way.

>> which of course doesn't work with repeat counts.
>
>How should it work with repeat counts anyways? If you enter a number in
>input mode, it is inserted as text...

I meant a repeat count on the insert command.

-zefram


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: vi command line editing
  1998-03-24 19:38             ` Andrew Main
@ 1998-03-24 20:30               ` Thomas Koehler
  1998-03-24 22:05                 ` HPUX (was Re: vi command line editing) Shawn Leas
  0 siblings, 1 reply; 14+ messages in thread
From: Thomas Koehler @ 1998-03-24 20:30 UTC (permalink / raw)
  To: zsh-users

On Tue, Mar 24, 1998 at 07:38:27PM +0000, Andrew Main wrote:

> Thomas Koehler wrote:
> >> The versions of vi that I've seen map arrow keys in insert
> >> mode to "^[ka" and so on,
> >
> >Then you haven't seen vim yet (:-)
> 
> Ah, but vim is not vi.  Not by a long way.

Right - but when you said "versions of vi", I thought of vi-clones :)

> >> which of course doesn't work with repeat counts.
> >
> >How should it work with repeat counts anyways? If you enter a number in
> >input mode, it is inserted as text...
> 
> I meant a repeat count on the insert command.

Well, now it gets clear - right, repeated inserts don't work when moving
around with the cursor keys - even not with vim.

I don't know whether or not this should be considered a problem - cursor
keys aren't intended to be used in insertmode anyways ;-)

> -zefram

CU,
Thomas

-- 
    Thomas Köhler    Email:     jean-luc@picard.franken.de
        <><           WWW:    http://home.pages.de/~jeanluc/
                      IRC:               jeanluc
      LCARS --- Linux for Computers on All Real Starships


^ permalink raw reply	[flat|nested] 14+ messages in thread

* HPUX (was Re: vi command line editing)
  1998-03-24 20:30               ` Thomas Koehler
@ 1998-03-24 22:05                 ` Shawn Leas
  1998-03-24 23:22                   ` Shawn Leas
  1998-03-25 10:22                   ` Andrew Main
  0 siblings, 2 replies; 14+ messages in thread
From: Shawn Leas @ 1998-03-24 22:05 UTC (permalink / raw)
  To: Thomas Koehler; +Cc: zsh-users


Why is it that with HPUX I need to do

bindkey -s "^[OA" "^[ka"
bindkey -s "^[OB" "^[ja"
bindkey -s "^[OD" "^[ha"
bindkey -s "^[OC" "^[la"

instead of 

bindkey -s "^[[A" "^[ka"
bindkey -s "^[[B" "^[ja"
bindkey -s "^[[C" "^[la"
bindkey -s "^[[D" "^[ha"

???

Is it the /usr/sbin/getty?  Something with the termcap?  I dunno 'bout
these things, but I'd like to.

Shawn


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HPUX (was Re: vi command line editing)
  1998-03-24 22:05                 ` HPUX (was Re: vi command line editing) Shawn Leas
@ 1998-03-24 23:22                   ` Shawn Leas
  1998-03-25 10:22                   ` Andrew Main
  1 sibling, 0 replies; 14+ messages in thread
From: Shawn Leas @ 1998-03-24 23:22 UTC (permalink / raw)
  To: Thomas Koehler; +Cc: zsh-users


Strange, hpux 10.10 this is the case, but not 10.20.

Shawn
On Tue, 24 Mar 1998, Shawn Leas wrote:

> 
> Why is it that with HPUX I need to do
> 
> bindkey -s "^[OA" "^[ka"
> bindkey -s "^[OB" "^[ja"
> bindkey -s "^[OD" "^[ha"
> bindkey -s "^[OC" "^[la"
> 
> instead of 
> 
> bindkey -s "^[[A" "^[ka"
> bindkey -s "^[[B" "^[ja"
> bindkey -s "^[[C" "^[la"
> bindkey -s "^[[D" "^[ha"
> 
> ???
> 
> Is it the /usr/sbin/getty?  Something with the termcap?  I dunno 'bout
> these things, but I'd like to.
> 
> Shawn
> 
> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HPUX (was Re: vi command line editing)
  1998-03-24 22:05                 ` HPUX (was Re: vi command line editing) Shawn Leas
  1998-03-24 23:22                   ` Shawn Leas
@ 1998-03-25 10:22                   ` Andrew Main
  1998-03-25 16:01                     ` Dan Nelson
  1998-03-25 16:45                     ` Bart Schaefer
  1 sibling, 2 replies; 14+ messages in thread
From: Andrew Main @ 1998-03-25 10:22 UTC (permalink / raw)
  To: Shawn Leas; +Cc: thomas, zsh-users

Shawn Leas wrote:
>bindkey -s "^[OA" "^[ka"
>bindkey -s "^[OB" "^[ja"
>bindkey -s "^[OD" "^[ha"
>bindkey -s "^[OC" "^[la"

That's a terminal issue.  Some terminals send "^[OA" instead of "^[[A".
Of course, a lot of terminals send sequences completely different from
these, but zsh should probably recognise both of these sets by default.

-zefram


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HPUX (was Re: vi command line editing)
  1998-03-25 10:22                   ` Andrew Main
@ 1998-03-25 16:01                     ` Dan Nelson
  1998-03-25 16:45                     ` Bart Schaefer
  1 sibling, 0 replies; 14+ messages in thread
From: Dan Nelson @ 1998-03-25 16:01 UTC (permalink / raw)
  To: Andrew Main, Shawn Leas; +Cc: thomas, zsh-users

In the last episode (Mar 25), Andrew Main said:
> Shawn Leas wrote:
> >bindkey -s "^[OA" "^[ka"
> >bindkey -s "^[OB" "^[ja"
> >bindkey -s "^[OD" "^[ha"
> >bindkey -s "^[OC" "^[la"
> 
> That's a terminal issue.  Some terminals send "^[OA" instead of "^[[A".
> Of course, a lot of terminals send sequences completely different from
> these, but zsh should probably recognise both of these sets by default.

My soution (adjust to your needs):

# usage: bindtc <cap> <default> <zsh-command>
# Binds a termcap entry <cap> to a command.  If the termcap string does 
# not exist, use <default>
bindtc ()
{
    local keyval=$(echotc "$1" 2>&-)
    bindkey "${keyval:-$2}" "$3"
}

# Bindings for UP, DOWN, LEFT, RIGHT
bindtc ku "^[[A" up-line-or-history
bindtc kd "^[[B" down-line-or-history
bindtc kr "^[[C" forward-char
bindtc kl "^[[D" backward-char

	-Dan Nelson
	dnelson@emsphone.com


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HPUX (was Re: vi command line editing)
  1998-03-25 10:22                   ` Andrew Main
  1998-03-25 16:01                     ` Dan Nelson
@ 1998-03-25 16:45                     ` Bart Schaefer
  1 sibling, 0 replies; 14+ messages in thread
From: Bart Schaefer @ 1998-03-25 16:45 UTC (permalink / raw)
  To: zsh-users

On Mar 25, 10:22am, Andrew Main wrote:
} Subject: Re: HPUX (was Re: vi command line editing)
}
} Shawn Leas wrote:
} >bindkey -s "^[OA" "^[ka"
} >bindkey -s "^[OB" "^[ja"
} >bindkey -s "^[OD" "^[ha"
} >bindkey -s "^[OC" "^[la"
} 
} That's a terminal issue.  Some terminals send "^[OA" instead of "^[[A".

Actually, it's a keypad transmit mode issue, I think.  vt100s and their
emulators in keypad mode send the '\eO' sequences, and in standard mode
send the '\e[' sequences.  You can often see this by typing ctrl-V up
in the shell, then starting vi and typing ctrl-V up in insert mode.

Some versions of the vt100 and xterm termcap/terminfo entries always put
the terminal in keypad mode, others switch into it in the ti/te ("Begin
program that uses cursor motion") capabilities, still others never leave
standard mode.  It's really annoying, especially on e.g. Linux where the
Num Lock key controls whether the -keyboard- really is in keypad mode.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~1998-03-25 16:53 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-03-24 15:14 vi command line editing Stephen Marley
1998-03-24 15:46 ` Andrew Main
1998-03-24 16:26   ` Stephen Marley
1998-03-24 17:06     ` Andrew Main
1998-03-24 18:04       ` Stephen Marley
1998-03-24 18:35         ` Andrew Main
1998-03-24 18:57           ` Thomas Koehler
1998-03-24 19:38             ` Andrew Main
1998-03-24 20:30               ` Thomas Koehler
1998-03-24 22:05                 ` HPUX (was Re: vi command line editing) Shawn Leas
1998-03-24 23:22                   ` Shawn Leas
1998-03-25 10:22                   ` Andrew Main
1998-03-25 16:01                     ` Dan Nelson
1998-03-25 16:45                     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).