Skip to content

Latest commit

 

History

History
476 lines (370 loc) · 17.4 KB

README.md

File metadata and controls

476 lines (370 loc) · 17.4 KB

OneDarkPro.nvim

OneDarkPro.nvim

Highly customisable Neovim colorscheme. With support for custom colors, styles and highlights by filetype
Inspired by VS Code's One Dark Pro

onedark

onedark

onelight

onelight

onedark vivid

onedark vivid

onedark dark

onedark dark

📖 Table of Contents

✨ Features

  • Override default styles, colors and highlight groups
  • Create custom highlight groups and even highlight groups by filetypes
  • Treesitter support
  • Support for many popular plugins

⚡ Requirements

  • Neovim 0.5+ (0.7+ for filetype highlights)
  • termguicolors enabled for true color support
  • treesitter for full syntax highlighting

📦 Installation

Install with your package manager:

use "olimorris/onedarkpro.nvim"    -- Packer
Plug 'olimorris/onedarkpro.nvim'   " Vim-Plug

🚀 Usage

Use the built-in :colorscheme command to load:

vim.cmd("colorscheme onedarkpro")  -- Lua
colorscheme onedarkpro             " Vimscript

🔧 Configuration

Default configuration

A call to the setup function is only required if you wish to change the default values listed below:

require("onedarkpro").setup({
  dark_theme = "onedark", -- The default dark theme
  light_theme = "onelight", -- The default light theme
  colors = {}, -- Override default colors by specifying colors for 'onelight' or 'onedark' themes
  highlights = {}, -- Override default highlight groups
  ft_highlights = {}, -- Override default highlight groups for specific filetypes
  plugins = { -- Override which plugin highlight groups are loaded
    -- See the Supported Plugins section for a list of available plugins
  },
  styles = { -- Choose from "bold,italic,underline"
      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 colorscheme's opinionated bold styles?
      italic = false, -- Use the colorscheme's opinionated italic styles?
      underline = false, -- Use the colorscheme's opinionated underline styles?
      undercurl = false, -- Use the colorscheme's opinionated undercurl styles?
      cursorline = false, -- Use cursorline highlighting?
      transparency = false, -- Use a transparent background?
      terminal_colors = false, -- Use the colorscheme's colors for Neovim's :terminal?
      window_unfocused_color = false, -- When the window is out of focus, change the normal background?
  }
})

Note: You only need to include values that you wish to change from the defaults!

Configuring themes

Currently, there are four themes available:

  • onedark
  • onelight
  • onedark_vivid
  • onedark_dark

A default main theme can be set with:

theme = "onedark_vivid",

If no value is specified, the colorscheme will use the values as per the default config which uses vim.o.background. With a dark background, the theme will use onedark and with a light background, onelight, by default. For greater customisation with vim.o.background, default dark and light themes can be set:

dark_theme = "onedark_vivid",
light_theme = "onelight",

Configuring plugins

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, and their names, see the plugins section

Configuring styles

Within the colorscheme, collections of highlight groups have been grouped together into styles. For users who use monospaced fonts with nice italics, this can go someway to enhancing the aesthetic of the colorscheme. These styles may be configured as below:

styles = {
  comments = "italic",
  functions = "NONE",
  keywords = "bold,italic",
  strings = "NONE",
  variables = "NONE",
  virtual_text = "NONE"
}

| Note: See the Neovim help for a full list of styles

Configuring colors

The colorscheme has a palette of 13 core colors alongside many additional ones which are used for menus and git diffs. These colors can be found in the themes.

The default colors can be changed by specifying the name of the color and a new hex code:

colors = {
  red = "#FF0000"
}

Specifying new colors

New colors may be created which will then be merged into a theme's color palette:

colors = {
  my_new_red = "#f44336"
}

Note: Custom colors can also be referenced when creating custom highlight group overrides

Specifying colors by theme

It's possible to override default colors within a 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 editor, syntax and plugin files use a large array of highlight groups. There are three ways to customize or override them:

  1. Using specific hex colors:
