Dark and light themes for Neovim 0.5 and above, written in Lua
Treesitter enabled / Fully customisable / Many popular plugins supported
Inspired by VS Code's One Dark Pro
- Dark and light versions - onedark and onelight
- Supports custom highlighting across filetypes
- Treesitter support
- Options to specify styles for:
- Comments
- Functions
- Keywords
- Strings
- Variables
- Virtual text
- Override default styles, colors, highlight groups and filetype highlight groups
- Create custom highlight groups
- LSP diagnostics support
- Support for a large array of vim-polygot packs (pull requests welcome)
- Support for popular plugins:
Telescope
Telescope
Note: All screenshots have Treesitter highlighting enabled
Note: A greater likeness to
VS Code
can be achieved by using the theme's ability to customise highlight groups by filetype
- Neovim 0.5 or greater
termguicolors
enabled for true color supporttreesitter
for full syntax highlighting
Using packer.nvim:
use 'olimorris/onedarkpro.nvim'
Alternatively, if using Vimscript and vim-plug:
call plug#begin('~/.config/nvim/plugged')
Plug 'olimorris/onedarkpro.nvim'
call plug#end()
Add the following to an init.lua
file to start using the theme:
require('onedarkpro').load()
Alternatively, if using Vimscript:
colorscheme onedarkpro
The vim.o.background
option may be used to set the theme:
vim.o.background = "dark" -- to load onedark
vim.o.background = "light" -- to load onelight
require("onedarkpro").load()
The theme's default configuration as per the config.lua file is:
local onedarkpro = require("onedarkpro")
onedarkpro.setup({
dark_theme = "onedark", -- The default dark theme
light_theme = "onelight", -- The default light theme
-- Theme can be overwritten with 'onedark' or 'onelight' as a string
theme = function()
if vim.o.background == "dark" then
return config.dark_theme
else
return config.light_theme
end
end,
colors = {}, -- Override default colors by specifying colors for 'onelight' or 'onedark' themes
hlgroups = {}, -- Override default highlight groups
filetype_hlgroups = {}, -- Override default highlight groups for specific filetypes
plugins = { -- Override which plugins highlight groups are loaded
native_lsp = true,
polygot = true,
treesitter = true,
-- NOTE: Other plugins have been omitted for brevity
},
styles = {
strings = "NONE", -- Style that is applied to strings
comments = "NONE", -- Style that is applied to comments
keywords = "NONE", -- Style that is applied to keywords
functions = "NONE", -- Style that is applied to functions
variables = "NONE", -- Style that is applied to variables
virtual_text = "NONE", -- Style that is applied to virtual text
},
options = {
bold = false, -- Use the themes opinionated bold styles?
italic = false, -- Use the themes opinionated italic styles?
underline = false, -- Use the themes opinionated underline styles?
undercurl = false, -- Use the themes opinionated undercurl styles?
cursorline = false, -- Use cursorline highlighting?
transparency = false, -- Use a transparent background?
terminal_colors = false, -- Use the theme's colors for Neovim's :terminal?
window_unfocussed_color = false, -- When the window is out of focus, change the normal background?
}
})
onedarkpro.load()
Note: If you wish to use the default config there is no need to copy the above into the setup function.
Currently there are three themes available:
- onedark
- onelight
- onedark_vivid
- onedark_dark
The theme can be set as follows:
theme = "onedark", -- Or "onelight", "onedark_vivid", "onedark_dark"
If no value is specified, the value of vim.o.background
will be used to set the theme with dark setting onedark
and light setting onelight
. For greater customisation with the vim.o.background
option, default dark and light themes can be set:
dark_theme = "onedark_vivid",
light_theme = "onelight",
By default, all of the plugins supported by the theme are loaded at runtime. Specific plugins can be disabled as follows:
plugins = {
native_lsp = false,
polygot = false,
treesitter = false
}
Alternatively, all of the plugins can be disabled at once:
plugins = {
all = false
}
Or, all of the plugins can be disabled with only a select few enabled:
plugins = {
all = false
native_lsp = true,
treesitter = true
}
Note: For a full list of plugins supported in the theme, see the plugins folder
Styles can be set by specifying the highlight group from the theme.lua file (and any plugin files) alongside the desired style(s):
styles = {
comments = "italic",
functions = "NONE",
keywords = "bold,italic",
strings = "NONE",
variables = "NONE",
virtual_text = "NONE"
}
Where italic, bold, underline and NONE are possible values for styles.
Note: Multiple styles can be passed using a comma. For example
bold,italic
The theme has a palette of 13 core colors alongside many additional ones used for menus and git diffs. These colors can be found in the color files.
The default colors can be changed by specifying the name of the color and the new hex code:
colors = {
red = "#FF0000"
}
New colors may be specified in the configuration which will then be merged into the theme's color palette:
colors = {
my_new_red = "#f44336"
}
Note: Custom colors can also be referenced when creating custom highlight group overrides in
hlgroups
It's possible to override default colors within the theme such as the bg
color. This is a common question for those who wish to have a darker background than the default. Of course it would make sense to have different bg
colors for the onedark
and onelight
themes. This can be achieved by specifying the theme name as a table, followed by the color:
colors = {
onedark = {
bg = "#FFFF00" -- yellow
},
onelight = {
bg = "#00FF00" -- green
}
}
The theme.lua file and plugins use a large array of highlight groups. There are three ways to customize them:
- Using specific hex colors
- Referencing the name of color variables
- Linking to other highlight groups in the theme
hlgroups = { -- Overriding the Comment highlight group
Comment = { fg = "#FF0000", bg = "#FFFF00", style = "italic" }, -- 1
Comment = { fg = "${my_new_red}" bg = "${yellow}", style = "bold,italic" }, -- 2
Comment = { link = "Substitute" } -- 3
}
The original One Dark Pro utilises custom highlights based on filetype to achieve its distinctive look. This can also be achieved within the theme:
filetype_hlgroups = {
yaml = { -- Use the filetype as per the `set filetype?` command
TSField = { fg = "${red}" }
},
python = {
TSConstructor = { fg = "${bg}", bg = "${red}" }
}
}
Note: Currently support for highlighting in Telescope's previewer is unavailable.
Note: Please see this issue for how other users are configuring their theme by filetype
Note: The excellent hlargs.nvim plugin allows for greater customisation over arguments definitions and usages
Filetype highlight groups work by detecting the filetype of the current buffer and checking the user's config to determine if any should be applied. As the user moves between buffers, the theme checks for a filetype change and applies any new highlights as neccessary.
When using common plugins such as Telescope or Trouble, additional windows with distinct filetypes are opened. This can cause the theme to reapply the default highlight groups as it detects a buffer filetype change. When closing the windows, the user's custom filetype highlight groups are then lost. To prevent this from happening, the theme has a table of filetypes and buffer types to ignore:
filetype_hlgroups_ignore = {
filetypes = {
"^aerial$",
"^alpha$",
"^fugitive$",
"^fugitiveblame$",
"^help$",
"^NvimTree$",
"^packer$",
"^qf$",
"^startify$",
"^startuptime$",
"^TelescopePrompt$",
"^TelescopeResults$",
"^terminal$",
"^toggleterm$",
"^undotree$"
},
buftypes = {
"^terminal$"
}
Additional filetypes and buffer types can be added in the config.
Alongside styles, the theme applies some opinionated formatting. These can be found in the theme.lua file with style
options containing theme.*
values.
These can be configured with the following options:
options = {
bold = true, -- Use the themes opinionated bold styles?
italic = true, -- Use the themes opinionated italic styles?
underline = true, -- Use the themes opinionated underline styles?
undercurl = true -- Use the themes opinionated undercurl styles?
}
The theme supports transparent backgrounds:
options = {
transparency = true
}
By setting the transparency option to true, the Normal
, Folded
, SignColumn
, Statusline
and Tabline
groups will have a NONE
background color. Additional transparency may be achieved by overriding more highlight groups.
The theme supports changing the colors for Neovim's :terminal
:
options = {
terminal_colors = true
}
The theme supports changing the color of the main window in Neovim when focussed is lost. For example, when a telescope
or packer
pop up appears:
options = {
window_unfocussed_color = true
}
Note: This can be seen in the Python screenshots above where
nvim-tree
is opened and out of focus
Cursorline highlighting is supported in the theme using a cursorline
color (which may of course be overriden). This can be enabled with the following:
colors = {
cursorline = "#FF0000" -- This is optional. The default cursorline color is based on the background
},
options = {
cursorline = true
}
The theme comes with Alacritty and Kitty themes. These can be found in the extras folder.
To enable the theme's colors to be extracted and used elsewhere in the Neovim config, a helper function, get_colors()
, has been included. This returns a table of the theme's current colors.
local colors = require("onedarkpro").get_colors(vim.g.onedarkpro_style)
print(colors.purple) -- #9a77cf
Note: The global variable
vim.g.onedarkpro_style
automatically detects whether to use theonedark
oronelight
theme.
To enable the easy switching between themes, the following helper function could be used:
function ToggleTheme()
if vim.o.background == "dark" then
vim.o.background = "light"
else
vim.o.background = "dark"
end
end
When configuring the theme, it may be useful to apply different colors or styles depending on whether onedark
or onelight
is active. This can be achieved by applying a conditional in the configuration:
hlgroups = {
TSField = {
fg = (vim.o.background == "dark" and "${red}" or "${green}")
}
}
Thanks to the following contributors for their work on the theme:
The following themes were used as an inspiration:
- One Dark Pro - The inspiration for this theme
- GitHub nvim theme - For the logo inspiration 😉