### MiniIcons Setup with Customizations Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md An example of calling the `MiniIcons.setup()` function with custom configurations for styles, icon overrides for extensions and files, and a custom `use_file_extension` function. ```lua require('mini.icons').setup({ style = 'glyph', extension = { lua = { hl = 'LuaHl' }, yml = { glyph = '󰫯', hl = 'YamlHl' } }, file = { ['Makefile'] = { glyph = '󱁤', hl = 'MakeHl' } }, use_file_extension = function(ext, file) -- Ignore yml/json/txt to use filetype detection return not vim.tbl_contains({'yml', 'json', 'txt'}, ext) end }) ``` -------------------------------- ### Comprehensive Configuration Example Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/types.md An example showcasing various configuration options, including icon overrides for extensions and files, and a custom `use_file_extension` callback. ```lua local config = { style = 'glyph', extension = { lua = { glyph = '󰢱', hl = 'MiniIconsAzure' }, rust = { glyph = '󱘗', hl = 'MiniIconsRed' }, py = 'python' -- Inherit from Python filetype }, file = { ['Makefile'] = { glyph = '󱁤', hl = 'MiniIconsGrey' } }, use_file_extension = function(ext, file) return not vim.tbl_contains({'yml', 'json'}, ext) end } ``` -------------------------------- ### Basic Icon Definition Example Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/types.md Example of creating an icon definition and applying it to a specific file extension using `MiniIcons.setup()`. ```lua local icon_def = { glyph = '󰢱', hl = 'MiniIconsAzure' } require('mini.icons').setup({ extension = { lua = icon_def -- Apply to Lua files } }) ``` -------------------------------- ### Minimal Setup Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/configuration.md Initialize the mini.icons plugin with default settings. ```lua require('mini.icons').setup() -- Uses all defaults ``` -------------------------------- ### Customize Icons with Setup Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Shows how to customize icons for specific categories using the setup function. This includes overriding glyphs and highlight groups for default, extension, and other categories. ```lua require('mini.icons').setup({ default = { -- Override default glyph for "file" category (reuse highlight group) file = { glyph = '󰈤' }, }, extension = { -- Override highlight group (not necessarily from 'mini.icons') lua = { hl = 'Special' }, -- Add icons for custom extension. This will also be used in -- 'file' category for input like 'file.my.ext'. ['my.ext'] = { glyph = '󰻲', hl = 'MiniIconsRed' }, }, }) ``` -------------------------------- ### Example use_file_extension Callback Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/types.md An example implementation of the `use_file_extension` callback. This specific example skips common text-based file extensions to rely on filetype detection instead. ```lua use_file_extension = function(ext, file) -- Skip yml/json/txt to rely on filetype detection if vim.tbl_contains({'yml', 'json', 'txt'}, ext) then return false end return true end ``` -------------------------------- ### Install Standalone mini.icons with lazy.nvim (Stable Branch) Source: https://github.com/nvim-mini/mini.icons/blob/main/README.md Use this snippet to install the stable branch of the mini.icons plugin with lazy.nvim. Set version to '*'. ```lua { 'nvim-mini/mini.icons', version = '*' }, ``` -------------------------------- ### Install Standalone mini.icons with mini.deps (Main Branch) Source: https://github.com/nvim-mini/mini.icons/blob/main/README.md Install the main development branch of the mini.icons plugin using the mini.deps plugin manager. ```lua add('nvim-mini/mini.icons') ``` -------------------------------- ### Install Standalone mini.icons with vim.pack (Main Branch) Source: https://github.com/nvim-mini/mini.icons/blob/main/README.md Use this snippet to install the main development branch of the mini.icons plugin using vim.pack. ```lua vim.pack.add({ 'https://github.com/nvim-mini/mini.icons' }) ``` -------------------------------- ### Direct Replacement for nvim-web-devicons Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md Shows how to replace `nvim-web-devicons` with `MiniIcons`. It includes setup and the equivalent `get` call. Note that `MiniIcons.get` returns a highlight group name, not a color code. ```lua -- Old code with nvim-web-devicons -- local devicons = require('nvim-web-devicons') -- local icon, color = devicons.get_icon('init.lua') -- New code with MiniIcons require('mini.icons').setup() local icon, hl = MiniIcons.get('file', 'init.lua') -- Note: hl is highlight group name, not color code ``` -------------------------------- ### Install Standalone mini.icons with mini.deps (Stable Branch) Source: https://github.com/nvim-mini/mini.icons/blob/main/README.md Install the stable branch of the mini.icons plugin using mini.deps. Specify 'stable' for the checkout. ```lua add({ source = 'nvim-mini/mini.icons', checkout = 'stable' }) ``` -------------------------------- ### Install Standalone mini.icons with lazy.nvim (Main Branch) Source: https://github.com/nvim-mini/mini.icons/blob/main/README.md Use this snippet to install the main development branch of the mini.icons plugin with lazy.nvim. Set version to false. ```lua { 'nvim-mini/mini.icons', version = false }, ``` -------------------------------- ### Setup Mini.icons with Custom Configuration Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Initialize the mini.icons module with a custom configuration table. Replace the empty table with your specific settings. ```lua require('mini.icons').setup({}) ``` -------------------------------- ### Install Standalone mini.icons with vim.pack (Stable Branch) Source: https://github.com/nvim-mini/mini.icons/blob/main/README.md Use this snippet to install the stable branch of the mini.icons plugin using vim.pack. Specify 'stable' for the version. ```lua vim.pack.add({ { src = 'https://github.com/nvim-mini/mini.icons', version = 'stable' }, }) ``` -------------------------------- ### Get LSP Kind Icon Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Shows how to get icons for various LSP (Language Server Protocol) 'kind' values. ```lua MiniIcons.get('lsp', 'array') MiniIcons.get('lsp', 'keyword') ``` -------------------------------- ### Getting Icons for Non-Existent Files in Lua Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md Demonstrates how to get icons for file paths, even if the files do not exist. MiniIcons' `get` function can be used directly for this purpose, as it does not perform file existence checks. ```lua local function get_icon_for_path(path) -- MiniIcons doesn't check if path exists, so we can use it directly local icon, hl = MiniIcons.get('file', path) -- Can still determine icon for paths that don't exist yet return icon, hl end -- Both work equally well get_icon_for_path('/home/user/existing/file.lua') get_icon_for_path('/home/user/nonexistent/file.lua') ``` -------------------------------- ### Ensure MiniIcons Setup is Called Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/errors.md Create a wrapper function that automatically calls require('mini.icons').setup() if MiniIcons is not yet initialized, before proceeding with other operations. ```lua local function ensure_miniicons_get(category, name) if _G.MiniIcons == nil then require('mini.icons').setup() end return MiniIcons.get(category, name) end ``` -------------------------------- ### Filetype Inheritance Example Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/types.md Demonstrates how to inherit icon data from another filetype by specifying the filetype name as the value in the configuration. ```lua require('mini.icons').setup({ extension = { purs = 'purescript' -- Inherit PureScript filetype icon } }) ``` -------------------------------- ### use_file_extension Function Example Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md An example of the `use_file_extension` function, which determines if a file extension should be considered for icon resolution. This function returns `true` to consider the extension or `false` to skip it. ```lua use_file_extension = function(ext, file) -- Ignore 'scm' extension to use vim.filetype.match() for query files return ext:sub(-3) ~= 'scm' end ``` -------------------------------- ### Conditional Configuration Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/configuration.md Dynamically configure mini.icons based on environment variables or other conditions. This example adds a Lua icon only if the 'lua' executable is available. ```lua local function get_miniicons_config() local config = { style = 'glyph', extension = {} } -- Add extensions based on environment if vim.fn.executable('lua') == 1 then config.extension.lua = { glyph = '󰢱', hl = 'MiniIconsAzure' } end return config end require('mini.icons').setup(get_miniicons_config()) ``` -------------------------------- ### Get Icon and Highlight Group Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Demonstrates how `MiniIcons.get` returns the icon string, its suggested highlight group, and a boolean indicating if it's a default fallback. ```lua -- Results into `icon='󰢱'`, `hl='MiniIconsAzure'`, `is_default=false` local icon, hl, is_default = MiniIcons.get('file', 'file.lua') -- Results into `icon='󰈔'`, `hl='MiniIconsGrey'`, `is_default=true` local icon, hl, is_default = MiniIcons.get('file', 'not-supported') ``` -------------------------------- ### Get File Icon with Extension Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Demonstrates retrieving a file icon, showing that case and path variations for the extension do not affect the result. ```lua MiniIcons.get('extension', 'lua') MiniIcons.get('extension', 'LUA') MiniIcons.get('extension', 'my.lua') ``` -------------------------------- ### Get Operating System Icon Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Retrieves icons for popular operating systems. ```lua MiniIcons.get('os', 'linux') MiniIcons.get('os', 'arch') MiniIcons.get('os', 'macos') ``` -------------------------------- ### Default MiniIcons Configuration Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md Shows the default values for the MiniIcons configuration table. These defaults are applied if specific options are not provided during setup. ```lua MiniIcons.config = { style = 'glyph', default = {}, directory = {}, extension = {}, file = {}, filetype = {}, lsp = {}, os = {}, use_file_extension = function(ext, file) return true end, } ``` -------------------------------- ### Get Filetype Icon Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Demonstrates how to retrieve icons based on Neovim's filetype. ```lua MiniIcons.get('filetype', 'lua') MiniIcons.get('filetype', 'help') MiniIcons.get('filetype', 'minifiles') ``` -------------------------------- ### List Supported Icons for a Category Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Shows how to use `MiniIcons.list` to get an array of icon names explicitly supported within a given category. ```lua MiniIcons.list('file') ``` -------------------------------- ### Default Configuration for mini.icons Source: https://github.com/nvim-mini/mini.icons/blob/main/README.md This configuration object sets the default icon style to 'glyph' and provides empty tables for customizing icons per category. The `use_file_extension` function determines if file extensions should be considered. No need to copy this inside `setup()`, as it will be used automatically. ```lua -- No need to copy this inside `setup()`. Will be used automatically. { -- Icon style: 'glyph' or 'ascii' style = 'glyph', -- Customize per category. See `:h MiniIcons.config` for details. default = {}, directory = {}, extension = {}, file = {}, filetype = {}, lsp = {}, os = {}, -- Control which extensions will be considered during "file" resolution use_file_extension = function(ext, file) return true end, } ``` -------------------------------- ### Custom Icon Definition Example Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md Demonstrates how to override default icons or define new ones for specific categories like 'default' and 'extension'. You can specify the icon glyph and its highlight group. ```lua { default = { file = { glyph = '󰈤', hl = 'MiniIconsGrey' } }, extension = { lua = { hl = 'Special' }, -- Override highlight only ['my.ext'] = { glyph = '󰻲', hl = 'MiniIconsRed' } -- New extension } } ``` -------------------------------- ### Get ASCII Icons Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Demonstrates how to retrieve ASCII-compatible icons based on icon name and category. These are computed as the first character of the resolved icon name. ```lua MiniIcons.get('file', 'Makefile') -- Has 'M' as icon MiniIcons.get('extension', 'lua') -- Has 'L' as icon MiniIcons.get('file', 'file.lua') -- Has 'L' as icon; it is resolved to -- come from 'lua' 'extension' category MiniIcons.get('file', 'myfile') -- Has 'F' as icon; it is resolved to -- come from 'file' 'default' category ``` -------------------------------- ### Check MiniIcons Initialization and Get Icon Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md Verifies if MiniIcons is initialized before attempting to retrieve an icon. Returns the icon, its highlight group, and a boolean indicating if it's a default icon. ```lua if _G.MiniIcons ~= nil then local icon, hl, is_default = MiniIcons.get('file', 'myfile.lua') -- Use icon and hl end ``` -------------------------------- ### Adaptive Icon Style Based on Terminal Support Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md Dynamically determines the best icon style ('glyph' or 'ascii') based on Neovim version and Nerd Font availability. Setup mini.icons with the determined style. ```lua local function get_icon_style() -- Check for terminal capability if vim.fn.has('nvim-0.10') == 1 then -- Check for Nerd Font support local has_nerd_fonts = vim.fn.exists('*WebDevIconsGetFileTypeSymbol') == 1 return has_nerd_fonts and 'glyph' or 'ascii' end return 'ascii' end require('mini.icons').setup({ style = get_icon_style() }) ``` -------------------------------- ### Deferred Error on Invalid Highlight Group Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/errors.md Demonstrates how an invalid highlight group name in the setup configuration does not cause an immediate error. The error is deferred until the icon is actually used. ```lua require('mini.icons').setup({ extension = { lua = { hl = 'InvalidHl' } -- Error deferred until icon is actually used } }) ``` -------------------------------- ### MiniIcons.get() Return Value Structure Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/types.md The `get()` function returns a table containing the icon glyph, its associated highlight group, and a boolean indicating if it's a default fallback icon. ```lua icon: string, -- Icon glyph or ASCII character hl: string, -- Highlight group name is_default: boolean -- Whether icon is from fallback default ``` -------------------------------- ### Initialize MiniIcons Module Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md Call `MiniIcons.setup()` to initialize the module. You can use default settings or provide a custom configuration table. ```lua require('mini.icons').setup() ``` ```lua require('mini.icons').setup({ style = 'glyph', extension = { lua = { hl = 'Special' } } }) ``` -------------------------------- ### MiniIcons.setup Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md Initializes and configures the MiniIcons module. This function must be called before using any other MiniIcons functionality. It creates a global `MiniIcons` table accessible via `_G.MiniIcons`. ```APIDOC ## MiniIcons.setup(config) ### Description Initializes and configures the MiniIcons module. Must be called before using any MiniIcons functionality. Creates a global `MiniIcons` table accessible via `_G.MiniIcons`. ### Signature ```lua MiniIcons.setup(config: table|nil) -> nil ``` ### Parameters | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | config | table \| nil | No | nil | Module configuration table. See `MiniIcons.config` for structure. Pass `{}` for defaults. | ### Returns None. Sets up the module globally with `_G.MiniIcons = MiniIcons`. ### Example ```lua require('mini.icons').setup() -- Or with custom config require('mini.icons').setup({ style = 'glyph', extension = { lua = { hl = 'Special' } } }) ``` ### Source `lua/mini/icons.lua:190-214` ``` -------------------------------- ### Mock nvim-web-devicons with MiniIcons (Lua) Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/README.md Initialize MiniIcons and then call `mock_nvim_web_devicons()` to make plugins that expect `nvim-web-devicons` work seamlessly with MiniIcons. ```lua require('mini.icons').setup() MiniIcons.mock_nvim_web_devicons() -- Now plugins expecting nvim-web-devicons work ``` -------------------------------- ### LSP Integration for Completion Items Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md Initializes mini.icons and optionally tweaks LSP kind displays. Formats LSP completion items by prepending the appropriate icon based on the item's kind. ```lua -- Initialize MiniIcons require('mini.icons').setup() -- Optionally tweak LSP kind displays MiniIcons.tweak_lsp_kind('prepend') -- Add icon before kind name -- In your completion handler local function format_lsp_completion(item) local kind = item.kind or 'Text' local icon, hl = MiniIcons.get('lsp', kind) return { word = item.word, abbr = string.format('%s %s', icon, item.word), user_data = { hl_group = hl } } end ``` -------------------------------- ### nvim-web-devicons Compatibility Mock Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md Sets up mini.icons and then mocks the nvim-web-devicons API. This allows plugins that specifically require nvim-web-devicons to function correctly with mini.icons. ```lua require('mini.icons').setup() -- Mock nvim-web-devicons for plugins that only support it MiniIcons.mock_nvim_web_devicons() -- Now any plugin expecting nvim-web-devicons works local icons = require('nvim-web-devicons') local icon, color = icons.get_icon('init.lua') ``` -------------------------------- ### Get Default Icon Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/categories-and-icons.md Retrieves the default icon for a specified category. Use this when an icon is not found in other categories or for the 'default' category itself. ```lua local icon, hl, is_default = MiniIcons.get('default', 'file') -- Gets default icon for 'file' category ``` -------------------------------- ### Configuration Structure Definition Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/types.md Defines the complete structure for the configuration table passed to `MiniIcons.setup()`. This includes various categories for icon overrides and style options. ```lua { style: string, default: table, directory: table, extension: table, file: table, filetype: table, lsp: table, os: table, use_file_extension: function(ext: string, file: string) -> boolean } ``` -------------------------------- ### Lazy load MiniIcons.tweak_lsp_kind Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Demonstrates how to lazily load `MiniIcons.tweak_lsp_kind` using `MiniDeps.later` to avoid startup delays. This is recommended due to the potential loading time of the `vim.lsp` module. ```lua require('mini.icons').setup() MiniDeps.later(MiniIcons.tweak_lsp_kind) ``` -------------------------------- ### Advanced Configuration with File Extension Control Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/configuration.md Customize icons for extensions and directories, and control which extensions use file extension detection versus filetype detection. ```lua require('mini.icons').setup({ style = 'glyph', extension = { lua = { hl = 'MyLuaHighlight' }, yml = { glyph = '󰫯', hl = 'YamlHl' }, json = { glyph = '󰘦', hl = 'JsonHl' } }, directory = { ['.config'] = { glyph = '󱁿', hl = 'MiniIconsCyan' }, src = { glyph = '󰴉', hl = 'MiniIconsPurple' } }, use_file_extension = function(ext, file) -- Skip certain extensions to use filetype detection if vim.tbl_contains({'yml', 'json', 'txt'}, ext) then return false end return true end }) ``` -------------------------------- ### Default Configuration for Mini.icons Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt This shows the default configuration table for mini.icons. Customize options like 'style' and per-category settings as needed. ```lua MiniIcons.config = { -- Icon style: 'glyph' or 'ascii' style = 'glyph', -- Customize per category. See `:h MiniIcons.config` for details. default = {}, directory = {}, extension = {}, file = {}, filetype = {}, lsp = {}, os = {}, -- Control which extensions will be considered during "file" resolution use_file_extension = function(ext, file) return true end, } ``` -------------------------------- ### Get File Icon by Basename Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Retrieves a file icon using its basename. This method matches the basename exactly against configured and built-in file names. ```lua MiniIcons.get('file', 'init.lua') MiniIcons.get('file', '~/.config/nvim/init.lua') MiniIcons.get('file', '/home/user/.config/nvim/init.lua') ``` -------------------------------- ### List Available Icons in Mini.icons Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md Retrieve lists of supported icons by category, such as 'extension', 'file', or 'filetype'. Useful for exploration and validation. ```lua -- Get all supported extensions local extensions = MiniIcons.list('extension') print('Supported extensions:', table.concat(extensions, ', ')) -- Get all supported files local files = MiniIcons.list('file') print('Supported files:', #files) -- Get all supported filetypes local filetypes = MiniIcons.list('filetype') print('Supported filetypes:', #filetypes) ``` -------------------------------- ### Get Icon Data from Default Category Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Retrieve fallback icon data from the 'default' category. This is used when an icon name is not explicitly supported within the target category. ```lua MiniIcons.get('default', 'file') ``` -------------------------------- ### MiniIcons.mock_nvim_web_devicons() Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md Mocks the `nvim-tree/nvim-web-devicons` module by creating a compatible interface that internally uses `MiniIcons.get()` for icon resolution. This is useful for integrating with plugins that expect `nvim-web-devicons`. ```APIDOC ## MiniIcons.mock_nvim_web_devicons() ### Description Mock the `nvim-tree/nvim-web-devicons` module by creating a compatible interface that internally uses `MiniIcons.get()` for icon resolution. Useful for integrating with plugins that only support nvim-web-devicons. ### Parameters None. ### Returns None. Registers mocked functions in `package.preload` or `package.loaded` for the `nvim-web-devicons` module. ### Mocked Functions The following nvim-web-devicons functions are mocked: **Icon retrieval**: - `get_icon(name, ext, opts)`: Returns icon and highlight for file/extension - `get_icon_by_filetype(ft, opts)`: Returns icon and highlight for filetype - `get_icon_color(...)`: Returns icon, hex color - `get_icon_cterm_color(...)`: Returns icon, cterm color - `get_icon_colors(...)`: Returns icon, hex color, cterm color - `get_icon_color_by_filetype(...)`: Returns icon and hex color for filetype - `get_icon_cterm_color_by_filetype(...)`: Returns icon and cterm color for filetype - `get_icon_colors_by_filetype(...)`: Returns icon, hex color, cterm color for filetype - `get_icon_name_by_filetype(ft)`: Returns filetype as-is **Icon table retrieval**: - `get_default_icon()`: Returns default icon table with `icon`, `color`, `cterm_color`, `name` - `get_icons()`: Returns table of all default, OS, file, and extension icons - `get_icons_by_extension()`: Returns table of extension icons - `get_icons_by_filename()`: Returns table of file icons - `get_icons_by_operating_system()`: Returns table of OS icons **No-op functions**: - `has_loaded()`: Always returns `true` - `refresh()`: No operation - `setup()`: No operation - `set_default_icon()`: No operation - `set_icon()`: No operation - `set_icon_by_filetype()`: No operation - `set_up_highlights()`: No operation ### Behavior Notes - When both `name` and `ext` are provided to `get_icon()`, the `name` is preferred and `ext` is ignored - Color values are returned as hex strings (e.g., `#6d8086`) or cterm codes - Returns `nil` for default icons unless `opts.default = true` - Works with or without nvim-web-devicons already installed - Sets `vim.g.nvim_web_devicons = 1` for compatibility detection ### Example ```lua require('mini.icons').setup() MiniIcons.mock_nvim_web_devicons() -- Now plugins expecting nvim-web-devicons can use it local icon, color = require('nvim-web-devicons').get_icon('init.lua') -- Returns: icon='󰢱', color='#...' -- Check if mocked if require('nvim-web-devicons').has_loaded() then print('Icons available') end ``` ``` -------------------------------- ### Skip Specific Extension Based on Filename Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/configuration.md Conditionally skips a file extension based on a pattern match with the filename. This example skips the '.lua' extension only for files named 'init.lua'. ```lua use_file_extension = function(ext, file) -- Skip lua extension for init.lua only if ext == 'lua' and vim.endswith(file, 'init.lua') then return false end return true end ``` -------------------------------- ### Resetting Mini.icons Cache Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/configuration.md Call `MiniIcons.setup()` again to apply new configurations and reset the icon cache. This function is safe to call multiple times. ```lua -- Initial setup require('mini.icons').setup({ style = 'glyph' }) -- Later, change configuration require('mini.icons').setup({ style = 'ascii' }) -- Cache is reset ``` -------------------------------- ### Compatibility Layer for Migration Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md Provides a compatibility function to ease the transition from `nvim-web-devicons` to `MiniIcons`. This function attempts to use `MiniIcons` first and falls back to `nvim-web-devicons` if it's not available. ```lua -- Maintain compatibility while transitioning local function get_icon(file, ext, opts) if _G.MiniIcons ~= nil then local category = file and 'file' or 'extension' return MiniIcons.get(category, file or ext) else -- Fallback to nvim-web-devicons if available return require('nvim-web-devicons').get_icon(file, ext, opts) end end ``` -------------------------------- ### Get Icon Data for Directory Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Retrieve icon data for directory paths. The function uses the basename of the path and supports various input formats, including relative and absolute paths. ```lua -- All of these will result in the same output MiniIcons.get('directory', '.config') MiniIcons.get('directory', '~/.config') MiniIcons.get('directory', '/home/user/.config') -- Results in different output MiniIcons.get('directory', '.Config') ``` -------------------------------- ### Get Icon Data for File Source: https://github.com/nvim-mini/mini.icons/blob/main/doc/mini-icons.txt Retrieve icon data for a given file category and name. The function returns the icon, its highlight group, and a boolean indicating if it's a default fallback. ```lua local icon, hl, is_default = MiniIcons.get('file', 'file.lua') ``` -------------------------------- ### Retrieve File Icon Data Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md Use `MiniIcons.get('file', name)` to get icon, highlight group, and fallback status for a file. The function supports various categories like 'directory', 'extension', 'filetype', 'lsp', and 'os'. ```lua -- Get Lua file icon local icon, hl, is_default = MiniIcons.get('file', 'init.lua') -- Returns: icon='󰢱', hl='MiniIconsAzure', is_default=false ``` ```lua -- Get directory icon local icon, hl, is_default = MiniIcons.get('directory', '.config') -- Only basename is used, so all these return the same: -- MiniIcons.get('directory', '~/.config') -- MiniIcons.get('directory', '/home/user/.config') ``` ```lua -- Handle unsupported icon with fallback local icon, hl, is_default = MiniIcons.get('file', 'unknownfile.xyz') -- Returns default icon with is_default=true ``` ```lua -- Get filetype icon local icon, hl, is_default = MiniIcons.get('filetype', 'lua') ``` ```lua -- Get LSP kind icon local icon, hl, is_default = MiniIcons.get('lsp', 'keyword') ``` ```lua -- Get OS icon local icon, hl, is_default = MiniIcons.get('os', 'linux') ``` -------------------------------- ### Format Completion Item with Icon Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md Formats a completion item by prepending its filetype icon and setting user data for highlight. Useful for custom completion sources. ```lua -- Custom completion source using MiniIcons local function format_completion_item(item) local icon, hl = MiniIcons.get('filetype', item.filetype or 'text') return { abbr = string.format('%s %s', icon, item.name), user_data = { hl = hl } } end ``` -------------------------------- ### MiniIcons Configuration Structure Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md The configuration table for MiniIcons. Keys include icon categories and a function to control extension usage. This table can only be modified during the `MiniIcons.setup()` call. ```lua MiniIcons.config: table ``` -------------------------------- ### Lazy Load MiniIcons Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md This pattern ensures that the mini.icons plugin is loaded only when it's first needed, improving startup performance. It defines helper functions to manage the loading and retrieval of icons. ```lua -- Lazy load MiniIcons when first needed local function ensure_miniicons() if _G.MiniIcons == nil then require('mini.icons').setup() end return _G.MiniIcons end local function get_file_icon(file) local MiniIcons = ensure_miniicons() return MiniIcons.get('file', file) end ``` -------------------------------- ### ASCII-Only Configuration Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/configuration.md Set the icon style to 'ascii' to use fallback ASCII characters instead of glyphs. ```lua require('mini.icons').setup({ style = 'ascii' -- Uses fallback ASCII characters }) ``` -------------------------------- ### Check MiniIcons Initialization Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/errors.md Before using MiniIcons functions, check if the plugin has been initialized to avoid errors. ```lua if _G.MiniIcons ~= nil then local icon, hl, is_default = MiniIcons.get('file', 'myfile.lua') else print('MiniIcons not initialized') end ``` -------------------------------- ### List Directory Contents with Icons Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md Generates a list of directory entries, including their names, icons, and highlight groups. Differentiates between files and directories. ```lua local function list_directory_with_icons(path) local result = {} for name in vim.fs.dir(path) do local full_path = path .. '/' .. name local is_dir = vim.fn.isdirectory(full_path) == 1 local category = is_dir and 'directory' or 'file' local icon, hl, _ = MiniIcons.get(category, name) table.insert(result, { name = name, icon = icon, hl = hl, is_dir = is_dir }) end return result end ``` -------------------------------- ### MiniIcons Configuration Table Structure Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/configuration.md This table outlines the structure of the configuration options available for MiniIcons. It includes settings for icon style, default mappings, and specific categories like directories, extensions, files, filetypes, LSP, and OS. ```lua { style = 'glyph', default = {}, directory = {}, extension = {}, file = {}, filetype = {}, lsp = {}, os = {}, use_file_extension = function(ext, file) return true end, } ``` -------------------------------- ### Customize Directory Icons Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/configuration.md Add custom icons for specific directory basenames. Keys are directory names, and values can be IconData tables or filetype names to inherit from. Matching is case-sensitive and based on the basename only. ```lua require('mini.icons').setup({ directory = { ['.cache'] = { glyph = '󰪺', hl = 'MiniIconsCyan' }, ['src'] = { glyph = '󰴉', hl = 'MiniIconsPurple' }, ['tests'] = { glyph = '󱞊', hl = 'MiniIconsBlue' } } }) ``` -------------------------------- ### Custom Styles and Extensions Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/configuration.md Configure custom icons for file extensions and specific filenames, and set the icon style. The 'py' extension inherits its icon from the 'python' filetype. ```lua require('mini.icons').setup({ style = 'glyph', extension = { lua = { glyph = '󰢱', hl = 'MiniIconsAzure' }, rust = { glyph = '󱘗', hl = 'MiniIconsRed' }, py = 'python' }, file = { ['Makefile'] = { glyph = '󱁤', hl = 'MiniIconsGrey' } } }) ``` -------------------------------- ### List Explicitly Supported File Icons Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md Retrieves a sorted list of icon names explicitly defined for the 'file' category. User-configured custom icons are included. ```lua -- Get all explicitly supported file icons local files = MiniIcons.list('file') ``` -------------------------------- ### List Explicitly Supported Directory Icons Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md Retrieves a sorted list of icon names explicitly defined for the 'directory' category. User-configured custom icons are included. ```lua -- Get all supported directory icons local directories = MiniIcons.list('directory') ``` -------------------------------- ### Render Icons in File Explorer Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md Integrate Mini.Icons to display file and directory icons within a custom file explorer function. Ensure the `MiniIcons.get` function is called with the correct category and name. ```lua local function render_explorer(directory) local items = vim.fs.dir(directory) for name in items do local full_path = directory .. '/' .. name local is_dir = vim.fn.isdirectory(full_path) == 1 local category = is_dir and 'directory' or 'file' local icon, hl = MiniIcons.get(category, name) -- Render with icon and highlight local line = string.format('%%#%s#%s%%#Normal# %s', hl, icon, name) vim.api.nvim_buf_set_lines(0, -1, -1, false, { line }) end end ``` -------------------------------- ### Batch Icon Resolution for Files Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/usage-patterns.md Efficiently retrieve icons for multiple files in a batch. This leverages MiniIcons' internal caching for speed. ```lua local function get_icons_for_files(files) local result = {} for _, file in ipairs(files) do -- MiniIcons caches, so repeated calls are fast local icon, hl = MiniIcons.get('file', file) table.insert(result, { file = file, icon = icon, hl = hl }) end return result end -- Very efficient even with many files due to caching local icons = get_icons_for_files(vim.fn.glob('**/*.lua', false, true)) ``` -------------------------------- ### List Explicitly Supported LSP Kind Icons Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md Retrieves a sorted list of icon names explicitly defined for the 'lsp' category. User-configured custom icons are included. ```lua -- Get all LSP kind icons local lsp_kinds = MiniIcons.list('lsp') ``` -------------------------------- ### List Explicitly Supported Extension Icons Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/api-reference-miniicons.md Retrieves a sorted list of icon names explicitly defined for the 'extension' category. User-configured custom icons are included. ```lua local extensions = MiniIcons.list('extension') -- Returns: {'7z', 'aac', 'aif', 'avi', 'bmp', 'bz', ..., 'zip', 'zst'} ``` -------------------------------- ### Customize Specific File Icons Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/configuration.md Set custom icons for exact file basenames. Keys are filenames, and values can be IconData tables or filetype names. Matching is case-sensitive. ```lua require('mini.icons').setup({ file = { ['init.lua'] = { glyph = '󰢱', hl = 'MiniIconsGreen' }, ['Makefile'] = { glyph = '󱁤', hl = 'MiniIconsGrey' }, ['package.json'] = { glyph = '󰎕', hl = 'MiniIconsOrange' } } }) ``` -------------------------------- ### Configure OS Icons Source: https://github.com/nvim-mini/mini.icons/blob/main/_autodocs/configuration.md Customize icons for operating systems like Linux, macOS, and Windows. Supports IconData tables for glyphs and highlighting, or strings to inherit icons from filetypes. ```lua require('mini.icons').setup({ os = { linux = { glyph = '󰌽', hl = 'MiniIconsYellow' }, macos = { glyph = '󰀵', hl = 'MiniIconsGrey' }, windows = { glyph = '󰍲', hl = 'MiniIconsBlue' } } }) ```