olimorris/onedarkpro.nvim

github github
tree-sitter-supported-colorscheme
star 133
stars
alert-circle 1
open issues
users 3
subscribers
git-branch 1
forks
CREATED

2021-04-07

UPDATED

8 days ago


OneDarkPro.nvim

:book: Table of Contents

:sparkles: Features

:camera: Screenshots

Dark

Light

Note: All screenshots have Treesitter highlighting enabled

Comparison to VS Code's One Dark Pro

Python

React

Lualine

Dark

Light

Color guide

Dark

Light

:zap: Requirements

  • Neovim 0.5 or greater
  • termguicolors enabled for true color support
  • treesitter for full syntax highlighting

:package: Installation

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()

:wrench: Configuration

Setup

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()

Note: This assumes that no value for theme is set in the setup function (see below)

Default configuration

The theme's default configuration as per the config.lua file is:

local onedarkpro = require("onedarkpro")
onedarkpro.setup({
  -- Theme can be overwritten with 'onedark' or 'onelight' as a string!
  theme = function()
    if vim.o.background == "dark" then
      return "onedark"
    else
      return "onelight"
    end
  end,
  colors = {}, -- Override default colors. Can specify colors for "onelight" or "onedark" themes by passing in a table
  hlgroups = {}, -- Override default highlight groups
  plugins = { -- Override which plugins highlight groups are loaded
      native_lsp = true,
      polygot = true,
      treesitter = true,
      -- Others 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
  },
  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?
      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()

Configuring the theme

Use either onedark or onelight for the dark and light themes, respectively.

theme = "onedark", -- [onedark/onelight] 

If no value is specified, the current value of vim.o.background will be used to set the theme.

Configuring plugins

By default, all 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,
}

Note: For a full list of plugins, see the plugins folder

Configuring styles

Styles can be set by specifying the highlight group from the theme.lua file alongside any desired styles:

styles = {
  comments = "italic",
  functions = "NONE",
  keywords = "bold,italic",
  strings = "NONE",
  variables = "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

Configuring colors

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"
}

Specifying new colors

New colors may be specified which will then be merged into the theme's color palette:

colors = {
  my_new_red = "#f44336"
}

Note: Custom colors can be referenced in highlight group overrides

Specifying colors by theme

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
  },
}

Configuring highlight groups

The theme.lua file and plugins use a large array of highlight groups. There are three ways to customize them:

  1. Using specific hex colors
  2. Referencing the name of color variables
  3. 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
}

Configuring options

Formatting

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?
}

Transparency

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.

Terminal Colors

The theme supports changing the colors for Neovim's :terminal:

options = {
  terminal_colors = true
}

Window Focus Color

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

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
}

:gift: Extras

Terminal themes

The theme comes with Alacritty and Kitty themes. These can be found in the extras folder.

Helper functions

Theme color tables

To enable plugins to match this theme, a helper function, get_colors(), has been included. This returns a table of the theme's current colors.

local colors = require("onedarkpro").get_colors("onelight")
print(colors.purple) -- #9a77cf

Changing the theme from onelight to onedark would return a new table of colors.

Note: Setting a ColorScheme autocommand which refreshes the configuration of the relevant plugin will ensure that they are using the correct colors from One Dark Pro

Toggling between Onedark and Onelight

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
  require("onedarkpro").load()
end

:clap: Credits

Contributors

Thanks to the following contributors for their work on the theme:

Inspiration

The following themes were used as an inspiration:

  • One Dark Pro - The inspiration for this theme
  • Nightfox - Originally used the theme's layout and utilities however moved away quite significantly since
  • onedark.vim - For the application of onedark colors in Neovim
  • GitHub nvim theme - For the logo inspiration :wink:

:page_with_curl: License

MIT