Skip to main content
Magictt uses lazy.nvim as its plugin manager. Lazy.nvim automatically loads all plugin specifications from the lua/magictt/plugins/ directory.

Plugin Structure

All plugins are stored in lua/magictt/plugins/. Each plugin file should return a table containing one or more plugin specifications.

Basic Plugin Structure

return {
  "author/plugin-name",
  -- Optional configuration here
}

Plugin with Configuration

return {
  "author/plugin-name",
  config = function()
    require("plugin-name").setup({
      -- plugin options
    })
  end,
}

Adding a New Plugin

1

Create a new plugin file

Create a new .lua file in lua/magictt/plugins/ with a descriptive name:
touch lua/magictt/plugins/my-plugin.lua
2

Add the plugin specification

Open the file and add your plugin configuration. Here’s an example based on the Comment.nvim plugin:
return {
  "numToStr/Comment.nvim",
  event = { "BufReadPre", "BufNewFile" },
  dependencies = {
    "JoosepAlviste/nvim-ts-context-commentstring",
  },
  config = function()
    local comment = require("Comment")
    local ts_context_commentstring = require("ts_context_commentstring.integrations.comment_nvim")

    comment.setup({
      pre_hook = ts_context_commentstring.create_pre_hook(),
    })
  end,
}
3

Restart Neovim

Lazy.nvim will automatically detect and load the new plugin file when you restart Neovim.You can also use :Lazy sync to install the plugin without restarting.
4

Verify installation

Open the Lazy panel with <leader>ln to verify your plugin is installed and loaded correctly.

Real Examples from Magictt

Simple Plugin (init.lua:1-4)

return {
  "nvim-lua/plenary.nvim", -- lua functions that many plugins use
  "christoomey/vim-tmux-navigator", -- tmux & split window navigation
}

Plugin with Dependencies (telescope.lua:1-9)

return {
  "nvim-telescope/telescope.nvim",
  branch = "0.1.x",
  dependencies = {
    "nvim-lua/plenary.nvim",
    { "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
    "nvim-tree/nvim-web-devicons",
    "folke/todo-comments.nvim",
  },
  config = function()
    local telescope = require("telescope")
    -- configuration here
  end,
}

Plugin with Keymaps (telescope.lua:29-36)

Many plugins define their keymaps within the config function:
config = function()
  local telescope = require("telescope")
  telescope.setup({ -- setup code })
  
  -- set keymaps
  local keymap = vim.keymap
  keymap.set("n", "<leader>ff", "<cmd>Telescope find_files<cr>", { desc = "Fuzzy find files in cwd" })
  keymap.set("n", "<leader>fr", "<cmd>Telescope oldfiles<cr>", { desc = "Fuzzy find recent files" })
end,

Plugin Specification Options

Common Options

  • dependencies - Other plugins this plugin depends on
  • event - Lazy load on specific events (e.g., "BufReadPre", "BufNewFile")
  • cmd - Lazy load on specific commands
  • ft - Lazy load on specific filetypes
  • keys - Lazy load on specific keymaps
  • config - Function to run after plugin is loaded
  • opts - Table passed to require("plugin").setup(opts)
  • build - Command to run after install/update
  • branch - Git branch to use

Lazy Loading

Lazy loading improves startup time by only loading plugins when needed:
return {
  "author/plugin-name",
  event = { "BufReadPre", "BufNewFile" }, -- Load when opening a file
  -- or
  cmd = "PluginCommand", -- Load when running :PluginCommand
  -- or
  ft = "python", -- Load for Python files only
}

Multiple Plugins per File

You can define multiple plugins in a single file by returning a table of tables:
return {
  {
    "author/plugin-one",
    config = function()
      -- config for plugin one
    end,
  },
  {
    "author/plugin-two",
    config = function()
      -- config for plugin two
    end,
  },
}

Auto-loading

Lazy.nvim automatically discovers and loads all .lua files in:
  • lua/magictt/plugins/
  • lua/magictt/plugins/lsp/ (subdirectories are also supported)
No need to manually require or import plugin files - just create the file and restart Neovim!

Managing Plugins

Lazy Commands

  • :Lazy or <leader>ln - Open Lazy panel
  • :Lazy sync - Install missing plugins and update
  • :Lazy clean - Remove unused plugins
  • :Lazy update - Update plugins
  • :Lazy profile - Profile plugin load times

Best Practices

  1. One plugin per file - Easier to manage and understand
  2. Use descriptive filenames - Match the plugin name (e.g., telescope.lua, nvim-tree.lua)
  3. Lazy load when possible - Use event, cmd, or ft to improve startup time
  4. Add comments - Explain what the plugin does
  5. Group related plugins - Use subdirectories for related plugins (e.g., lsp/)

Build docs developers (and LLMs) love