joshdick / onedark.vim

A dark Vim/Neovim color scheme inspired by Atom's One Dark syntax theme.
MIT License
3.91k stars 529 forks source link
colorscheme dark-syntax-theme lightline vim vim-airline vim-colorscheme

onedark.vim

A dark Vim/Neovim color scheme for the GUI and 16/256/true-color terminals, based on FlatColor, with colors inspired by the excellent One Dark syntax theme for the Atom text editor.

Color Reference

Color Reference

Breaking Changes

Pull request #271, merged July 11, 2021, contained several breaking changes, especially for 16-color users.

If you are an existing onedark.vim user that is suddenly having issues after this PR was merged, see the PR description for details.

Supported Plugins

onedark.vim includes support for the following Vim and Neovim plugins:

Installation

  1. Install the theme using your Vim plug-in manager of choice (or manually, by placing colors/onedark.vim in your ~/.vim/colors/ directory and autoload/onedark.vim in your ~/.vim/autoload/ directory.)

    The theme also supports being installed as a Vim 8 package. Simply clone this repository into ~/.vim/pack/*/opt/ (so that the local path to this README would end up being ~/.vim/pack/*/opt/onedark.vim/README.md) and add packadd! onedark.vim to your ~/.vimrc. (The * in the path can be any value; see :help packages for more information.)

  2. If you use Vim in a terminal, do the following to test whether your terminal emulator supports 24-bit/"true" color, then add relevant ~/.vimrc configuration if so:

    Note: GUI (non-terminal) Vim will always display 24-bit color regardless of the configuration done in this step.

    Run the following snippet in your shell:

    printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"

    If your terminal emulator does NOT display the word TRUECOLOR in red, it does not support 24-bit color. If you don't want to switch to a different terminal emulator that supports 24-bit color, proceed to step 3. (After installation, the g:onedark_termcolors option may interest you.)

    If your terminal emulator displays the word TRUECOLOR in red, it supports 24-bit color, and you should add the following lines to your ~/.vimrc to enable 24-bit color terminal support inside Vim.

    (If you use tmux, be sure to view the tmux-related notes in the first few lines.)

    "Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
    "If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
    "(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.)
    if (empty($TMUX))
     if (has("nvim"))
       "For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
       let $NVIM_TUI_ENABLE_TRUE_COLOR=1
     endif
     "For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
     "Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
     " < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
     if (has("termguicolors"))
       set termguicolors
     endif
    endif
  3. Add the following to your ~/.vimrc (below any lines you may have added in steps 1 and 2):

    syntax on
    colorscheme onedark
  4. Installing the sheerun/vim-polyglot plug-in is recommended for improved syntax highlighting for various languages, but is not required.

Options

Note: All options should be set before the colorscheme onedark line in your ~/.vimrc.

lightline.vim Colorscheme

lightline-onedark.vim Preview

This repository includes a companion lightline.vim colorscheme for use with onedark.vim.

The lightline.vim colorscheme:

Installation

(These instructions assume that lightline.vim and onedark.vim are already installed and configured to your liking.)

Place onedark.vim/autoload/lightline/colorscheme/onedark.vim in your ~/.vim/autoload/lightline/colorscheme/ directory either manually or by using your Vim plug-in manager of choice, then add the following lines to your ~/.vimrc (or merge them into your existing lightline.vim configuration):

let g:lightline = {
  \ 'colorscheme': 'onedark',
  \ }

vim-airline Theme

airline-onedark.vim Preview

This repository includes a companion vim-airline theme for use with onedark.vim.

The vim-airline theme:

Installation

(These instructions assume that vim-airline and onedark.vim are already installed and configured to your liking.)

Place onedark.vim/autoload/airline/themes/onedark.vim in your ~/.vim/autoload/airline/themes/ directory either manually or by using your Vim plug-in manager of choice, then add the following line to your ~/.vimrc:

let g:airline_theme='onedark'

Troubleshooting

Why do the colors in terminal Vim look totally crazy?

Broken Colors

If Vim looks similar to the screenshot above, you have enabled Vim's 24-bit color terminal support, but your terminal doesn't support 24 bit color. Remove the relevant ~/.vimrc configuration for enabling 24-bit color support to get things looking better.

Why do the colors in terminal Vim look slightly off/not like the preview image at the top of this README?

If your terminal doesn't support 24-bit color as described in the Installation section of this README, or 24-bit color support is not always available everywhere you use your Vim configuration, colors will not look like they do in the preview image.

