zsh-workers
 help / color / mirror / code / Atom feed
* Weird Vi-mode behavior
@ 2008-11-03 12:24 Matthieu Louvel de Monceaux
  2008-11-03 12:37 ` Peter Stephenson
  0 siblings, 1 reply; 12+ messages in thread
From: Matthieu Louvel de Monceaux @ 2008-11-03 12:24 UTC (permalink / raw)
  To: zsh-workers

Hello,
I'm using zsh 4.3.9+1101.
On bash i was used to work with the vi-mode activated.
I activated it in zsh by

bindkey -v


And now it works, except one huge thing :
When we return from command mode to insert mode, we can't modify
the text from the beginning to the spot where we got insert ...
Definitely a weird behavior ...

To get it too, just type 'foo folk x' for example.
Then Esc, type 'b' to go to the previous word, then press 'i' to go 
insert mode.
Now you can't edit the 'foo ' part anymore.

Thank you by advance,
M. Louvel de Monceaux


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

* Re: Weird Vi-mode behavior
  2008-11-03 12:24 Weird Vi-mode behavior Matthieu Louvel de Monceaux
@ 2008-11-03 12:37 ` Peter Stephenson
  2008-11-03 12:56   ` Stephane Chazelas
  2008-11-03 13:12   ` Matthieu Louvel de Monceaux
  0 siblings, 2 replies; 12+ messages in thread
From: Peter Stephenson @ 2008-11-03 12:37 UTC (permalink / raw)
  To: Matthieu Louvel de Monceaux; +Cc: zsh-workers

Matthieu Louvel de Monceaux wrote:
> When we return from command mode to insert mode, we can't modify
> the text from the beginning to the spot where we got insert ...
> Definitely a weird behavior ...
> 
> To get it too, just type 'foo folk x' for example.
> Then Esc, type 'b' to go to the previous word, then press 'i' to go 
> insert mode.
> Now you can't edit the 'foo ' part anymore.

I'm sorry, I don't understand.  You're in insert mode, and you're
inserting at the "folk", right?  (That's what your description implies
with the usual key bindings.)  Then of course you won't be editing "foo
", you'll be inserting new text in front of "folk".

Do you mean you can't use the cursor key to go backward?

Do you mean you hit "b" *twice* to go back to the "foo" and you expect
to be in overwrite mode rather than insert mode so that you type over
the "foo"?

Do you mean you were expecting the effect of "I" (capital important)
which takes you to the start of the line and then puts you in insert
mode?

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


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

* Re: Weird Vi-mode behavior
  2008-11-03 12:37 ` Peter Stephenson
@ 2008-11-03 12:56   ` Stephane Chazelas
  2008-11-03 17:34     ` Matthieu Louvel de Monceaux
  2008-11-03 13:12   ` Matthieu Louvel de Monceaux
  1 sibling, 1 reply; 12+ messages in thread
From: Stephane Chazelas @ 2008-11-03 12:56 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Matthieu Louvel de Monceaux, zsh-workers

On Mon, Nov 03, 2008 at 12:37:02PM +0000, Peter Stephenson wrote:
> Matthieu Louvel de Monceaux wrote:
> > When we return from command mode to insert mode, we can't modify
> > the text from the beginning to the spot where we got insert ...
> > Definitely a weird behavior ...
> > 
> > To get it too, just type 'foo folk x' for example.
> > Then Esc, type 'b' to go to the previous word, then press 'i' to go 
> > insert mode.
> > Now you can't edit the 'foo ' part anymore.
> 
> I'm sorry, I don't understand.
[...]

I suspect he is refering to the traditional vi behavior of
vi-backward-delete-char documented in "info zsh 'Modifying
Text'"

vi-backward-delete-char (unbound) (X) (^H)
     Delete the character behind the cursor, without changing lines.
     If in insert mode, this won't delete past the point where insert
     mode was last entered.

So I suspects he wants instead:

if (($+terminfo[kbs])); then
  bindkey -M viins $terminfo[kbs] backward-delete-char
else
  bindkey -M viins '^?' backward-delete-char
  bindkey -M viins '^H' backward-delete-char
fi
(($+terminfo[kdch1])) &&
  bindkey -M viins $terminfo[kdch1] delete-char


The above trys to map the emacs-style (as opposed to vi style)
backward-delete-char to the character sent by the backspace key
(using the terminfo database if it's there, or hardcoding both
^? and ^H). It also maps delete-char to the character sent by
the delete key if the terminfo database has that information.
Note that on a number of terminals, backspace sends ^H and
delete ^? while in a number of others backspace sends ^? and
delete something else like the sequence \e[3~

-- 
Stéphane


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

* Re: Weird Vi-mode behavior
  2008-11-03 12:37 ` Peter Stephenson
  2008-11-03 12:56   ` Stephane Chazelas
@ 2008-11-03 13:12   ` Matthieu Louvel de Monceaux
  1 sibling, 0 replies; 12+ messages in thread
From: Matthieu Louvel de Monceaux @ 2008-11-03 13:12 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

Peter Stephenson wrote:
> Matthieu Louvel de Monceaux wrote:
>   
>> When we return from command mode to insert mode, we can't modify
>> the text from the beginning to the spot where we got insert ...
>> Definitely a weird behavior ...
>>
>> To get it too, just type 'foo folk x' for example.
>> Then Esc, type 'b' to go to the previous word, then press 'i' to go 
>> insert mode.
>> Now you can't edit the 'foo ' part anymore.
>>     
>
> I'm sorry, I don't understand.  You're in insert mode, and you're
> inserting at the "folk", right?  (That's what your description implies
> with the usual key bindings.)  Then of course you won't be editing "foo
> ", you'll be inserting new text in front of "folk".
>
> Do you mean you can't use the cursor key to go backward?
>
> Do you mean you hit "b" *twice* to go back to the "foo" and you expect
> to be in overwrite mode rather than insert mode so that you type over
> the "foo"?
>
> Do you mean you were expecting the effect of "I" (capital important)
> which takes you to the start of the line and then puts you in insert
> mode?
>
>   
Maybe I badly explained, sorry maybe the fault of my english.

I mean when I'm inserting at 'folk', I can't backspace in 'foo ' anymore.
I can of course use the arrow keys to move the cursor, but backspace has 
no effect.
Anywhere else the backspace key works properly.

Cheers,
M. Louvel de Monceaux


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

* Re: Weird Vi-mode behavior
  2008-11-03 12:56   ` Stephane Chazelas
@ 2008-11-03 17:34     ` Matthieu Louvel de Monceaux
  2008-11-03 17:38       ` Mikael Magnusson
  2008-11-03 17:39       ` Peter Stephenson
  0 siblings, 2 replies; 12+ messages in thread
From: Matthieu Louvel de Monceaux @ 2008-11-03 17:34 UTC (permalink / raw)
  To: Peter Stephenson, Stephane Chazelas, zsh-workers

Stephane Chazelas wrote:
> On Mon, Nov 03, 2008 at 12:37:02PM +0000, Peter Stephenson wrote:
>   
>> Matthieu Louvel de Monceaux wrote:
>>     
>>> When we return from command mode to insert mode, we can't modify
>>> the text from the beginning to the spot where we got insert ...
>>> Definitely a weird behavior ...
>>>
>>> To get it too, just type 'foo folk x' for example.
>>> Then Esc, type 'b' to go to the previous word, then press 'i' to go 
>>> insert mode.
>>> Now you can't edit the 'foo ' part anymore.
>>>       
>> I'm sorry, I don't understand.
>>     
> [...]
>
> I suspect he is refering to the traditional vi behavior of
> vi-backward-delete-char documented in "info zsh 'Modifying
> Text'"
>
> vi-backward-delete-char (unbound) (X) (^H)
>      Delete the character behind the cursor, without changing lines.
>      If in insert mode, this won't delete past the point where insert
>      mode was last entered.
>
> So I suspects he wants instead:
>
> if (($+terminfo[kbs])); then
>   bindkey -M viins $terminfo[kbs] backward-delete-char
> else
>   bindkey -M viins '^?' backward-delete-char
>   bindkey -M viins '^H' backward-delete-char
> fi
> (($+terminfo[kdch1])) &&
>   bindkey -M viins $terminfo[kdch1] delete-char
>
>
> The above trys to map the emacs-style (as opposed to vi style)
> backward-delete-char to the character sent by the backspace key
> (using the terminfo database if it's there, or hardcoding both
> ^? and ^H). It also maps delete-char to the character sent by
> the delete key if the terminfo database has that information.
> Note that on a number of terminals, backspace sends ^H and
> delete ^? while in a number of others backspace sends ^? and
> delete something else like the sequence \e[3~
>
>   
Thank you for your nice piece of information.
You want me to put those bindings in my zshrc file ?

But i don't understand that :

(($+terminfo[kdch1])) &&

You said that it maps delete-char to the char sent by the delete key.
Is it the role of the '&&' ?


M. Louvel de Monceaux


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

* Re: Weird Vi-mode behavior
  2008-11-03 17:34     ` Matthieu Louvel de Monceaux
@ 2008-11-03 17:38       ` Mikael Magnusson
  2008-11-03 17:45         ` Matthieu Louvel de Monceaux
  2008-11-03 17:39       ` Peter Stephenson
  1 sibling, 1 reply; 12+ messages in thread
From: Mikael Magnusson @ 2008-11-03 17:38 UTC (permalink / raw)
  To: Matthieu Louvel de Monceaux; +Cc: Stephane Chazelas, zsh-workers

2008/11/3 Matthieu Louvel de Monceaux <glory69@gmail.com>:
> Thank you for your nice piece of information.
> You want me to put those bindings in my zshrc file ?
>
> But i don't understand that :
>
> (($+terminfo[kdch1])) &&
>
> You said that it maps delete-char to the char sent by the delete key.
> Is it the role of the '&&' ?

a && b is like if a; then b; fi, but shorter, and only works if b is a
single statement (or is in {}, but then you're better off with an if
probably).

-- 
Mikael Magnusson


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

* Re: Weird Vi-mode behavior
  2008-11-03 17:34     ` Matthieu Louvel de Monceaux
  2008-11-03 17:38       ` Mikael Magnusson
@ 2008-11-03 17:39       ` Peter Stephenson
  1 sibling, 0 replies; 12+ messages in thread
From: Peter Stephenson @ 2008-11-03 17:39 UTC (permalink / raw)
  To: Matthieu Louvel de Monceaux; +Cc: zsh-workers

Matthieu Louvel de Monceaux wrote:
> Stephane Chazelas wrote:
> Thank you for your nice piece of information.
> You want me to put those bindings in my zshrc file ?
> 
> But i don't understand that :
> 
> (($+terminfo[kdch1])) &&
> 
> You said that it maps delete-char to the char sent by the delete key.
> Is it the role of the '&&' ?

That's not the important bit, which is the "bindkey" statement.
Stephane's suggestion checks if there is information about what
the "delete" key outputs, and if there is, it rebinds that.  Assuming
you're using ^h or ^? for backward delete, the two key lines are the

  bindkey -M viins '^?' backward-delete-char
  bindkey -M viins '^H' backward-delete-char

The test above those attempts to see which of the two possibilities the
"backspace" key is sending.  Typically, the two lines above will be
fine.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


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

* Re: Weird Vi-mode behavior
  2008-11-03 17:38       ` Mikael Magnusson
@ 2008-11-03 17:45         ` Matthieu Louvel de Monceaux
  2008-11-03 17:50           ` Mikael Magnusson
  0 siblings, 1 reply; 12+ messages in thread
From: Matthieu Louvel de Monceaux @ 2008-11-03 17:45 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Stephane Chazelas, zsh-workers

Mikael Magnusson wrote:
> 2008/11/3 Matthieu Louvel de Monceaux <glory69@gmail.com>:
>   
>> Thank you for your nice piece of information.
>> You want me to put those bindings in my zshrc file ?
>>
>> But i don't understand that :
>>
>> (($+terminfo[kdch1])) &&
>>
>> You said that it maps delete-char to the char sent by the delete key.
>> Is it the role of the '&&' ?
>>     
>
> a && b is like if a; then b; fi, but shorter, and only works if b is a
> single statement (or is in {}, but then you're better off with an if
> probably).
>
>   
Indeed that sounds logical.
Same thing than

if (($+terminfo[kdch1])); then
    bindkey -M viins $terminfo[kdch1] delete-char
fi

If I well understood.

Anyway, I would like to know the reason of that vi-mode behavior,
different from both vi editor and bash vi-mode behaviours ... maybe
you could make me understand about that.


M. Louvel de Monceaux


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

* Re: Weird Vi-mode behavior
  2008-11-03 17:45         ` Matthieu Louvel de Monceaux
@ 2008-11-03 17:50           ` Mikael Magnusson
  2008-11-03 17:55             ` Matthieu Louvel de Monceaux
  0 siblings, 1 reply; 12+ messages in thread
From: Mikael Magnusson @ 2008-11-03 17:50 UTC (permalink / raw)
  To: Matthieu Louvel de Monceaux; +Cc: Stephane Chazelas, zsh-workers

2008/11/3 Matthieu Louvel de Monceaux <glory69@gmail.com>:
> Indeed that sounds logical.
> Same thing than
>
> if (($+terminfo[kdch1])); then
>   bindkey -M viins $terminfo[kdch1] delete-char
> fi
>
> If I well understood.

yep.

> Anyway, I would like to know the reason of that vi-mode behavior,
> different from both vi editor and bash vi-mode behaviours ... maybe
> you could make me understand about that.

It is not different from the vi editor. If you have the string "Hello
there" in vi, and the cursor is on the t in there and you enter insert
mode, then you cannot backspace further left than that. Maybe you are
used to vim where the default in many distros (probably) is to allow
backspacing past this point. You can ":set compatible" to get the
original vi behaviour.

-- 
Mikael Magnusson


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

* Re: Weird Vi-mode behavior
  2008-11-03 17:50           ` Mikael Magnusson
@ 2008-11-03 17:55             ` Matthieu Louvel de Monceaux
  2008-11-03 23:09               ` Matt Wozniski
  0 siblings, 1 reply; 12+ messages in thread
From: Matthieu Louvel de Monceaux @ 2008-11-03 17:55 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Stephane Chazelas, zsh-workers

Mikael Magnusson wrote:
> 2008/11/3 Matthieu Louvel de Monceaux <glory69@gmail.com>:
>   
>> Indeed that sounds logical.
>> Same thing than
>>
>> if (($+terminfo[kdch1])); then
>>   bindkey -M viins $terminfo[kdch1] delete-char
>> fi
>>
>> If I well understood.
>>     
>
> yep.
>
>   
>> Anyway, I would like to know the reason of that vi-mode behavior,
>> different from both vi editor and bash vi-mode behaviours ... maybe
>> you could make me understand about that.
>>     
>
> It is not different from the vi editor. If you have the string "Hello
> there" in vi, and the cursor is on the t in there and you enter insert
> mode, then you cannot backspace further left than that. Maybe you are
> used to vim where the default in many distros (probably) is to allow
> backspacing past this point. You can ":set compatible" to get the
> original vi behaviour.
>
>   
You're right.
I got confused by too-much of Vim :)
The keybindings given up there will make sense for me.
Thanks all.

M. Louvel de Monceaux


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

* Re: Weird Vi-mode behavior
  2008-11-03 17:55             ` Matthieu Louvel de Monceaux
@ 2008-11-03 23:09               ` Matt Wozniski
  2008-11-04  0:50                 ` Matthieu Louvel de Monceaux
  0 siblings, 1 reply; 12+ messages in thread
From: Matt Wozniski @ 2008-11-03 23:09 UTC (permalink / raw)
  To: zsh-workers

On Mon, Nov 3, 2008 at 12:55 PM, Matthieu Louvel de Monceaux wrote:
> Mikael Magnusson wrote:
>
>> 2008/11/3 Matthieu Louvel de Monceaux:
>>
>>> Anyway, I would like to know the reason of that vi-mode behavior,
>>> different from both vi editor and bash vi-mode behaviours ... maybe
>>> you could make me understand about that.
>>>
>>
>> It is not different from the vi editor. If you have the string "Hello
>> there" in vi, and the cursor is on the t in there and you enter insert
>> mode, then you cannot backspace further left than that. Maybe you are
>> used to vim where the default in many distros (probably) is to allow
>> backspacing past this point. You can ":set compatible" to get the
>> original vi behaviour.
>
> You're right.
> I got confused by too-much of Vim :)
> The keybindings given up there will make sense for me.
> Thanks all.

