From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8794 invoked from network); 16 Feb 2002 17:48:52 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 16 Feb 2002 17:48:52 -0000 Received: (qmail 24730 invoked by alias); 16 Feb 2002 17:48:40 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 4680 Received: (qmail 24719 invoked from network); 16 Feb 2002 17:48:39 -0000 Date: Sat, 16 Feb 2002 18:48:05 +0100 From: Thomas =?iso-8859-1?Q?K=F6hler?= To: zsh-users@sunsite.dk Subject: Re: vim-a-like vi mode status bar Message-ID: <20020216174804.GA11720@picard.franken.de> Mail-Followup-To: zsh-users@sunsite.dk References: <20020216172000.GA892@stu163.keble.ox.ac.uk> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="sHrvAb52M6C8blB9" Content-Disposition: inline In-Reply-To: <20020216172000.GA892@stu163.keble.ox.ac.uk> User-Agent: Mutt/1.3.27i X-Operating-System: Linux picard 2.4.7 X-Editor: VIM - Vi IMproved 6.0 http://www.vim.org/ X-IRC: tirc; Nick: jeanluc X-URL: http://jeanluc-picard.de/ --sHrvAb52M6C8blB9 Content-Type: multipart/mixed; boundary="UHN/qo2QbUvPLonB" Content-Disposition: inline --UHN/qo2QbUvPLonB Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, Ian Lynagh wrote [020216 18:28]: > Hi all >=20 > I have thought it would be nice to have a vim-a-like indicator of > whether or not you are insert or command mode when using the vi line > editting mode for a long time now. In a burst of enthusiasm I have put > something together over the last couple of days (attached). However it's > not quite as nice as it might have been and I have run into a few > annoyances along the way. Well, I use something similar. Of course, I have a multiline prompt, so what I have here might work for you, but it might need some adjustment - the escape sequences for moving the cursor might not work for your type of terminal... Ciao, Thomas --=20 Thomas K=F6hler Email: jean-luc@picard.franken.de | LCARS - Linux <>< WWW: http://jeanluc-picard.de | for Computers IRC: jeanluc | on All Real PGP public key available from Homepage! | Starships --UHN/qo2QbUvPLonB Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename="zshrc.showmode" Content-Transfer-Encoding: quoted-printable # vi keybindings bindkey -v bindkey -M vicmd "^R" redo bindkey -M vicmd "u" undo bindkey -M vicmd "ga" what-cursor-position unsetopt promptcr redisplay() { builtin zle .redisplay ( true ; show_mode "INSERT") &! } redisplay2() { builtin zle .redisplay (true ; show_mode "NORMAL") &! } zle -N redisplay zle -N redisplay2 bindkey -M viins "^X^R" redisplay bindkey -M vicmd "^X^R" redisplay2 screenclear () { echo -n "\033[2J\033[400H" builtin zle .redisplay (true ; show_mode "INSERT") &! } zle -N screenclear bindkey "=0C" screenclear screenclearx () { repeat 2 print=20 local MYLINE=3D"$LBUFFER$RBUFFER" highlight $MYLINE repeat 4 print=20 builtin zle redisplay } zle -N screenclearx bindkey "^Xl" screenclearx show_mode() { local COL local x COL=3D$[COLUMNS-3] COL=3D$[COL-$#1] x=3D$(echo $PREBUFFER | wc -l ) x=3D$[x+1] echo -n "=1B7=1B[$x;A=1B[0;G" echo -n "" echo -n "=1B[0;37;44m--$1--=1B[0m" echo -n "=1B8" } zmodload zsh/parameter ### vi-add-eol (unbound) (A) (unbound) ### Move to the end of the line and enter insert mode. vi-add-eol() { show_mode "INSERT" builtin zle .vi-add-eol } zle -N vi-add-eol bindkey -M vicmd "A" vi-add-eol ### vi-add-next (unbound) (a) (unbound) ### Enter insert mode after the current cursor posi=AD ### tion, without changing lines. vi-add-next() { show_mode "INSERT" builtin zle .vi-add-next # OLDLBUFFER=3D$LBUFFER # OLDRBUFFER=3D$RBUFFER # NNUMERIC=3D$NUMERIC # bindkey -M viins "=1B" vi-cmd-mode-a } zle -N vi-add-next bindkey -M vicmd "a" vi-add-next ### vi-change (unbound) (c) (unbound) ### Read a movement command from the keyboard, and kill ### from the cursor position to the endpoint of the ### movement. Then enter insert mode. If the command ### is vi-change, change the current line. vi-change() { show_mode "INSERT" builtin zle .vi-change } zle -N vi-change bindkey -M vicmd "c" vi-change ### vi-change-eol (unbound) (C) (unbound) ### Kill to the end of the line and enter insert mode. vi-change-eol() { show_mode "INSERT" builtin zle .vi-change-eol } zle -N vi-change-eol bindkey -M vicmd "C" vi-change-eol ### vi-change-whole-line (unbound) (S) (unbound) ### Kill the current line and enter insert mode. vi-change-whole-line() { show_mode "INSERT" builtin zle .vi-change-whole-line } zle -N vi-change-whole-line bindkey -M vicmd "S" vi-change-whole-line ### vi-insert (unbound) (i) (unbound) ### Enter insert mode. vi-insert() { show_mode "INSERT" builtin zle .vi-insert } zle -N vi-insert bindkey -M vicmd "i" vi-insert ### vi-insert-bol (unbound) (I) (unbound) ### Move to the first non-blank character on the line ### and enter insert mode. vi-insert-bol() { show_mode "INSERT" builtin zle .vi-insert-bol } zle -N vi-insert-bol bindkey -M vicmd "I" vi-insert-bol ### vi-open-line-above (unbound) (O) (unbound) ### Open a line above the cursor and enter insert mode. vi-open-line-above() { show_mode "INSERT" builtin zle .vi-open-line-above } zle -N vi-open-line-above bindkey -M vicmd "O" vi-open-line-above ### vi-open-line-below (unbound) (o) (unbound) ### Open a line below the cursor and enter insert mode. vi-open-line-below() { show_mode "INSERT" builtin zle .vi-open-line-below } zle -N vi-open-line-below bindkey -M vicmd "o" vi-open-line-below ### vi-substitute (unbound) (s) (unbound) ### Substitute the next character(s). vi-substitute() { show_mode "INSERT" builtin zle .vi-substitute } zle -N vi-substitute bindkey -M vicmd "s" vi-substitute ### vi-replace (unbound) (R) (unbound) ### Enter overwrite mode. ### vi-replace() { show_mode "REPLACE" builtin zle .vi-replace } zle -N vi-replace bindkey -M vicmd "R" vi-replace ### vi-cmd-mode (^X^V) (unbound) (^[) ### Enter command mode; that is, select the `vicmd' ### keymap. Yes, this is bound by default in emacs ### mode. vi-cmd-mode() { show_mode "NORMAL" builtin zle .vi-cmd-mode } zle -N vi-cmd-mode bindkey -M viins "=1B" vi-cmd-mode ### vi-oper-swap-case ### Read a movement command from the keyboard, and swap ### the case of all characters from the cursor position ### to the endpoint of the movement. If the movement ### command is vi-oper-swap-case, swap the case of all ### characters on the current line. ### bindkey -M vicmd "g~" vi-oper-swap-case --UHN/qo2QbUvPLonB-- --sHrvAb52M6C8blB9 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8bptUTEYXWMJlHuYRAjahAJ0bfpb/jcKMp4PmO6LRMsaZ0AtdVACfRqTK +AectX4rEaGkWI33U/lQZtI= =xAgN -----END PGP SIGNATURE----- --sHrvAb52M6C8blB9--