Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the font size if you're using init.lua (lua environment) and not .vimrc file #1211

Closed
nishu-murmu opened this issue Feb 12, 2022 · 12 comments
Labels
enhancement New feature or request

Comments

@nishu-murmu
Copy link

I wanted to use Neovide but am not using standard .vimrc file.
my source file is a lua file.
Can we get a feature to edit fonts in lua environment.

Neovide

@nishu-murmu nishu-murmu added the enhancement New feature or request label Feb 12, 2022
@nishu-murmu nishu-murmu changed the title How to change the font size if you're init.lua (lua environment) and not .vimrc file How to change the font size if you're using init.lua (lua environment) and not .vimrc file Feb 12, 2022
@MultisampledNight
Copy link
Contributor

MultisampledNight commented Feb 12, 2022

Hi! You can do so with the guifont option, see the website at https://neovide.dev/configuration.html#font for details! For example, to set the font to Source Code Pro on size 12 with slight hinting:

VimScript:

set guifont=Source_Code_Pro:h12:#h-slight

Lua:

vim.o.guifont = "Source Code Pro:h12:#h-slight"

A few things to note:

  • The font options (as in, h12 or #h-slight or all the other ones) apply to all fonts at once. It's not possible to set them individually for the time being.
  • The lua table syntax you see floating around here in the issue is a bit misleading. In effect, table fields are concatenated with , in this case, which is only really useful for fallback fonts, but quite misleading when combined with options (since then it looks like the options would only apply to the last fallback font but actually they'll apply to all fonts). It's probably preferable to use the string syntax instead.
Original misinformed comment from longer ago The option Neovide uses for this is builtin in NeoVim, it's called `guifont`. So that has nothing to do with Neovide itself. According to `:h lua-vim-opt`, you could just use
vim.opt.guifont = { "Source Code Pro", "h12" }

EDIT: Probably vim.opt.guifont = { "Source Code Pro", ":h12" } was meant instead. I don't know what made that work, since parsing relies on the colon to detect options.

where Source Code Pro sets the font family and h12 sets the font size. See :h 'guifont' for more configuration options.

@nishu-murmu
Copy link
Author

I know about guifont
I have used it in my config in settings.lua file
Here's the settings.lua file

vim.cmd([[
let g:mapleader = " "

set nocompatible
syntax enable
filetype plugin indent on
set encoding=utf-8
set fileencoding=utf-8
set showcmd
set cmdheight=1
set scrolloff=10
set splitbelow
set splitright
set conceallevel=0
set title
set tabstop=2
set shiftwidth=2
set autoindent
set smarttab
set expandtab
set showtabline=2
set noshowmode
set nobackup
set nowritebackup
set updatetime=300
set timeoutlen=500
set clipboard=unnamedplus
set laststatus=0
set number
set ruler
set cursorline
set hidden
set nowrap
set backspace=start,eol,indent
set mouse=a
set lazyredraw
set wildignore+=*/node_modules/*
set termguicolors
set guifont=Hack:h12
set background=dark 
colorscheme onedark

au BufNewFile,BufRead *.es6 setf javascript
au BufNewFile,BufRead *.tsx setf typescriptreact
]])

Still the font size doesn't change

Then I read for fonts to work properly and not breaking, you need to use guifont in the init file so I also added it in init.lua file but still it isn't working

Here's the init.lua file

require("user.settings")
vim.opt.guifont = { "Source Code Pro", "h12" }
require("user.mappings")
require("user.plugins")
require("user.lsp-config")
require("user.lsp-saga")
require("user.auto-pairs")
require("user.Comment")
require("user.lualine")
require("user.treesitter")
require("user.telescope")
require("user.gitsigns")
require("user.nvim-tree")
require("user.nvim-cmp")
require("user.web-devicons")
require("user.bufferline")
require("user.alpha")
require("user.scroll")
require("user.colorizer")
require("user.whichkey")

@MultisampledNight
Copy link
Contributor

That's truly difficult to tell, as any of those imported files could contain a new value for guifont. While you could check your final value with :set guifont? and then search in all your config files for it, that's still not an issue with Neovide itself.

@Kethku
Copy link
Member

Kethku commented Feb 12, 2022

The option Neovide uses for this is builtin in NeoVim, it's called guifont. So that has nothing to do with Neovide itself. According to :h lua-vim-opt, you could just use

vim.opt.guifont = { "Source Code Pro", "h12" }

where Source Code Pro sets the font family and h12 sets the font size. See :h 'guifont' for more configuration options.

I'd be surprised if this works. We currently parse the guifont manually, and I don't know how lua objects get converted. I use vim.o.guifont = "Cascadia Code PL,Delugia Nerd Font:h11" in my config. (I think thats right. I'm translating from fennel and don't remember precisely what the lua syntax is). If you wanted to make this dynamic, or bind to a function, I'd achieve that with string concatenation.

@MultisampledNight
Copy link
Contributor

Well, I just followed the example in :h lua-vim-opt. But if we don't support it, I've got another thing to tackle.

@nishu-murmu
Copy link
Author

@MultisampledNight your code (vim.opt.guifont = ) didn't seem to work
but @Kethku yours (vim.o.guifont =)actually did work but i need to reduce my fontsize a bit less than my Neovim config comparatively.
For example fontsize 8 in neovide is equivalent font size 12 in neovim

@alai
Copy link

alai commented Jun 12, 2022

The option Neovide uses for this is builtin in NeoVim, it's called guifont. So that has nothing to do with Neovide itself. According to :h lua-vim-opt, you could just use

vim.opt.guifont = { "Source Code Pro", "h12" }

where Source Code Pro sets the font family and h12 sets the font size. See :h 'guifont' for more configuration options.

I'd be surprised if this works. We currently parse the guifont manually, and I don't know how lua objects get converted. I use vim.o.guifont = "Cascadia Code PL,Delugia Nerd Font:h11" in my config. (I think thats right. I'm translating from fennel and don't remember precisely what the lua syntax is). If you wanted to make this dynamic, or bind to a function, I'd achieve that with string concatenation.

For those who did this, and see font family setting both works in nvim and neovide, but the font size setting doesn't work for neovide, add a : before the font size in your options.lua like:

vim.opt.guifont = { "Source Code Pro", ":h12" }

@mbledkowski
Copy link

@alai Thank you <3

@umop3plsdn
Copy link

this was exactly my problem! no matter what I did neovide was just HUGE all the time and I was racking my brain but this does the trick!

@jjaimealeman
Copy link

For those who did this, and see font family setting both works in nvim and neovide, but the font size setting doesn't work for neovide, add a : before the font size in your options.lua like:

👍 Thanks, this worked for me!

@Shaolo
Copy link

Shaolo commented Dec 4, 2022

On Win10 I had to use an "_" in place of spaces and the colon in the height to make it work.

vim.opt.guifont = { "JetBrains_Mono", ":h10" }

@DominicCronin
Copy link

On neovim-qt on Windows 11, this worked:
vim.o.guifont='MesloLGL NFM:h12'

Note the unescaped space, and having to set the height option as a colon-separated element in the string. vim.opt.guifont didn't work, although it would have looked prettier IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants