> function SMap(key, action, ...)

Here is my take on this (even longer):

fun! TMultiMap(modes, base, key, ...) "{{{3
    let max = strlen(a:modes)
    let force_normal = 0
    let i = 0
    while i < max
        let this = strpart(a:modes, i, 1)
        let i = i + 1
        if this ==# '*'
            let this = ''
            let pre  = ''
            let post = ''
        elseif this ==# '+'
            let this = ''
            let pre  = ''
            let post = ''
            let force_normal = 1
        elseif this ==# 'n'
            let pre  = ''
            let post = ''
        elseif this ==# 'i'
            if force_normal
                let pre = '<esc>'
            else
                let pre = '<c-\><c-o>'
            endif
            let post = ''
        elseif this ==# 'v'
            if force_normal
                let pre = '<esc>'
                let post = ''
            else
                let pre = '<c-c>'
                let post = '<C-\><C-G>'
            endif
        elseif this ==# 'c'
            if force_normal
                let pre = '<esc>'
                let post = ''
            else
                let pre = '<c-c>'
                let post = '<C-\><C-G>'
            endif
        elseif this ==# 'o'
            if force_normal
                let pre = '<esc>'
                let post = ''
            else
                let pre = '<c-c>'
                let post = '<C-\><C-G>'
            endif
        elseif this =~# '^[NIVCO]$'
            let this = tolower(this)
            let pre  = ''
            let post = ''
        else
            throw 'Unknown mode (must be one of: "*nivcoNIVCO"): '.
this
        endif
        let c = ''
        let n = 1
        while n <= a:0
            exe "let c = c.pre. a:". n ." .post"
            let n = n + 1
        endwh
        " echom "DBG ". this.a:base .' '. TMultiMapKey(a:key) .' '. c
        if exists('*TMultiMapKey')
            let k = TMultiMapKey(a:key)
        else
            let k = a:key
        endif
        if !empty(k)
            exe this.a:base .' '. k .' '. c
        endif
    endw
endfun

Example usage:
call TMultiMap("*i", "noremap", "<M-PageDown>", "<c-w>w", '<c-d>', '<c-
w>p')
call TMultiMap("*i", "noremap", "<M-PageUp>",   "<c-w>w", '<c-u>', '<c-
w>p')

An optional TMultiMapKey() function can be used to process the key
somehow (eg enable alt-maps for the terminal).

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to