LazyVim

https://lazyvim.org

Interesting book: LazyVim for Ambitious Developers

Since September/2023 and I'm testing LazyVim distribution (do not confuse with Lazy.nvim plugin, very related but different).

The out-of-the-box experience is not 100% aligned with what I'm used to, but at least it's not as buggy as LunarVim. So far it's being my favorite #vim distro.

See also: LazyVim for coding


Useful keybindings to know right-away

Notifications

Sometimes we want to read the notifications carefully and they go away.


Things to do right after installation

keep my .vimrc

Put this at the end of lua/config/options.lua

-- meleu: load my own "old" configs written in VimScript
if vim.fn.filereadable("~/.vimrc") then
  vim.cmd("source ~/.vimrc")
end

plugins to disable

Create the file lua/plugins/disabled.lua:

return {
  -- disable mini.surround, (confusing keybindings)
  -- I have years of muscle memory using tpope/vim-surround
  { "echasnovski/mini.surround", enabled = false },
}

plugins to install

Create the file lua/plugins/init.lua:

return {
  "vim-scripts/ReplaceWithRegister",
  "tpope/vim-surround",
  "tpope/vim-repeat",     -- make vim-surround dot-repeatable
  "tpope/vim-speeddating", -- <C-a>/<C-x> to increase/decrease dates
}

gr for "go replace" conflicting with "go reference"

Check docs for more uptodate info.

lua/plugins/lsp.lua:

-- overriding LazyVim's default LSP configs
return {
  "neovim/nvim-lspconfig",
  opts = function()
    local keys = require("lazyvim.plugins.lsp.keymaps").get()

    -- I want to use gr for "Go Replace" (vim-scripts/ReplaceWithRegister)
    keys[#keys + 1] = { "gr", false }

    -- use gR to "Go to References"
    keys[#keys + 1] = { "gR", ":Telescope lsp_references<cr>", desc = "[G]oto [R]eferences" }
  end,
}

disable H and L to navigate between buffers

These keys have a native meaning in vim and should not be remapped to do other things. Prefixing them with the leaderkey would be ok...

lua/config/keymaps.lua:

vim.keymap.del("n", "<S-h>")
vim.keymap.del("n", "<S-l>")

Since LazyVim comes with bufferline, making buffers look like tabs, I want to navigate between buffers with gt/gT.

lua/config/keymaps.lua

vim.keymap.set("n", "gT", ":bprevious<cr>", { desc = "Prev buffer" })
vim.keymap.set("n", "gt", ":bnext<cr>", { desc = "Next buffer" })

disable <enter> to accept autosuggestions

Inspiration from here..

The code below disables <cr> to accept autosuggestions and configure <tab>/<s-tab> to choose the suggestions.

lua/plugins/nvim-cmp.lua:

return {
  "hrsh7th/nvim-cmp",
  opts = function(_, opts)
    -- disable <cr> to accept completion
    -- enable <tab> and <s-tab> to navigate completion menu
    local cmp = require("cmp")
    opts.mapping = vim.tbl_extend("force", opts.mapping, {
      ["<Tab>"] = cmp.mapping.select_next_item(),
      ["<S-Tab>"] = cmp.mapping.select_prev_item(),
      ["<CR>"] = function(fallback)
        cmp.abort()
        fallback()
      end,
    })
  end,
}

disable the clock in lualine

lua/plugins/lualine.lua:

return {
  "nvim-lualine/lualine.nvim",
  opts = {
    sections = {
      lualine_z = {},
    },
  },
}

enable borders for...

Mason and Lazy.nvim UI

lua/plugins/extended-mason.lua

return {
  "williamboman/mason.nvim",
  opts = {
    ui = {
      border = "rounded",
    },
  },
}

lua/config/lazy.lua

-- ...
require("lazy").setup({
  -- a bunch of configs here...
  ui = {
    border = "rounded",
  },
})

completion suggestions

lua/plugins/extended-nvim-cmp.lua:

return {
  "hrsh7th/nvim-cmp",
  opts = function(_, opts)
    -- enable borders for completion menu and documentation
    opts.window = {
      completion = {
        border = "rounded",
      },
      documentation = {
        border = "rounded",
      },
    }
  end,
}

hover documentation

lua/plugins/extended-noice.lua

return {
 "folke/noice.nvim",
 opts = {
   presets = {
     lsp_doc_border = true,
   },
 },
}

disable plugin update notification

update: I've noticed that this is the default config in 2024-07-22 (enabled: true, notify: false)

lua/config/lazy.lua

  checker = {
    enabled = true,
    notify = false,
  },

specific use cases

vim-tmux-navigator

https://github.com/christoomey/vim-tmux-navigator

lua/plugins/vim-tmux-navigator.lua:

return {
  "christoomey/vim-tmux-navigator",
  cmd = {
    "TmuxNavigatorLeft",
    "TmuxNavigatorRight",
    "TmuxNavigatorUp",
    "TmuxNavigatorDown",
  },
  keys = {
    { "<c-h>", ":TmuxNavigatorLeft<cr>" },
    { "<c-j>", ":TmuxNavigatorDown<cr>" },
    { "<c-k>", ":TmuxNavigatorUp<cr>" },
    { "<c-l>", ":TmuxNavigatorRight<cr>" },
  },
}

Things I still wanna do

Connected Pages
On this page
LazyVim
  • Useful keybindings to know right-away
    1. Notifications
  • Things to do right after installation
  • keep my .vimrc
  • plugins to disable
  • plugins to install
  • gr for "go replace" conflicting with "go reference"
  • disable H and L to navigate between buffers
  • navigate between buffers like they were tabs
  • disable to accept autosuggestions
  • disable the clock in lualine
  • enable borders for...
    1. Mason and Lazy.nvim UI
    2. completion suggestions
    3. hover documentation
  • disable plugin update notification
  • specific use cases
    1. vim-tmux-navigator
  • Things I still wanna do