/LazyVim

Starter template for lazy Neovim users

Primary LanguageLuaApache License 2.0Apache-2.0

LazyVim

LazyVim is a Neovim setup powered by ๐Ÿ’ค lazy.nvim to make it easy to customize and extend your config. Rather than having to choose between starting from scratch or using a pre-made distro, LazyVim offers the best of both worlds - the flexibility to tweak your config as needed, along with the convenience of a pre-configured setup.

image

โœจ Features

  • ๐Ÿ”ฅ Transform your Neovim into a full-fledged IDE
  • ๐Ÿ’ค Easily customize and extend your config with lazy.nvim
  • ๐Ÿš€ Blazingly fast
  • ๐Ÿงน Sane default settings for options, autocmds, and keymaps
  • ๐Ÿ“ฆ Comes with a wealth of plugins pre-configured and ready to use

โšก๏ธ Requirements

  • Neovim >= 0.8.0 (needs to be built with LuaJIT)
  • Git >= 2.19.0 (for partial clones support)
  • a Nerd Font (optional)

๐Ÿš€ Getting Started

You can find a starter template for LazyVim here

TLDR:

require("lazy").setup({
  spec = {
    -- import LazyVim plugins
    { "LazyVim/LazyVim", import = "lazyvim.plugins" },
    -- import/override with your plugins
    { import = "plugins" },
    -- import any extras modules here
    -- { import = "lazyvim.plugins.extras.lang.typescript" },
    -- { import = "lazyvim.plugins.extras.lang.json" },
  },
  defaults = {
    lazy = true, -- every plugin is lazy-loaded by default
    version = "*", -- try installing the latest stable version for plugins that support semver
  },
})

๐Ÿ“‚ File Structure

The files under config will be automatically loaded at the appropriate time, so you don't need to require those files manually. LazyVim comes with a set of default config files that will be loaded before your own. See here

You can add your custom plugin specs under lua/plugins/. All files there will be automatically loaded by lazy.nvim

~/.config/nvim
โ”œโ”€โ”€ lua
โ”‚   โ”œโ”€โ”€ config
โ”‚   โ”‚   โ”œโ”€โ”€ autocmds.lua
โ”‚   โ”‚   โ”œโ”€โ”€ keymaps.lua
โ”‚   โ”‚   โ”œโ”€โ”€ lazy.lua
โ”‚   โ”‚   โ””โ”€โ”€ options.lua
โ”‚   โ””โ”€โ”€ plugins
โ”‚       โ”œโ”€โ”€ spec1.lua
โ”‚       โ”œโ”€โ”€ **
โ”‚       โ””โ”€โ”€ spec2.lua
โ””โ”€โ”€ init.toml

๐Ÿš€ Configuring LazyVim

Configuring LazyVim is exactly the same as using lazy.nvim to build a config from scratch.

For the full plugin spec documentation please check the lazy.nvim readme.

