So you want to increase or decrease the font size? Maybe as easily as pressing Ctrl + or Ctrl - like in every other GUI application out there? Keep reading.
First things first, most Vim users still run
nvim) from the command line. Nothing wrong with that. But if you are running Vim inside of a terminal emulator, know that the font isn’t controlled by Vim–it is controlled by the terminal emulator, so look up the documentation for that. For example, I am using GNOME Terminal. In GNOME you can adjust the font size with Ctrl Shift + and Ctrl - and it just works™. In other terminal emulators you can often hold Ctrl and scroll the mouse wheel to adjust font size.
With that out of the way, this post is really about GUI Vim–whether that is gVim or one of the many Neovim frontends.
The easiest out-of-the-box way to adjust the font is to run:
This will open a font picker. On my Linux install it looks like this:
Your font picker probably looks different, but it will have all the same basic options, including an input field for changing the font size.
After you select the new font, you can inspect the value with
:set guifont? guifont=IBM Plex Mono:h11
In my case, I am using a font named IBM Plex Mono. And the font size is
Say we want to share our screen during a presentation. We could bump up the font size to 18 by running:
:set guifont=IBM\ Plex\ Mono:h18
That font format should work on gVim for Mac or Windows, or Neovim on any OS, including Linux.
Linux GTK gVim
If you are running gVim on Linux, chances are you are using the GTK version of gVim and need to use a slightly different, simpler format:
:set guifont=IBM\ Plex\ Mono\ 18
So what about keyboard shortcuts?
If we had
:DecreaseFont commands to adjust the font size, we could map keyboard shortcuts with:
nnoremap <C-+> :IncreaseFont<CR> nnoremap <C--> :DecreaseFont<CR>
Unfortunately, these font commands do not exist out-of-the-box. There is no such functionality that ships with Vim.
That is why I created a plugin–ezguifont.vim–that introduces these commands.
You can install
mkropat/vim-ezguifont like any other Vim plugin. For example, with vim-plug you would add:
ezguifont.vim works best if you set an explicit font, instead of using the default (blank) font. Add the following to your
let g:ezguifont = 'IBM Plex Mono:h11'
Except you would replace the font with whatever
set guifont? showed previously after you set it.
Next add the key mappings we hypothesized earlier:
nnoremap <C-+> :IncreaseFont<CR> nnoremap <C-=> :IncreaseFont<CR> nnoremap <C--> :DecreaseFont<CR>
(We map Ctrl = as well so you can omit holding the Shift key in Ctrl Shift +)
Restart Vim to have the settings take effect.
Now you should be able to Ctrl + and Ctrl - in Vim just like you do in any other GUI application! See the ezguifont.vim README for full documentation.