Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 890
kev Avatar asked Oct 17 '25 17:10

kev


1 Answers

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.

like image 170
Ingo Karkat Avatar answered Oct 20 '25 10:10

Ingo Karkat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!