FWIW, Vim behaves the same way unless you change the 'backspace'
option to a non-default value.  Your distro may change it, but Vim
ships with this option set to Vi-compatible behavior in both
compatible and non-compatible modes.

~Matt


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

* Re: Weird Vi-mode behavior
  2008-11-03 23:09               ` Matt Wozniski
@ 2008-11-04  0:50                 ` Matthieu Louvel de Monceaux
  0 siblings, 0 replies; 12+ messages in thread
From: Matthieu Louvel de Monceaux @ 2008-11-04  0:50 UTC (permalink / raw)
  To: Matt Wozniski; +Cc: zsh-workers

Matt Wozniski wrote:
> On Mon, Nov 3, 2008 at 12:55 PM, Matthieu Louvel de Monceaux wrote:
>   
>> Mikael Magnusson wrote:
>>
>>     
>>> 2008/11/3 Matthieu Louvel de Monceaux:
>>>
>>>       
>>>> Anyway, I would like to know the reason of that vi-mode behavior,
>>>> different from both vi editor and bash vi-mode behaviours ... maybe
>>>> you could make me understand about that.
>>>>
>>>>         
>>> It is not different from the vi editor. If you have the string "Hello
>>> there" in vi, and the cursor is on the t in there and you enter insert
>>> mode, then you cannot backspace further left than that. Maybe you are
>>> used to vim where the default in many distros (probably) is to allow
>>> backspacing past this point. You can ":set compatible" to get the
>>> original vi behaviour.
>>>       
>> You're right.
>> I got confused by too-much of Vim :)
>> The keybindings given up there will make sense for me.
>> Thanks all.
>>     
>
> FWIW, Vim behaves the same way unless you change the 'backspace'
> option to a non-default value.  Your distro may change it, but Vim
> ships with this option set to Vi-compatible behavior in both
> compatible and non-compatible modes.
>
> ~Matt
>
>   
Indeed I changed it by

set backspace=indent,eol,start

where start is actually the one needed to backspace further left
the spot where we entered the insert mode.

Cheers,


M. Louvel de Monceaux


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

end of thread, other threads:[~2008-11-04  0:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-03 12:24 Weird Vi-mode behavior Matthieu Louvel de Monceaux
2008-11-03 12:37 ` Peter Stephenson
2008-11-03 12:56   ` Stephane Chazelas
2008-11-03 17:34     ` Matthieu Louvel de Monceaux
2008-11-03 17:38       ` Mikael Magnusson
2008-11-03 17:45         ` Matthieu Louvel de Monceaux
2008-11-03 17:50           ` Mikael Magnusson
2008-11-03 17:55             ` Matthieu Louvel de Monceaux
2008-11-03 23:09               ` Matt Wozniski
2008-11-04  0:50                 ` Matthieu Louvel de Monceaux
2008-11-03 17:39       ` Peter Stephenson
2008-11-03 13:12   ` Matthieu Louvel de Monceaux

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).