* Fwd: In Vi mode, show whether "insert" or "command" state is active
@ 2014-12-17 7:13 Jason Spiro
2014-12-17 7:58 ` Nathan Schwarz
2014-12-17 8:23 ` Bart Schaefer
0 siblings, 2 replies; 7+ messages in thread
From: Jason Spiro @ 2014-12-17 7:13 UTC (permalink / raw)
To: zsh-workers
Dear list,
Here is a feature request forwarded to you from the Debian bug
tracking system. You may also view the feature request on the Web at
<http://bugs.debian.org/772985>.
Kind regards,
~Jason Spiro
---------- Forwarded message ----------
From: Debian Bug Tracking System <http://bugs.debian.org/772985>
Date: Fri, Dec 12, 2014
Subject: Bug#772985: In Vi mode, show whether "insert" or "command"
state is active
Package: zsh
Version: 4.3.17-1
Severity: wishlist
Zsh includes a Vi emulation feature. This feature lets you use the Vi
keys at the zsh command prompt. Zsh's Vi emulation includes a
"command mode" and an "insert mode".
Zsh's Vi emulation does not show the user which mode is active. This
is frustrating and confusing. (It's like an electric oven with no
indicator to show whether the oven is on or off.)
The current state-of-the-art Vi implementation is gVim, maintained by
Bram Moolenaar. gVim provides a few indicators to tell you which mode
you're in. One of these indicators is the cursor. gVim uses a
blinking block cursor in command mode, and a blinking bar in insert
mode.
It would be very good if zsh, too, would show the user which mode was
active. You can do this any way you like. I would like it if you did
this by setting the cursor style, just as gVim does.
Here is how to set the cursor style (in supported terminals):
Set cursor to blinking bar: echo -en "\e[5 q"
Set cursor to blinking block: echo -en "\e[1 q"
The above commands definitely work in recent versions of iTerm2 (for
Mac OS) and xterm. I haven't tested them in any other terminal
emulators. Surely some terminal emulators do nothing at all in
response to the above control sequences. Luckily, since Debian is
open source, their users can submit patches to fix this.
P.S. Thank you very much for helping to maintain zsh. It's perhaps
the most featureful shell out there, and I like it.
Kind regards,
~Jason Spiro
--
Bug#772985: http://bugs.debian.org/772985
Debian Bug Tracking System
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Fwd: In Vi mode, show whether "insert" or "command" state is active
2014-12-17 7:13 Fwd: In Vi mode, show whether "insert" or "command" state is active Jason Spiro
@ 2014-12-17 7:58 ` Nathan Schwarz
2014-12-17 16:55 ` Bart Schaefer
2014-12-17 8:23 ` Bart Schaefer
1 sibling, 1 reply; 7+ messages in thread
From: Nathan Schwarz @ 2014-12-17 7:58 UTC (permalink / raw)
To: zsh-workers
This is already possible. The guys haven't read the manual.
zle-keymap-select () {
if [ $KEYMAP = vicmd ]; then
PROMPT="$(setPrompt ':')"
else
PROMPT="$(setPrompt '>')"
fi
zle reset-prompt
}
zle -N zle-keymap-select
This is my personal setup, but you can put in anything you want (obviously).
For the blinking-cursor-stuff you can use this:
zle-keymap-select () {
if [ $KEYMAP = vicmd ]; then
echo -en "\e[5 q"
else
echo -en "\e[1 q"
fi
zle reset-prompt
}
zle -N zle-keymap-select
-Nathan
Ps: Sorry for double-sending Jason, I replied to you instead of replying to the ml.
--
/"\ ASCII Ribbon Campaign
\ / - against HTML emails
X - against proprietory attachments
/ \ http://en.wikipedia.org/wiki/ASCII_Ribbon_Campaign
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Fwd: In Vi mode, show whether "insert" or "command" state is active
2014-12-17 7:13 Fwd: In Vi mode, show whether "insert" or "command" state is active Jason Spiro
2014-12-17 7:58 ` Nathan Schwarz
@ 2014-12-17 8:23 ` Bart Schaefer
1 sibling, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2014-12-17 8:23 UTC (permalink / raw)
To: Jason Spiro, zsh-workers
On Dec 17, 2:13am, Jason Spiro wrote:
}
} ---------- Forwarded message ----------
}
} Zsh's Vi emulation does not show the user which mode is active. This
} is frustrating and confusing. (It's like an electric oven with no
} indicator to show whether the oven is on or off.)
}
} It would be very good if zsh, too, would show the user which mode was
} active. You can do this any way you like. I would like it if you did
} this by setting the cursor style, just as gVim does.
Check out this thread:
http://www.zsh.org/mla/users/2013/msg00534.html
(Requires ZSH_VERSION > 5.0.3 to avoid an infinite loop bug.)
} Here is how to set the cursor style (in supported terminals):
}
} Set cursor to blinking bar: echo -en "\e[5 q"
} Set cursor to blinking block: echo -en "\e[1 q"
This should do it for you (note that I don't have a terminal that
supports the #5 cursor so this is only partly tested):
zle-keymap-select() {
case $KEYMAP in
(vicmd) print -nR $'\e[5 q';;
(viins) print -nR $'\e[1 q';;
(*) print -nR $'\e[2 q';;
esac
}
zle -N zle-keymap-select
You will also need to run zle-keymap-select from zle-line-init to
set up the cursor properly on entry to the editor.
} The above commands definitely work in recent versions of iTerm2 (for
} Mac OS) and xterm. I haven't tested them in any other terminal
} emulators. Surely some terminal emulators do nothing at all in
} response to the above control sequences.
Gnome-terminal displays garbage characters, so this is not something
one can do in general. As far as I can tell even gVim does not have
this feature built in, you have to supply some .vimrc coding.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Fwd: In Vi mode, show whether "insert" or "command" state is active
2014-12-17 7:58 ` Nathan Schwarz
@ 2014-12-17 16:55 ` Bart Schaefer
2014-12-17 18:27 ` Oliver Kiddle
0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2014-12-17 16:55 UTC (permalink / raw)
To: zsh-workers
On Dec 17, 8:58am, Nathan Schwarz wrote:
}
} zle-keymap-select () {
} if [ $KEYMAP = vicmd ]; then
} echo -en "\e[5 q"
} else
} echo -en "\e[1 q"
} fi
} zle reset-prompt
} }
} zle -N zle-keymap-select
You don't even need the reset-prompt in that case because you're echo'ng
a nonprinting sequence that causes the terminal to change the cursor
shape.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Fwd: In Vi mode, show whether "insert" or "command" state is active
2014-12-17 16:55 ` Bart Schaefer
@ 2014-12-17 18:27 ` Oliver Kiddle
0 siblings, 0 replies; 7+ messages in thread
From: Oliver Kiddle @ 2014-12-17 18:27 UTC (permalink / raw)
To: zsh-workers
Bart wrote:
>
> } zle-keymap-select () {
> } if [ $KEYMAP = vicmd ]; then
> } echo -en "\e[5 q"
> } else
> } echo -en "\e[1 q"
> } fi
> } zle reset-prompt
> } }
> } zle -N zle-keymap-select
>
> You don't even need the reset-prompt in that case because you're echo'ng
> a nonprinting sequence that causes the terminal to change the cursor
> shape.
However, you will need to ensure that the cursor is always reset when a
line is accepted. Most reliable place to do that appears to be POSTEDIT:
POSTEDIT+=$'\e[2 q'
I find the cursor shape is actually much better than the prompt (or
right prompt) for indicating the mode. Only problem is that it can be
hard to find a narrow bar style cursor in a screenful of text.
I'd also recommend configuring either the zle highlighting of the region
or the cursor to use some colour. If you take the defaults of both zsh
and most terminal emulators, the cursor is a large inverse block and the
region is highlighted in inverse video. This makes it hard to tell where
the cursor is and whether the cursor position is included in the region
or not.
Oliver
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Fwd: In Vi mode, show whether "insert" or "command" state is active
2014-12-22 0:07 Jason Spiro
@ 2014-12-22 1:57 ` Bart Schaefer
0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2014-12-22 1:57 UTC (permalink / raw)
To: zsh-workers
On Dec 21, 7:07pm, Jason Spiro wrote:
}
} I know that it's already possible. The feature request was not asking
} you to make mode indication _possible_: it was asking you to make it
} please happen _by default_. :)
And my point was that *even vim* doesn't make it happen *by default*.
You have to configure it, and it functions in a terminal-specific
manner. Attempting to build it in to the shell is just going to
result in frustration when it only works a fraction of the time.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Fwd: In Vi mode, show whether "insert" or "command" state is active
@ 2014-12-22 0:07 Jason Spiro
2014-12-22 1:57 ` Bart Schaefer
0 siblings, 1 reply; 7+ messages in thread
From: Jason Spiro @ 2014-12-22 0:07 UTC (permalink / raw)
To: zsh-workers
On Wed, Dec 17, 2014 at 2:58 AM, Nathan Schwarz <nathan@notwhite.ro> wrote:
> This is already possible.
I know that it's already possible. The feature request was not asking
you to make mode indication _possible_: it was asking you to make it
please happen _by default_. :)
You don't have to make it happen using a cursor change. You can
choose whatever method you like. May I suggest that you do things the
same way Bash's 'show-mode-in-prompt' feature does things: add a
colon to the beginning of the prompt in vicmd mode; add a plus sign in
viins mode.
> For the blinking-cursor-stuff you can use this:
> [...]
Good to know; thank you.
> Ps: Sorry for double-sending Jason, I replied to you instead of replying to the ml.
No worries.
On Wed, Dec 17, 2014 at 1:27 PM, Oliver Kiddle <okiddle@yahoo.co.uk> wrote:
> However, you will need to ensure that the cursor is always reset when a
> line is accepted. Most reliable place to do that appears to be POSTEDIT:
> POSTEDIT+=$'\e[2 q'
Thank you Oliver.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-12-22 1:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-17 7:13 Fwd: In Vi mode, show whether "insert" or "command" state is active Jason Spiro
2014-12-17 7:58 ` Nathan Schwarz
2014-12-17 16:55 ` Bart Schaefer
2014-12-17 18:27 ` Oliver Kiddle
2014-12-17 8:23 ` Bart Schaefer
2014-12-22 0:07 Jason Spiro
2014-12-22 1:57 ` 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).