Example spec: lua/plugins/example.lua
-- every spec file under config.plugins will be loaded automatically by lazy.nvim
--
-- In your plugin files, you can:
-- * add extra plugins
-- * disable/enabled LazyVim plugins
-- * override the configuration of LazyVim plugins
return {
  -- change trouble config
  {
    "folke/trouble.nvim",
    -- opts will be merged with the parent spec
    opts = { use_diagnostic_signs = true },
  },

  -- disable trouble
  { "folke/trouble.nvim", enabled = false },

  -- add symbols-outline
  {
    "simrat39/symbols-outline.nvim",
    cmd = "SymbolsOutline",
    keys = { { "<leader>cs", "<cmd>SymbolsOutline<cr>", desc = "Symbols Outline" } },
    config = true,
  },

  -- override nvim-cmp and add cmp-emoji
  {
    "hrsh7th/nvim-cmp",
    dependencies = { "hrsh7th/cmp-emoji" },
    ---@param opts cmp.ConfigSchema
    opts = function(_, opts)
      local cmp = require("cmp")
      opts.sources = cmp.config.sources(vim.list_extend(opts.sources, { { name = "emoji" } }))
    end,
  },

  -- change some telescope options and add telescope-fzf-native
  {
    "nvim-telescope/telescope.nvim",
    dependencies = { { "nvim-telescope/telescope-fzf-native.nvim", build = "make" } },
    keys = {
      -- add a keymap to browse plugin files
      -- stylua: ignore
      {
        "<leader>fp",
        function() require("telescope.builtin").find_files({ cwd = require("lazy.core.config").options.root }) end,
        desc = "Find Plugin File",
      },
    },
    -- change some options
    opts = {
      defaults = {
        layout_strategy = "horizontal",
        layout_config = { prompt_position = "top" },
        sorting_strategy = "ascending",
        winblend = 0,
      },
    },
    -- apply the config and additionally load fzf-native
    config = function(_, opts)
      local telescope = require("telescope")
      telescope.setup(opts)
      telescope.load_extension("fzf")
    end,
  },

  -- add pyright and setup tsserver with typescript.nvim
  {
    "neovim/nvim-lspconfig",
    dependencies = {
      "jose-elias-alvarez/typescript.nvim",
      init = function()
        require("lazyvim.util").on_attach(function(_, buffer)
          -- stylua: ignore
          vim.keymap.set( "n", "<leader>co", "TypescriptOrganizeImports", { buffer = buffer, desc = "Organize Imports" })
          vim.keymap.set("n", "<leader>cR", "TypescriptRenameFile", { desc = "Rename File", buffer = buffer })
        end)
      end,
    },
    ---@class PluginLspOpts
    opts = {
      ---@type lspconfig.options
      servers = {
        -- pyright will be automatically installed with mason and loaded with lspconfig
        pyright = {},
        tsserver = {},
      },
      -- you can do any additional lsp server setup here
      -- return true if you don't want this server to be setup with lspconfig
      ---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
      setup = {
        -- example to setup with typescript.nvim
        tsserver = function(_, opts)
          require("typescript").setup({ server = opts })
          return true
        end,
        -- Specify * to use this function as a fallback for any server
        -- ["*"] = function(server, opts) end,
      },
    },
  },

  -- for typescript, LazyVim also includes extra specs to properly setup lspconfig,
  -- treesitter, mason and typescript.nvim. So instead of the above, you can use:
  { import = "lazyvim.plugins.extras.lang.typescript" },

  -- add more treesitter parsers
  {
    "nvim-treesitter/nvim-treesitter",
    opts = {
      ensure_installed = {
        "bash",
        "help",
        "html",
        "javascript",
        "json",
        "lua",
        "markdown",
        "markdown_inline",
        "python",
        "query",
        "regex",
        "tsx",
        "typescript",
        "vim",
        "yaml",
      },
    },
  },

  -- since `vim.tbl_deep_extend`, can only merge tables and not lists, the code above
  -- would overwrite `ensure_installed` with the ne value.
  -- If you'd rather extend the default config, use the code below instead:
  {
    "nvim-treesitter/nvim-treesitter",
    opts = function(_, opts)
      vim.list_extend(opts.ensure_installed, {
        -- add tsx and treesitter
        ensure_installed = {
          "tsx",
          "typescript",
        },
      })
    end,
  },

  -- the opts function can also be used to change the default opts:
  {
    "nvim-lualine/lualine.nvim",
    event = "VeryLazy",
    opts = function(_, opts)
      table.insert(opts.sections.lualine_x, "๐Ÿ˜„")
    end,
  },

  -- or you can return new options to override all the defaults
  {
    "nvim-lualine/lualine.nvim",
    event = "VeryLazy",
    opts = function()
      return {
        --[[add your custom lualine config here]]
      }
    end,
  },

  -- use mini.starter instead of alpha
  { import = "lazyvim.plugins.extras.ui.mini-starter" },

  -- add jsonls and schemastore ans setup treesitter for json, json5 and jsonc
  { import = "lazyvim.plugins.extras.lang.json" },

  -- add any tools you want to have installed below
  {
    "williamboman/mason.nvim",
    opts = {
      ensure_installed = {
        "stylua",
        "shellcheck",
        "shfmt",
        "flake8",
      },
    },
  },
}

โŒจ๏ธ Keymaps

LazyVim uses which-key.nvim to help you remember your keymaps. Just press any key like <space> and you'll see a popup with all possible keymaps starting with <space>.

image

