olimorris/onedark.nvim

github github
tree-sitter-supported-colorscheme plugin
star 103
stars
alert-circle 1
open issues
users 2
subscribers
git-branch 0
forks
CREATED

2021-04-07

UPDATED

3 days ago

packer

require('packer').startup(function()
  use 'olimorris/onedark.nvim'
end)

paq

require "paq" { 
  'olimorris/onedark.nvim'
}

OneDarkPro.nvim

:book: Table of Contents

:sparkles: Features

:camera: Screenshots

Dark

Python

React

Light

Python

React

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 you're 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 your init.lua file to start using the theme:

require('onedarkpro').load()

Alternatively, if you're using Vimscript:

colorscheme onedarkpro

Note: You can use vim.o.background to set the theme

vim.o.background = "light" -- to load onelight
require('onedarkpro').load()

Default configuration

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

local onedarkpro = require('onedarkpro')
onedarkpro.setup({
  theme = function(), -- Override with "onedark" or "onelight". Alternatively, remove the option and the theme uses `vim.o.background` to determine
  colors = {}, -- Override default colors. Can specify colors for "onelight" or "onedark" themes
  hlgroups = {}, -- Override default highlight groups
  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 you don't specify any value for theme, then the current value of vim.o.background will be used to set the theme.

Configuring styles

Styles can be set by specifying the highlight group from the theme.lua file alongside your 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 and 7 additional colors (for both onelight and onedark themes). 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

You can specify new colors which will be merged into the theme's color palette:

colors = {
  my_new_red = '#f44336'
}

Note: Your custom colors can be referenced in highlight group overrides

Specifying colors by theme

As an example, you may wish to change the theme's default bg color. 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 uses a large array of highlight groups. There are three ways to customize them:

  1. Using specifc hex colors
  2. Referencing the name of color variables
  3. Linking to other highlight groups in the theme
hlgroups = {
  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 to match VS Code's One Dark Pro. 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 can be applied by overriding the 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 your 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 your 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, heavily, as an inspiration:

  • One Dark Pro - The inspiration for this theme
  • Nightfox - For the general functionality of the theme which I used as the base
  • onedark.vim - For the original colors and their application in Neovim

:page_with_curl: License

MIT