zsh-workers
 help / color / mirror / code / Atom feed
From: ZyX <zyx.vim@gmail.com>
To: zsh-workers@zsh.org
Subject: Re: CTRL-O in vi mode
Date: Wed, 17 Nov 2010 00:04:23 +0300	[thread overview]
Message-ID: <201011170004.23709@-zyx> (raw)
In-Reply-To: <4CE2EA45.6060909@gmx.de>

[-- Attachment #1: Type: Text/Plain, Size: 3336 bytes --]

Reply to message «CTRL-O in vi mode», 
sent 23:32:05 16 November 2010, Tuesday
by Bernd Strohhaecker:

> I'm using vi mode. Is it possible in viins mode to realize Vim's CTRL-O
> command, e.g. execute one vicmd command and then return to viins mode?
Of course, it is. I do use emacs mode but have lots of custom mappings and <C-o>
is one of them:

    function _-vi-digit-arg
    {
        emulate -LR zsh
        [[ -z "${NUMERIC}" ]] && NUMERIC=0
        [[ -z "$1" ]] && num=0 || num=$(( $1 ))
        shift
        (( NUMERIC=NUMERIC*10+num )) && $@
    }
    function _-repeat-for-key
    {
        emulate -LR zsh
        local key
        read -k key
        local -i OLDLLEN=${#LBUFFER} OLDRLEN=${#RBUFFER}
        local OLDLBUFFER="$LBUFFER" OLDRBUFFER="$RBUFFER"
        (( NUMERIC )) || NUMERIC=1
        if ! [[ -z $2 ]] ; then
            eval $2
            (( NUMERIC-- ))
        fi
        while (( NUMERIC )) ; do
            eval $1
            (( NUMERIC-- ))
        done
        local -i LLEN=${#LBUFFER} RLEN=${#RBUFFER}
        if (( LLEN<OLDLLEN || RLEN<OLDRLEN )) ; then
            local KILLTEXT="${OLDLBUFFER[LLEN+1,-1]}${OLDRBUFFER[1,OLDRLEN-RLEN]}"
            zle copy-region-as-kill "$KILLTEXT"
        fi
    }
    function _-vi-delete
    {
        emulate -LR zsh
        local key
        read -k key
        key=$(( #key ))
        if   (( key==##t )) ; then
            _-repeat-for-key 'RBUFFER=${(S)RBUFFER/#$key*$key/$key}' \
                             'RBUFFER=${(S)RBUFFER/#*$key/$key}'
        elif (( key==##T )) ; then
            _-repeat-for-key 'LBUFFER=${(S)LBUFFER/%$key*$key/$key}' \
                             'LBUFFER=${(S)LBUFFER/%$key*/$key}'
        elif (( key==##f )) ; then _-repeat-for-key 'RBUFFER=${RBUFFER#*$key}'
        elif (( key==##F )) ; then _-repeat-for-key 'LBUFFER=${LBUFFER%$key*}'
        elif (( key==##d )) ; then zle kill-whole-line
        elif (( key==##$ )) ; then zle kill-line
        elif (( key==##\^ )); then zle backward-kill-line
        elif (( key==##0 )) && [[ -z $NUMERIC ]] ;
                              then zle backward-kill-line
        elif (( key>=##0 && key<=##9 ))
                              then _-vi-digit-arg $(( key - ##0 )) _-vi-delete
        fi
    }
    function _-vi-ctrl-o
    {
        emulate -LR zsh
        local keystr
        read -k keystr
        local -r keystr
        local -ri key=$(( #keystr ))
          if (( key==##A )) ; then zle end-of-line
        elif (( key==##$ )) ; then zle end-of-line
        elif (( key==##I )) ; then zle vi-first-non-blank
        elif (( key==##d )) ; then _-vi-delete
        elif (( key==##0 )) && [[ -z $NUMERIC ]] ;
                              then zle beginning-of-line
        elif (( key>=##0 && key<=##9 ))
                              then _-vi-digit-arg $(( key - ##0 )) _-vi-ctrl-o
        #elif (( key==##s )) ; then zle sedsubstitute
        #elif (( key==##= )) ; then zle tailfor
        else
            zle ${${(z)$(bindkey -M vicmd $keystr)}[2]}
        fi
    }

    zle -N vi-ctrl-o                         _-vi-ctrl-o
    bindkey  -N evi    emacs
    bindkey  -A evi     main
    bindkey -rM evi    "\C-o"
    bindkey  -M evi    "\C-o"         "vi-ctrl-o"

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

           reply	other threads:[~2010-11-16 21:28 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <4CE2EA45.6060909@gmx.de>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201011170004.23709@-zyx \
    --to=zyx.vim@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).