However, you can use the g:onedark_termcolors option to control onedark.vim's fallback colors in situations where 24-bit color terminal support is not available.

g:onedark_termcolors can be set to one of two values, 256 for 256-color mode (the default), or 16 for 16-color mode (which uses your terminal emulator's native 16 colors.)

When Vim/Neovim are configured to use 24-bit color, the g:onedark_termcolors option is ignored. However, g:onedark_termcolors can still coexist with 24-bit color configuration. For instance, when tmux 2.1 or earlier and/or older Vim/Neovim versions that don't support 24-bit color are used, the g:onedark_termcolors option will take effect.

Why do all comments look like they're highlighted?

Broken Italics

If all comments look like the one in the screenshot above, you have enabled italics in onedark.vim by setting g:onedark_terminal_italics=1 in your ~/.vimrc, but your terminal isn't displaying italics correctly. You can either remove the option or try to fix your terminal. If you're using iTerm2 on macOS, you might need to use a special TERMINFO to get italics working.

Why do colors look washed out when using iTerm2?

Make sure that in Preferences, Profiles -> [Active Profile] -> Colors -> Minimum Contrast is turned all the way down. See #145 for more information.

Miscellaneous

Customizing onedark.vim's look without forking the repository

onedark.vim exposes onedark#extend_highlight and onedark#set_highlight functions that you can call from within your ~/.vimrc in order to customize the look of onedark.vim.

onedark#extend_highlight

onedark#extend_highlight allows you to customize individual aspects of onedark.vim's existing highlight groups, overriding only the keys you provide. (To completely redefine/override an existing highlight group, see onedark#set_highlight below.)

onedark#extend_highlight's first argument should be the name of a highlight group, and its second argument should be partial style data.

Place the following lines before the colorscheme onedark line in your ~/.vimrc, then change the example overrides to suit your needs:

if (has("autocmd"))
  augroup colorextend
    autocmd!
    " Make `Function`s bold in GUI mode
    autocmd ColorScheme * call onedark#extend_highlight("Function", { "gui": "bold" })
    " Override the `Statement` foreground color in 256-color mode
    autocmd ColorScheme * call onedark#extend_highlight("Statement", { "fg": { "cterm": 128 } })
    " Override the `Identifier` background color in GUI mode
    autocmd ColorScheme * call onedark#extend_highlight("Identifier", { "bg": { "gui": "#333333" } })
  augroup END
endif

onedark#set_highlight

onedark#set_highlight allows you to completely redefine/override highlight groups of your choosing.

onedark#set_highlight's first argument should be the name of a highlight group, and its second argument should be complete style data.

For example, to remove the background color only when running in terminals (outside GUI mode and for use in transparent terminals,) place the following lines before the colorscheme onedark line in your ~/.vimrc:

" onedark.vim override: Don't set a background color when running in a terminal;
" just use the terminal's background color
" `gui` is the hex color code used in GUI mode/nvim true-color mode
" `cterm` is the color code used in 256-color mode
" `cterm16` is the color code used in 16-color mode
if (has("autocmd") && !has("gui_running"))
  augroup colorset
    autocmd!
    let s:white = { "gui": "#ABB2BF", "cterm": "145", "cterm16" : "7" }
    autocmd ColorScheme * call onedark#set_highlight("Normal", { "fg": s:white }) " `bg` will not be styled since there is no `bg` setting
  augroup END
endif

Global color overrides

You can override colors across all highlights by adding color definitions to the g:onedark_color_overrides dictionary in your ~/.vimrc like so:

let g:onedark_color_overrides = {
\ "background": {"gui": "#2F343F", "cterm": "235", "cterm16": "0" },
\ "purple": { "gui": "#C678DF", "cterm": "170", "cterm16": "5" }
\}

This also needs to be done before colorscheme onedark.

More examples of highlight group names and style data can be found in onedark.vim's source code (colors/onedark.vim inside this repository).

tmux theme

If you'd like a tmux theme that complements onedark.vim, @odedlaz has you covered.

Contributing

If you'd like to contribute to onedark.vim, check out the contribution guidelines.

Relatives of onedark.vim

Several other themes and projects have reused code and/or colors from this project, or were otherwise inspired by it.

If onedark.vim isn't meeting your needs, try one of its relatives!

Preview images

Preview images were taken using: