From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8608 invoked from network); 16 Feb 2002 17:20:28 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 16 Feb 2002 17:20:28 -0000 Received: (qmail 19149 invoked by alias); 16 Feb 2002 17:20:05 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 4679 Received: (qmail 19136 invoked from network); 16 Feb 2002 17:20:04 -0000 Date: Sat, 16 Feb 2002 17:20:00 +0000 From: Ian Lynagh To: zsh-users@sunsite.dk Subject: vim-a-like vi mode status bar Message-ID: <20020216172000.GA892@stu163.keble.ox.ac.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="2oS5YaxWCcQjTEyO" Content-Disposition: inline User-Agent: Mutt/1.3.25i Sender: Ian Lynagh --2oS5YaxWCcQjTEyO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all 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. Initially I was planning to have the indicator in the prompt. However AFAICT once the prompt has been displayed it is cached, so even if you for zsh to redraw it (I tried various things like "zle redisplay", "zle push-input; zle get-line", "zle -R") it just redraws the old one. Did I miss a way to do this? Is there a reason why it shouldn't be possible to pipe something into source? Or another way to do it without a temporary file? With the script attached, if I paste a command in then only the first character is visible until I press ^R. If I type something else first then it works fine (even if I first delete what I typed!). Perhaps this is a bug? I also couldn't find a way to set the statusbar after accepting a command. zsh -M complains it's not being called from a widget if I call it from precmd. Finally I would welcome any comments/criticisms on the code! Thanks Ian --2oS5YaxWCcQjTEyO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=zsh-vi-mode-status-bar # Provides you with a vim-a-like vi-mode status bar showing what mode # you are in. # To be called from .zshrc # Author: Ian Lynagh # Licence: GPL 2 # Copyright: Ian Lynagh 2002 # Should we show "" or "" for insert mode? alias statusbar-show-insert="zstyle :vi-mode-statusbar: show-insert yes" alias statusbar-no-show-insert="zstyle :vi-mode-statusbar: show-insert no" alias statusbar-test-show-insert="zstyle -t :vi-mode-statusbar: show-insert" statusbar-no-show-insert # What mode are we now in? alias statusbar-now-insert="zstyle :vi-mode-statusbar: now-insert yes" alias statusbar-now-command="zstyle :vi-mode-statusbar: now-insert no" alias statusbar-test-now-insert="zstyle -t :vi-mode-statusbar: now-insert" # What mode were we in last time? alias statusbar-last-insert="zstyle :vi-mode-statusbar: last-insert yes" alias statusbar-last-command="zstyle :vi-mode-statusbar: last-insert no" alias statusbar-test-last-insert="zstyle -t :vi-mode-statusbar: last-insert" # Helper function function stat-statusbar-update { if statusbar-test-now-insert then if statusbar-test-show-insert then zle -M "" else if ! statusbar-test-last-insert then zle -M "" fi fi statusbar-last-insert else zle -M "" statusbar-last-command fi } # Before each prompt reset function precmd { statusbar-now-insert statusbar-last-command } # Wrap each widget # This makes a new ~/.zshrc.stat.functions function gen-stat-functions { local EXTRA CHANGE rm ~/.zshrc.stat.functions zle -l -a | grep "^[a-zA-Z]" | while read WIDGET do UPDATE="stat-statusbar-update" CHANGE="" case "$WIDGET" in vi-(add-(eol|next)|insert(|-bol)|change-(eol|whole-line) \ |open-line-(above|below)|replace) \ |accept-(and-(hold|infer-next-history)|line(|-and-down-history)) \ |get-line|pound-insert|push-(input|line(|-or-edit)) \ |send-break|run-help|which-command) CHANGE="statusbar-now-insert" ;; vi-cmd-mode) echo foo CHANGE="statusbar-now-command" ;; vi-change) CHANGE="statusbar-now-insert" UPDATE="" ;; esac echo " function stat-$WIDGET { zle .$WIDGET $CHANGE $UPDATE } zle -N stat-$WIDGET stat-$WIDGET zle -A stat-$WIDGET $WIDGET" >> ~/.zshrc.stat.functions done } # Don't bother updating it automagically - that's just asking for it! # Just . whatever was last created . ~/.zshrc.stat.functions # Use vi mode bindkey -v --2oS5YaxWCcQjTEyO--