2

For my terminal Vim 8.0, I have downloaded this plugin that makes changing font size on the fly easy: https://github.com/drmikehenry/vim-fontsize

Following the instructions, here is how I decided to define my mappings for changing fonts:

nmap <silent> <C>+ <Plug>FontsizeInc
nmap <silent> <C-kPlus> <Plug>FontsizeDec
nmap <silent> <C>- <Plug>FontsizeDec
nmap <silent> <C-kMinus> <Plug>FontsizeDec
nmap <silent> <C>0 <Plug>FontsizeDefault

However, to my surprise, the functionalities are only working for the + and - characters that are not in the NumPad are of my keyboard. When I hit the combinations using + or - form the NumPad, nothing happens. And otherwise, my Vim recognizes the NumPad just normally.

How could I perhaps solve this issue?

  • Those mappings dont look quite right to my eye – D. Ben Knoble Jan 6 at 18:47
  • Also the title of your question has nothing to do with it’s body? – D. Ben Knoble Jan 6 at 18:47
  • @D.BenKnoble Ooops, my bad, I mistakenly copied and pasted the title from wrong place. Fixed it now. About the mappings, what does not look right? It works perfectly for <C>+, <C>- and <C>0, just not <C-kPlus> and <C-kMinus> – Jorget Millani Jan 6 at 18:52
  • The typical syntax is map <LHS> <RHS>, but in your question i see 3 “sides” after the map commands – D. Ben Knoble Jan 6 at 18:53
  • @D.BenKnoble Changed that, no effect – Jorget Millani Jan 6 at 19:17
2

If I understand your question right, you are working in a terminal. Vim can't change the font size in a terminal. What you see, when pressing Ctrl-+ and Ctrl-- is a functionality of the terminal.

Try it without starting vim.

The plugin you downloaded just changes the guifont.

For this I have the following in my gvimrc:

command! -bar -nargs=0 BiggerFont  :let &guifont = substitute(&guifont,'\d\+$','\=submatch(0)+1','')
command! -bar -nargs=0 SmallerFont :let &guifont = substitute(&guifont,'\d\+$','\=submatch(0)-1','')
nnoremap <M-->        :SmallerFont<CR>
nnoremap <M-+>        :BiggerFont<CR>

Stolen from tpope.

BTW: The {lhs} of the mappings <C>+, <C>- and <C>0 all map a sequence of 4 characters.

BTW-2: I'm not sure that Ctrl-+ and Ctrl-- is mappable at all. If I go into insert mode in gVim and enter Ctrl-V + Ctrl-+ I just get a single +. If I use Ctrl-V + Ctrl-L I get ^L.

  • Thanks, I corrected the mappings, getting rid of that part. Still, the same thing: it does work with <C>+ and <C>-, so it can change the fonts - I don't think it is only the terminal, because if I comment those lines out the re-sizing of the font stops working. It just does not work with the numpad keys – Jorget Millani Jan 6 at 19:18
  • 1
    I'm pretty sure your terminal does that, not Vim. My GNOME-Terminal has this. It changes the font size with <C-+> and <C--> even without Vim. – Ralf Jan 6 at 19:20
  • You are using Vim in a terminal, not gVim? Which OS?, Which terminal emulator? – Ralf Jan 6 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.