12

how can I override some color scheme value in neovim lua config file? I am trying to use .lua instead of .vim. Previously in my init.vim file I have this to override some settings I want to enable these settings for init.lua file also. How I can achieve this?

highlight ColorColumn ctermbg=0 guibg=lightgrey
highlight Normal ctermfg=white ctermbg=black
autocmd ColorScheme * highlight CursorLineNr cterm=bold term=bold gui=bold

config file

2

1 Answer 1

11

For Neovim

In your Lua configuration init.lua, you can use vim.cmd function to add highlight and create auto-command:

vim.cmd([[highlight ColorColumn ctermbg=0 guibg=lightgrey]])
vim.cmd([[highlight Normal ctermfg=white ctermbg=black]])
vim.cmd([[autocmd ColorScheme * highlight CursorLineNr cterm=bold term=bold gui=bold]])

For Neovim >= 0.7

With this Neovim version, there is a new function in API to set highlight : nvim_set_hl

You could define your highlights with it in Lua:

vim.api.nvim_set_hl(0, "ColorColumn", { ctermbg=0, bg=LightGrey })
vim.api.nvim_set_hl(0, "Normal", { ctermfg=White,  ctermbg=Black })

There is also nvim_create_autocmd function in API to create auto-command in Lua:

vim.api.nvim_create_autocmd("ColorScheme", 
  pattern="*",
  callback = function()
    vim.api.nvim_set_hl(0, "CursorLineNr", { cterm=bold, bold=true })   
  end,
)
1
  • How do I found out about this? It seems like everytime I use the help I never find what I want and resort to googling in the end. Is there some mapping from viml commands to lua bindings that have been implemented somewhere?
    – Tiseno
    May 4 at 5:28

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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