zsh-users
 help / color / mirror / code / Atom feed
* getting zle vi-modes to show the current mode
@ 2006-11-13 19:27 Matt Wozniski
  2006-11-13 19:36 ` Frank Terbeck
  2006-11-14 19:13 ` Bart Schaefer
  0 siblings, 2 replies; 6+ messages in thread
From: Matt Wozniski @ 2006-11-13 19:27 UTC (permalink / raw)
  To: zsh-users

Hello all,

I'm pretty usre that if I could just get used to it, I'd like
vi-keybindings on the prompt more than emacs ones, but I keep losing
track of whether I'm in insert or command mode.  Can anyone suggest a
simple way to have zsh display the current mode under the prompt (or
in the prompt), a la vim?  I'm sure I could do it by replacing every
function in the vi-mode keymaps with something like

function my-vi-insert {
  zle -M "--INSERT--"
  zle .vi-insert
}

but I'd like to avoid the trouble if there's a better way.  :)

~Matt


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

* Re: getting zle vi-modes to show the current mode
  2006-11-13 19:27 getting zle vi-modes to show the current mode Matt Wozniski
@ 2006-11-13 19:36 ` Frank Terbeck
  2006-11-14 19:13 ` Bart Schaefer
  1 sibling, 0 replies; 6+ messages in thread
From: Frank Terbeck @ 2006-11-13 19:36 UTC (permalink / raw)
  To: zsh-users

Matt Wozniski <godlygeek@gmail.com>:
> I'm pretty usre that if I could just get used to it, I'd like
> vi-keybindings on the prompt more than emacs ones, but I keep losing
> track of whether I'm in insert or command mode.  Can anyone suggest a
> simple way to have zsh display the current mode under the prompt (or
> in the prompt), a la vim?  I'm sure I could do it by replacing every
> function in the vi-mode keymaps with something like

Check out the archives. :-)

Maybe this is what you want:
<http://www.zsh.org/mla/users/2006/msg00042.html>

Regards, Frank


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

* Re: getting zle vi-modes to show the current mode
  2006-11-13 19:27 getting zle vi-modes to show the current mode Matt Wozniski
  2006-11-13 19:36 ` Frank Terbeck
@ 2006-11-14 19:13 ` Bart Schaefer
  2006-11-15  5:30   ` Matt Wozniski
  1 sibling, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2006-11-14 19:13 UTC (permalink / raw)
  To: zsh-users

On Nov 13, 11:27am, Matt Wozniski wrote:
>
> function my-vi-insert {
>   zle -M "--INSERT--"
>   zle .vi-insert
> }

Start with this:

    function zle-keymap-select {
      zle -M "$KEYMAP"
    }
    zle -N zle-keymap-select

Tweak as desired.  Requires a fairly recent build of zsh.


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

* Re: getting zle vi-modes to show the current mode
  2006-11-14 19:13 ` Bart Schaefer
@ 2006-11-15  5:30   ` Matt Wozniski
  2006-11-16  5:19     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Matt Wozniski @ 2006-11-15  5:30 UTC (permalink / raw)
  To: zsh-users

For the purpose of the archives (that I didn't manage to search well
enough in the first place), I thought it might be a good idea to show
the solution I eventually came to.  The following will print the
current mode on the line below the prompt.  The only flaw I know of is
that a long line that wraps at the edge of the terminal will overwrite
the mode indicator until either the next line or the next mode change.

If anyone can make any suggestions for improvements, I'd be happy to hear them.

Thanks for the help, all!

--------------------------

bindkey -v

function my-accept-line {
  POSTDISPLAY=""
  zle .accept-line
}
zle -N my-accept-line
bindkey "^M" my-accept-line
bindkey "^J" my-accept-line

setopt prompt_subst;
PS1=$'%{\e7\e[${COLUMNS}G \e[K-- INSERT --\e8\e[B\e[A%}'"$PS1"
PS2=$'%{\e7\e[${COLUMNS}G \e[K-- INSERT --\e8\e[B\e[A%}'"$PS2"
PS3=$'%{\e7\e[${COLUMNS}G \e[K-- INSERT --\e8\e[B\e[A%}'"$PS3"
PS4=$'%{\e7\e[${COLUMNS}G \e[K-- INSERT --\e8\e[B\e[A%}'"$PS4"

function zle-keymap-select {
  if [[ "$KEYMAP" == vicmd ]]; then
    POSTDISPLAY=$'\n'"-- NORMAL --"
  else
    POSTDISPLAY=$'\n'"-- INSERT --"
  fi
}
zle -N zle-keymap-select


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

* Re: getting zle vi-modes to show the current mode
  2006-11-15  5:30   ` Matt Wozniski
@ 2006-11-16  5:19     ` Bart Schaefer
       [not found]       ` <17393e3e0611160622o39ebf557tcf04c56acb21155f@mail.gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2006-11-16  5:19 UTC (permalink / raw)
  To: zsh-users

On Nov 14,  9:31pm, Matt Wozniski wrote:
}
} If anyone can make any suggestions for improvements, I'd be happy to
} hear them.

How about:

    function zle-line-init zle-keymap-select {
      RPS1="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}"
      RPS2=$RPS1
      RPS3=$RPS1
      RPS4=$RPS1
      zle reset-prompt
    }
    zle -N zle-line-init
    zle -N zle-keymap-select


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

* Fwd: getting zle vi-modes to show the current mode
       [not found]       ` <17393e3e0611160622o39ebf557tcf04c56acb21155f@mail.gmail.com>
@ 2006-11-16 14:25         ` Matt Wozniski
  0 siblings, 0 replies; 6+ messages in thread
From: Matt Wozniski @ 2006-11-16 14:25 UTC (permalink / raw)
  To: zsh-users

*sigh*... two out of three times, I reply to the sender and not the
list.  My apologies, Bart.
--
I didn't know that you can define two functions at once like that...
that's kinda cool.  I was thinking about doing it that way, and it's
certainly less complicated than what I came up with, but I like the
way that no matter how many lines are being edited in the current
buffer, the indicator always appears on the line below.  Yours is
certainly more clever, and certainly more portable, but I prefer the
way mine looks.  I am still considering ways to improve upon it,
though.  Since I'm almost always running inside of a session in gnu
screen, I might just set zsh up so that the current mode appears in
the screen caption line.

Thanks for the suggestion, though!


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

end of thread, other threads:[~2006-11-16 14:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-13 19:27 getting zle vi-modes to show the current mode Matt Wozniski
2006-11-13 19:36 ` Frank Terbeck
2006-11-14 19:13 ` Bart Schaefer
2006-11-15  5:30   ` Matt Wozniski
2006-11-16  5:19     ` Bart Schaefer
     [not found]       ` <17393e3e0611160622o39ebf557tcf04c56acb21155f@mail.gmail.com>
2006-11-16 14:25         ` Fwd: " Matt Wozniski

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