General
Key Description Mode
<C-h> Go to left window n
<C-j> Go to lower window n
<C-k> Go to upper window n
<C-l> Go to right window n
<C-Up> Increase window height n
<C-Down> Decrease window height n
<C-Left> Decrease window width n
<C-Right> Increase window width n
<A-j> Move down n, v, i
<A-k> Move up n, v, i
<S-h> Prev buffer n
<S-l> Next buffer n
[p Paste below n
]p Paste above n
<esc> Escape and clear hlsearch i, n
n Next search result n, x, o
N Prev search result n, x, o
<C-s> Save file i, v, n, s
<leader>l Lazy n
<leader>fn New File n
<leader>xl Open Location List n
<leader>xq Open Quickfix List n
<leader>tf Toggle format on Save n
<leader>ts Toggle Spelling n
<leader>tw Toggle Word Wrap n
<leader>tn Toggle Line Numbers n
<leader>td Toggle Diagnostics n
<leader>tc Toggle Conceal n
<leader>gg Lazygit (cwd) n
<leader>gG Lazygit (root dir) n
<leader>qq Quit all n
<leader>hl Highlight Groups at cursor n
<leader>ot Terminal (root dir) n
<leader>oT Terminal (cwd) n
<esc><esc> Enter Normal Mode t
<leader>ww other-window n
<leader>wd delete-window n
<leader>w- split-window-below n
<leader>w| split-window-right n
<leader><tab>l Last n
<leader><tab>f First n
<leader><tab><tab> New Tab n
<leader><tab>] Next n
<leader><tab>d Close n
<leader><tab>[ Previous n
<leader>b] Next Buffer n
<leader>bb Switch to Other Buffer n
<leader>b[ Previous Buffer n
<leader>` Switch to Other Buffer n
LSP
Key Description Mode
<leader>cd Line Diagnostics n
<leader>cl Lsp Info n
<leader>xd Telescope Diagnostics n
gd Goto Definition n
gr References n
gD Goto Declaration n
gI Goto Implementation n
gt Goto Type Definition n
K Hover n
gK Signature Help n
[d Next Diagnostic n
]d Prev Diagnostic n
]e Next Error n
[e Prev Error n
]w Next Warning n
[w Prev Warning n
<leader>ca Code Action n, v
<leader>cf Format Document n
<leader>cf Format Range v
<leader>cr Rename n
Plugins
Key Description Mode
<leader>cm mason.nvim Mason n
<leader>bd mini.bufremove Delete Buffer n
<leader>bD mini.bufremove Delete Buffer (Force) n
<leader>ft neo-tree.nvim NeoTree (root dir) n
<leader>fT neo-tree.nvim NeoTree (cwd) n
<S-Enter> noice.nvim Redirect Cmdline c
<leader>nl noice.nvim Noice Last Message n
<leader>nh noice.nvim Noice History n
<leader>na noice.nvim Noice All n
<c-f> noice.nvim Scroll forward n
<c-b> noice.nvim Scroll backward n
<leader>nd nvim-notify Delete all Notifications n
<leader>sr nvim-spectre Replace in files (Spectre) n
<leader>qs persistence.nvim Restore Session n
<leader>ql persistence.nvim Restore Last Session n
<leader>qd persistence.nvim Don't Save Current Session n
<leader>/ telescope.nvim Find in Files (Grep) n
<leader><space> telescope.nvim Find Files (root dir) n
<leader>fb telescope.nvim Buffers n
<leader>ff telescope.nvim Find Files (root dir) n
<leader>fF telescope.nvim Find Files (cwd) n
<leader>fr telescope.nvim Recent n
<leader>gc telescope.nvim commits n
<leader>gs telescope.nvim status n
<leader>ha telescope.nvim Auto Commands n
<leader>hc telescope.nvim Commands n
<leader>hf telescope.nvim File Types n
<leader>hh telescope.nvim Help Pages n
<leader>hk telescope.nvim Key Maps n
<leader>hm telescope.nvim Man Pages n
<leader>ho telescope.nvim Options n
<leader>hs telescope.nvim Search Highlight Groups n
<leader>ht telescope.nvim Telescope n
<leader>sb telescope.nvim Buffer n
<leader>sc telescope.nvim Command History n
<leader>sg telescope.nvim Grep (root dir) n
<leader>sG telescope.nvim Grep (cwd) n
<leader>sm telescope.nvim Jump to Mark n
<leader>, telescope.nvim Switch Buffer n
<leader>: telescope.nvim Command History n
<leader>ss telescope.nvim Goto Symbol n
]t todo-comments.nvim Next todo comment n
[t todo-comments.nvim Previous todo comment n
<leader>xt todo-comments.nvim Todo Trouble n
<leader>xtt todo-comments.nvim Todo Trouble n
<leader>xT todo-comments.nvim Todo Telescope n
<leader>xx trouble.nvim Document Diagnostics (Trouble) n
<leader>xX trouble.nvim Workspace Diagnostics (Trouble) n
]] vim-illuminate Next Reference n
[[ vim-illuminate Prev Reference n

๐Ÿ“ฆ Plugins

Core
Extras: lang.json

To use this, add it to your lazy.nvim imports:

require("lazy").setup({
  spec = {
    { "folke/LazyVim", import = "lazyvim.plugins" },
    { import = "lazyvim.plugins.extras.lang.json" },
    { import = "plugins" },
  },
})
Extras: lang.typescript

To use this, add it to your lazy.nvim imports:

require("lazy").setup({
  spec = {
    { "folke/LazyVim", import = "lazyvim.plugins" },
    { import = "lazyvim.plugins.extras.lang.typescript" },
    { import = "plugins" },
  },
})
Extras: ui.mini-starter

To use this, add it to your lazy.nvim imports:

require("lazy").setup({
  spec = {
    { "folke/LazyVim", import = "lazyvim.plugins" },
    { import = "lazyvim.plugins.extras.ui.mini-starter" },
    { import = "plugins" },
  },
})