olimorris/onedark.nvim

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

2021-04-07

UPDATED

11 hours 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

Color guide

Dark

Light

Comparison to VS Code's One Dark Pro

Python

React

Note: All screenshots have Treesitter highlighting enabled

: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 select 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({
  -- The theme to be used. Can be either `onedark` or `onelight`. Leave blank to let `vim.o.background` dictate
  theme = function()
        if vim.o.background == "dark" then
            return "onedark"
        else
            return "onelight"
        end
    end,
  colors = {}, -- Override default colors
  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?
      transparent = false, -- Use a transparent background?
      highlight_cursorline = false, -- Use cursorline highlighting?
  }
})
onedarkpro.load()

Configuring the theme

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

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

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

You may wish to change the theme's default bg color, as an example. For the onedark and onelight themes, it would make sense to have separate colors for both. This can be achieved by specifying the theme name as a table, followed by the color:

colors = {
  onelight = {
    bg = "#00FF00", -- green
  },
  onedark = {
    bg = "#FFFF00", -- yellow
  },
}

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

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 = {
  highlight_cursorline = true
}

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

:clap: Credits

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