How to change Neovim font?

This is not for a terminal, but still it might be useful to someone.

For Neovim-Qt GUI client, you can change the font by Ctrl + mouse scroll if you put the following to ginit.vim:

let s:fontsize = 12
function! AdjustFontSize(amount)
  let s:fontsize = s:fontsize+a:amount
  :execute "GuiFont! Consolas:h" . s:fontsize
endfunction

noremap <C-ScrollWheelUp> :call AdjustFontSize(1)<CR>
noremap <C-ScrollWheelDown> :call AdjustFontSize(-1)<CR>
inoremap <C-ScrollWheelUp> <Esc>:call AdjustFontSize(1)<CR>a
inoremap <C-ScrollWheelDown> <Esc>:call AdjustFontSize(-1)<CR>a

For those who prefer using keyboard, there is a nice way to use numpad's + (kPlus) and - (kMinus)

" In normal mode, pressing numpad's+ increases the font
noremap <kPlus> :call AdjustFontSize(1)<CR>
noremap <kMinus> :call AdjustFontSize(-1)<CR>

" In insert mode, pressing ctrl + numpad's+ increases the font
inoremap <C-kPlus> <Esc>:call AdjustFontSize(1)<CR>a
inoremap <C-kMinus> <Esc>:call AdjustFontSize(-1)<CR>a

Obviously you can replace Consolas with the font you prefer.


Change the font in your terminal emulator's preferences. Terminal programs generally can't set their own fonts. Only GUI clients like Gvim or macvim use the set guifont option.

Tags:

Neovim