tags:

views:

77

answers:

2

I forgot the array syntax while on Zsh-commandline:

$ hello=[1,2,3,4] %ERR: 

I want to fix the problem by substitution. In Vim, I would do :.s@,@ @g. So how can I edit the current line, or let call it a current buffer, by running a command on it?

+1  A: 

Only using custom zle widget, for example:

function _-sedsubs()
{
    emulate -LR zsh
    zle -R "Substitution:"
    local SEDARG="s"
    local key=""
    read -k key
    local -r start=$key
    while (( (#key)!=(##\n) &&
             (#key)!=(##\r) )) ; do
        if (( (#key)==(##^?) || (#key)==(##^h) )) ; then
            SEDARG=${SEDARG[1,-2]}
        else
            SEDARG="${SEDARG}$key"
        fi
        zle -R "Substitution: $SEDARG"
        read -k key || return 1
    done
    BUFFER="$(echo $BUFFER | sed -r -e "$SEDARG")"
}
zle -N sedsubstitute                     _-sedsubs
bindkey "\C-o:s" sedsubstitute
ZyX
+2  A: 
[jkramer/sgi5k:~]# list=(1,2,3,4,5,6,7,8,9,10)
[jkramer/sgi5k:~]# !:gs/,/ /                  
list=(1 2 3 4 5 6 7 8 9 10)

See zshexpn(1) for more information of history completion/alternation.

jkramer