Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Neovim font?

Tags:

neovim

VIM contains a 'set guifont' option to change the font. Neovim does not support this option, so I am wondering if it's possible to change the font Neovim uses in the Terminal?

like image 797
mbdev Avatar asked Feb 09 '16 06:02

mbdev


People also ask

What font does Neovim use?

Neovim will use whatever font your terminal app is set to use.

How do I change the font in Vimrc?

In Vim, pop open the GUI to select the font by typing in this command: :set guifont=* . It should open up the standard font dialog box for your platform. Select the font you want to use and close the dialog.


5 Answers

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.

like image 120
Hope Avatar answered Nov 02 '22 18:11

Hope


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.

like image 41
nabn Avatar answered Nov 02 '22 18:11

nabn


How to change the font depends on how you are currently using Neovim:

For terminal Neovim

If you use Neovim in a terminal, to change the font neovim used, you need to change the font your terminal uses. Check your terminal manual on how to change font style and font size, etc.

For Neovim GUI client

For Neovim GUI client, you need to set the font in the file ginit.vim. ginit.vim is located in the same folder as init.vim[^1]. Different GUI clients have different command for setting the font you use and font size. An incomplete list of GUI client I have tried:

  • nvim-qt: Use the comamnd GuiFont inside ginit.vim to change font, for example, GuiFont Hack:h12 (suppose you have installed font Hack).
  • fvim: fvim is another Neovim GUI client. You can use set guifont=Hack:12 inside ginit.vim to set the font that fvim uses.

[^1]: Inside Neovim, use :echo stdpath('config') to show where that directory is for your platform.

like image 36
jdhao Avatar answered Nov 02 '22 16:11

jdhao


I use Neovim-qt version on my Ubuntu18.04. But I use the same config file for my vim.

After trial-and-error, I found the way to change neovim font to FiraCode Monospace. Although you could type the command :Guifont Fira Mono:h12 inside GUI to change the currently used font, it works only once. After you close the GUI, need to set up the font again. : (
Or you need another config file ginit.vim to set up GUI-related things. The same problem of setting up font for GUI, just write GuiFont Fira Mono:h12 in ginit.vim.

like image 39
Yossarian42 Avatar answered Nov 02 '22 17:11

Yossarian42


Apart from the answers in this question, the reason many scripts/plugins that works for vim/Gvim but not NeoVim (qt) is that in NeoVim, the font is defined by Guifont instead of guifont.

like image 44
X.Arthur Avatar answered Nov 02 '22 17:11

X.Arthur