nightfox.nvim

repository·main·Indexed 26 days ago

https://github.com/edeneast/nightfox.nvim

A highly customizable colorscheme for Vim and Neovim supporting LSP, Treesitter, and various plugins. It features multiple palettes (Nightfox, Dayfox, Nordfox, etc.), a colorblind mode with daltonization and simulation, and a compilation system for fast startup times. Users can deeply customize the theme via three layers: palettes (base colors), specs (logical mappings), and groups (highlight groups).

Tokens
6.5K
Snippets
19
Records
30
Agent score
38%

What's inside nightfox.nvim

  1. Overview of nightfox.nvim features

    main

    nightfox.nvim is a highly customizable theme for Vim and Neovim. Key features include:

    • Support for both Vim and Neovim.
    • Highly configurable via template overriding.
    • Colorblind mode: Includes daltonization and simulation.
    • Support for multiple plugins and status lines.
    • Compilation: Compiles user configurations for fast startup times.
    • Color library: Exports a color library utility.
    • Interactive mode: Supports live configuration re-loading.
  2. Manage plugin modules

    main
    Nightfox uses modules to store configuration for various plugins. Modules are enabled by default. To change this, set options.module_default to false. To enable or configure a specific module, set the module key to true or provide a table with { enable = true, ... } for additional configuration.
  3. Use NightfoxInteractive for live configuration reloading

    main

    The :NightfoxInteractive command allows you to see changes to your Nightfox configuration immediately upon saving the file. It attaches an autocmd to the current buffer that triggers on BufferWritePost, clears the internal state, re-sources the config, and resets the colorscheme.

    Note: This requires executing luafile on the current file. If you use packer.nvim and have your config inside a config = function() end block, this method will not work as packer would require re-compilation.

    :NightfoxInteractive
  4. Requirements for nightfox.nvim

    main

    Ensure your environment meets the following requirements:

    • Neovim: >= 0.8 or Vim 9 with lua = 5.1+
    • True color support: Required. (Note: MacOS default terminal does not support true color; use Iterm2 or another compatible terminal).
    • Undercurl terminal support: Optional.
  5. Configure Nightfox using init() and overrides

    main

    You can set components separately using init() for general options and the override module for specific components. Overrides for palettes and specs are defined per style, while groups are applied globally (using the all key).

    -- Set general options
    require('nightfox').init({
      dim_inactive = true,
    })
    
    -- Set specific overrides
    local override = require('nightfox').override
    override.palettes({
      nightfox = {
        red = "#c94f6d",
      },
      nordfox = {
        comment = "#60728a",
      },
    })
    override.specs({
      nightfox = {
        syntax = {
          keyword = "magenta"
        }
      }
    })
    override.groups({
      all = {
        IncSearch = { bg = "palette.cyan" },
      },
    })
  6. Integrate nightfox with Lualine or Lightline

    main

    When using status line plugins, ensure the colorscheme is set correctly so the plugin can detect the theme.

    Lualine: Checks vim.g.colors_name. Set the colorscheme before calling setup.

    Lightline: Checks vim.g.lightline.colorscheme. You must set this value explicitly.

    -- Lualine
    vim.cmd("colorscheme nightfox")
    require('lualine').setup({ ... })
    -- Lightline
    vim.cmd("colorscheme nightfox")
    vim.g.lightline = { colorscheme = "nightfox" }
  7. Configure Nightfox using setup()

    main

    The setup() function is a convenience wrapper that allows you to configure all components of Nightfox (options, palettes, specs, and groups) in a single call. This is the recommended way to apply a complete custom configuration.

    local options = {
      dim_inactive = true,
    }
    local palettes = {
      nightfox = {
        red = "#c94f6d",
      },
      nordfox = {
        comment = "#60728a",
      },
    }
    local specs = {
      nightfox = {
        syntax = {
          keyword = "magenta"
        }
      }
    }
    local groups = {
      all = {
        IncSearch = { bg = "palette.cyan" },
      },
    }
    require('nightfox').setup({
      options = options,
      palettes = palettes,
      specs = specs,
      groups = groups,
    })
  8. Manage plugin support via Modules

    main

    Modules allow you to enable or disable extra information and highlight groups for specific plugins or features.

    There are two types of modules:

    1. Base modules: A simple boolean indicating if the module is enabled.
    2. Extended modules: A table containing an enable field (boolean) and additional customization options.

    Neovim-specific modules (enabled by default on Neovim):

    • diagnostic
    • native_lsp
    • treesitter

    Commonly used modules: alpha, aerial, barbar, cmp, coc, dap-ui, dashboard, fern, fidget, gitgutter, gitsigns, hop, illuminate, indent_blanklines, lazy.nvim, leap, mini, modes, navic, neogit, neotest, neotree, notify, nvimtree, telescope, whichkey, and more.

  9. Identify Syntax Highlight Groups

    main

    To determine which highlight group is applied to a specific piece of syntax:

    1. Treesitter: Use the :Inspect command.
    2. Vim Highlighting: Use a custom function to output the stack of highlight groups under the cursor.
    " Output the highlight group under the cursor
    function! SynStack()
      for i1 in synstack(line("."), col("."))
        let i2 = synIDtrans(i1)
        let n1 = synIDattr(i1, "name")
        let n2 = synIDattr(i2, "name")
        echo n1 "->" n2
      endfor
    endfunction
    
    map <F2> <cmd>call SynStack()<cr>
  10. Extend palettes and specs with custom template values

    main

    You can create custom template values in specs to distinguish between different uses of the same color. For example, you can define an inactive value in specs that points to a specific palette color, and then use that inactive name in your groups configuration.

    require("nightfox").setup({
      palettes = {
        duskfox = {
          bg1 = "#000000",
          bg0 = "#1d1d2b",
          bg3 = "#121820",
          sel0 = "#131b24",
        },
      },
      specs = {
        all = {
          inactive = "bg0",
        },
        duskfox = {
          inactive = "#090909",
        },
      },
      groups = {
        all = {
          NormalNC = { fg = "fg1", bg = "inactive" },
        },
      },
    })
  11. Use Interactive mode for configuration

    main

    The NightfoxInteractive command allows you to see configuration changes in real-time. It attaches an autocmd to the current buffer that triggers on BufferWritePost. When you save your config file, Nightfox will clear its internal state, re-source the config, and reset the colorscheme automatically.

    Note: This requires executing luafile on the current file. If you use packer.nvim with a config = function() end block, this mode will not work as Packer requires re-compilation.

    NightfoxInteractive