简体   繁体   中英

How to map {Ctrl 0,-,=} keys in vim?

My keyboard's layout(2nd row):

` 1 ... 0 - = Backspace

I want to map function calls to Ctrl + 0 , - , = .

This is the function I created:

" it doesn't work
nnoremap <C-=>  :call IncFontSize(+1)<CR>

" it works
nnoremap <C-->  :call IncFontSize(-1)<CR>

" it doesn't work
nnoremap <C-0>  :call IncFontSize(0)<CR>

fun! IncFontSize(inc)
    if !exists('+guifont')
        return
    endif
    let s:defaultfont = 'Ubuntu Mono 12'
    if a:inc==0 || empty(&guifont)
        let &guifont = s:defaultfont
        return
    endif
    let &guifont = substitute(&guifont, '\d\+$', '\=submatch(0)+'.a:inc, '')
endfun

How can I map function calls to these keys?

Notice how in command-line mode, Ctrl - _ results in ^_ , but Ctrl - 0 and Ctrl - = yield nothing.

Due to the way that the keyboard input is handled internally, differentiating this as well as many other key combinations (like Ctrl + Letter vs. Ctrl + Shift + Letter ) unfortunately isn't possible today, even in GVIM. This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. link

But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.

http://vim.wikia.com/wiki/Fast_window_resizing_with_plus/minus_keys

just only + and - …… no alias name

:nmap + :echo "hello world"<CR>

Is it what you want ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM