snacks.nvim

repository·main·Indexed 27 days ago

https://github.com/folke/snacks.nvim

A collection of small, high-quality Neovim plugins designed to improve developer experience through UI enhancements, utilities, and workflow optimizations. Features include a picker for files, git, and LSP; a dashboard; a notifier; bigfile handling for large files; and various utilities like Zen mode, scratch buffers, and terminal toggles. Requires Neovim >= 0.9.4.

Tokens
39.4K
Snippets
126
Records
222
Agent score
93%

What's inside snacks.nvim

  1. Overview of snacks.nvim features

    main

    snacks.nvim is a collection of small Quality of Life (QoL) plugins for Neovim. Key features include:

    • UI & Aesthetics: animate, dashboard, dim, indent, notifier, scroll, statuscolumn, zen.
    • File & Buffer Management: bigfile, bufdelete, explorer, quickfile, rename.
    • Navigation & Selection: picker, scope, words.
    • Utilities: debug, gh (GitHub CLI), git, gitbrowse, input, keymap, layout, lazygit, terminal, toggle, win.
    • Developer Tools: profiler, scratch, image (via Kitty Graphics Protocol).
  2. Use the Snacks picker for fuzzy finding

    main
    The snacks.nvim picker is a modern fuzzy-finder for Neovim. It features over 40 built-in sources, a fast fuzzy matching engine supporting fzf syntax (including field searches like file:lua$ 'function), and asynchronous finders/matchers. It uses Treesitter for highlighting and provides various layouts via Snacks.layout.
  3. Use bigfile to handle large files automatically

    main

    bigfile is a feature in snacks.nvim that introduces a new filetype bigfile when a file exceeds a configured size threshold. This mechanism is designed to prevent performance degradation by automatically stopping heavy plugins like LSP and Treesitter from attaching to the buffer.

    By default, when a big file is detected, snacks.nvim enables syntax for the buffer and disables mini.animate (if present).

  4. Use the Scratch module for temporary buffers

    main

    The scratch module allows you to quickly open temporary buffers for testing code, taking notes, or experimentation. Scratch buffers are organized using context such as your working directory, Git branch, and vim.v.count1.

    Key features:

    • Lua Execution: In Lua buffers, pressing <cr> (Enter) executes the buffer or selection using Snacks.debug.run(), displaying print output inline and showing errors as diagnostics.
    • Persistence: Supports auto-saves when the buffer is hidden.
    • Organization: Uses templates and context-aware file naming to keep scratch sessions separate.
  5. Setup the animate module

    main

    To use the animate module, include snacks.nvim in your plugin manager (e.g., lazy.nvim) and provide an animate table within the opts configuration. You can leave the table empty to use default settings.

    -- lazy.nvim
    {
      "folke/snacks.nvim",
      ---@type snacks.Config
      opts = {
        animate = {
          -- your animate configuration comes here
          -- or leave it empty to use the default settings
        }
      }
    }
  6. Setup gitbrowse with lazy.nvim

    main

    To use gitbrowse, add snacks.nvim to your lazy.nvim configuration. You can provide custom configuration for gitbrowse within the opts table. If you leave it empty, it will use the default settings.

    -- lazy.nvim
    {
      "folke/snacks.nvim",
      ---@type snacks.Config
      opts = {
        gitbrowse = {
          -- your gitbrowse configuration comes here
          -- or leave it empty to use the default settings
          -- refer to the configuration section below
        }
      }
    }
  7. Navigate the Snacks Explorer

    main

    Use the following keybindings to navigate the file tree:

    • <CR> or l: Open file or toggle directory.
    • h: Close directory.
    • <BS> (Backspace): Go up one directory.
    • .: Focus on current directory (sets it as cwd).
    • H: Toggle hidden files.
    • I: Toggle ignored files (from .gitignore).
    • Z: Close all directories.

    Quick Actions

    • <leader>/: Grep in the current directory.
    • <c-t>: Open terminal in the current directory.
    • <c-c>: Change tab directory to the current directory.
    • P: Toggle preview.
  8. Setup snacks.nvim indent

    main

    To use the indent feature in snacks.nvim, add it to your lazy.nvim configuration. You can provide an indent table within opts to customize the behavior, or leave it empty to use the default settings.

    -- lazy.nvim
    {
      "folke/snacks.nvim",
      ---@type snacks.Config
      opts = {
        indent = {
          -- your indent configuration comes here
          -- or leave it empty to use the default settings
          -- refer to the configuration section below
        }
      }
    }
  9. Install and configure the GitHub integration

    main

    To use the GitHub integration in snacks.nvim, you must have the GitHub CLI (gh) installed and authenticated. You also need the picker module enabled.

    Use the following lazy.nvim configuration to set up the module and recommended keymaps for browsing issues and pull requests:

    {
      "folke/snacks.nvim",
      opts = {
        gh = {
          -- your gh configuration comes here
          -- or leave it empty to use the default settings
        },
        picker = {
          sources = {
            gh_issue = {
              -- your gh_issue picker configuration comes here
            },
            gh_pr = {
              -- your gh_pr picker configuration comes here
            }
          }
        },
      },
      keys = {
        { "<leader>gi", function() Snacks.picker.gh_issue() end, desc = "GitHub Issues (open)" },
        { "<leader>gI", function() Snacks.picker.gh_issue({ state = "all" }) end, desc = "GitHub Issues (all)" },
        { "<leader>gp", function() Snacks.picker.gh_pr() end, desc = "GitHub Pull Requests (open)" },
        { "<leader>gP", function() Snacks.picker.gh_pr({ state = "all" }) end, desc = "GitHub Pull Requests (all)" },
      },
    }
  10. Configure the Snacks Dashboard layout

    main

    The snacks.dashboard allows you to create custom startup screens using a sections list. Each section can be a predefined section name (like header, keys, recent_files, projects, or startup), a terminal command, or a custom function.

    Key configuration options for items include:

    • pane: The pane number to place the section in.
    • section: The name of the section to include.
    • icon: An icon to display.
    • title: A title for the section.
    • indent: Number of spaces for indentation.
    • padding: Bottom or {bottom, top} padding.
    • key: A shortcut key for the item.
    • action: The action to run (command starting with :, a keymap string, or a function).
    • enabled: A boolean or function to determine if the section should be shown.
    {
      sections = {
        { section = "header" },
        { 
          pane = 2, 
          icon = " ", 
          title = "Recent Files", 
          section = "recent_files", 
          indent = 2, 
          padding = 1 
        },
        { section = "startup" },
      ,
    }
  11. Setup the snacks.nvim layout module

    main

    To use the layout module, configure it within your lazy.nvim setup. You can provide a custom configuration or leave it empty to use the default settings.

    -- lazy.nvim
    {
      "folke/snacks.nvim",
      ---@type snacks.Config
      opts = {
        layout = {
          -- your layout configuration comes here
          -- or leave it empty to use the default settings
          -- refer to the configuration section below
        }
      }
    }
  12. Install and configure bigfile with lazy.nvim

    main

    To use the bigfile feature, add snacks.nvim to your lazy.nvim configuration and provide a bigfile table within the opts object.

    -- lazy.nvim
    {
      "folke/snacks.nvim",
      ---@type snacks.Config
      opts = {
        bigfile = {
          -- your bigfile configuration comes here
          -- or leave it empty to use the default settings
        }
      }
    }