highlights = {
  Comment = { fg = "#FF0000", bg = "#FFFF00" }
}
  1. Referencing the name of colors:
highlights = {
  Comment = { fg = "${my_new_red}" bg = "${yellow}" }
}
  1. Linking to other highlight groups:
highlights = {
  Comment = { link = "Substitute" }
}

Configuring filetype highlight groups

The original One Dark Pro utilises custom highlights based on filetype to achieve its distinctive look. This can also be achieved within the colorscheme:

ft_highlights = {
  -- Use the filetype as per the `set filetype?` command
  yaml = {
    TSField = { fg = "${red}" }
  },
  python = {
    TSConstructor = { fg = "${bg}", bg = "${red}" }
  }
}

Note:

  • Neovim 0.7+ is required for filetype highlights
  • Currently support for highlighting in Telescope's previewer is unavailable
  • Please see this issue for how other users are configuring their theme by filetype
  • The excellent hlargs.nvim plugin allows for greater customisation over arguments definitions and usages

Ignoring filetypes and buffer types

Certain file and buffer types may be ignored to prevent filetype highlights being overwritten when navigating to a new buffer. The default types to be ignored are:

ft_highlights_ignore = {
  filetypes = {
    "^aerial$",
    "^alpha$",
    "^fugitive$",
    "^fugitiveblame$",
    "^help$",
    "^NvimTree$",
    "^packer$",
    "^qf$",
    "^startify$",
    "^startuptime$",
    "^TelescopePrompt$",
    "^TelescopeResults$",
    "^terminal$",
    "^toggleterm$",
    "^undotree$"
  },
  buftypes = {
    "^terminal$"
  }

Configuring options

Formatting

Alongside styles, the colorscheme applies some opinionated formatting. These can be configured with the following options:

options = {
  bold = true, -- Use the colorscheme's opinionated bold styles?
  italic = true, -- Use the colorscheme's opinionated italic styles?
  underline = true, -- Use the colorscheme's opinionated underline styles?
  undercurl = true -- Use the colorscheme's opinionated undercurl styles?
}

Transparency

The colorscheme supports transparent backgrounds:

options = {
  transparency = true
}

By setting the transparency option to true, the Normal, Folded, SignColumn, Statusline and Tabline groups will have NONE as the background color. Additional transparency may be achieved by overriding more highlight groups.

Terminal Colors

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

options = {
  terminal_colors = true
}

Window Focus Color

The colorscheme supports changing the color of the main window in Neovim when the focus is lost. For example, when a telescope or packer pop up appears:

options = {
  window_unfocused_color = true
}

Note: This can be seen in the screenshots above where nvim-tree is opened and out of focus

Cursorline

Cursorline highlighting is supported in the colorscheme using a cursorline color (which may of course be overridden). 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
}

🔌 Supported Plugins

The colorscheme supports the following plugins:

🔬 Comparison to VS Code's One Dark Pro

Python

Comparison to VS Code - Python

React

Comparison to VS Code - React

Note: A greater likeness to Visual Studio Code can be achieved by using the theme's ability to customise highlight groups by filetype

🎁 Extras

Lualine

The colorscheme has Lualine support out of the box for all of its themes. This can be found in the Lualine folder.

Terminal themes

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

Helpers

Theme color tables

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_theme)
print(colors.purple) -- #9a77cf

Note: The global variable vim.g.onedarkpro_theme represents the currently loaded theme

Toggling between themes

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

Configuring styles/colors/highlight groups based on the theme

When configuring the colorscheme, 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:

highlights = {
  TSField = {
    fg = (vim.o.background == "dark" and "${red}" or "${green}")
  }
}

❓ FAQs

I want to change X highlight group but I don't know what it is. How do I find out?

If you're using Treesitter then install Playground as this gives you access to the powerful :TSHighlightCapturesUnderCursor command. This shows any treesitter or syntax highlight groups under the cursor.

👏 Credits

Contributors

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

Inspiration

The following colorschemes were used as an inspiration: