vim特殊字符输入及整理 (2)

A fake leader for vim

Rykka posted @ 2012年6月04日 01:53 in vim , 2943 阅读

When we using the '<Space>' as a mapleader in vim.
The disadvantage is you can not see it with 'showcmd' ,
it's a whitespace!
This will lead to some unwanted behavior as
you don't know whether you have pressed it or not.

So I write a small function in vimrc to show it.

" using expr to return a map , which can autoload plugin files
map <expr><Space> <SID>fake_leader()
fun! s:fake_leader() "{{{
    " A fake leader to display the status of <Space>.
    " you should set your mapleader to a key other than '<Space>'
    " disadvantage: only recevie 2 key mapping
    "        e.g. <leader>vv but no <leader>v or <leader>vvv
    echohl WarningMsg | echo "F:<Space>+" | echohl Normal
    let n1 = getchar()
    let c1 = nr2char(n1)
    let t=""
    if c1 == "\<Space>"
        echon "<Space>"
        let t = g:mapleader . g:mapleader
    elseif c1 == "\<Esc>"
        echon "<Escape>"
    elseif c1 == "\\"
        echon "<Bslash>"
        let t = g:mapleader . "\\"
    elseif n1 == "\<BS>"
        echon "<BS>"
    else
        echon c1
        let c2 = nr2char(getchar())
        let t = g:mapleader .c1.c2
    endif
    redraw | echo 
    return t 
endfun "}}}

 

 

 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter