Skip to main content

Neovim Configuration

Config-Sway includes a modern Neovim setup based on NvChad v2.5, providing a powerful IDE-like experience with LSP support, syntax highlighting, and efficient keybindings.

Configuration Structure

~/.config/nvim/
├── init.lua                 # Main entry point
├── lua/
│   ├── autocmds.lua         # Auto-commands
│   ├── chadrc.lua           # NvChad configuration
│   ├── mappings.lua         # Custom keybindings
│   ├── options.lua          # Editor options
│   ├── configs/
│   │   ├── conform.lua      # Code formatting
│   │   ├── lazy.lua         # Plugin manager config
│   │   └── lspconfig.lua    # LSP setup
│   └── plugins/
│       └── init.lua         # Plugin definitions

NvChad Framework

What is NvChad?

NvChad is a Neovim configuration framework that provides:
  • Pre-configured LSP (Language Server Protocol)
  • Modern UI with custom statusline
  • File explorer (NvimTree)
  • Fuzzy finder (Telescope)
  • Git integration
  • Syntax highlighting (Treesitter)

Initialization

~/.config/nvim/init.lua
vim.g.base46_cache = vim.fn.stdpath "data" .. "/base46/"
vim.g.mapleader = " "

-- Bootstrap lazy.nvim plugin manager
local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"

if not vim.uv.fs_stat(lazypath) then
  local repo = "https://github.com/folke/lazy.nvim.git"
  vim.fn.system { "git", "clone", "--filter=blob:none", repo, "--branch=stable", lazypath }
end

vim.opt.rtp:prepend(lazypath)
Leader key: Set to Space

Plugin Management

require("lazy").setup({
  { "nvzone/volt" , lazy = true },
  { "nvzone/menu" , lazy = true },
  {
    "NvChad/NvChad",
    lazy = false,
    branch = "v2.5",
    import = "nvchad.plugins",
  },
  { import = "plugins" },
}, lazy_config)
  • Lazy loading improves startup time
  • NvChad v2.5 provides base functionality
  • Custom plugins loaded from lua/plugins/

Core Configuration

Editor Options

~/.config/nvim/init.lua
vim.opt.number = true
vim.opt.relativenumber = true
  • Line numbers: Absolute line numbers displayed
  • Relative numbers: Distance from current line (useful for motions like 5j)
With relative numbers, you can quickly jump 7 lines down with 7j or delete 3 lines up with d3k.

Additional Options

~/.config/nvim/lua/options.lua
require "nvchad.options"

-- Add custom options here
-- local o = vim.o
-- o.cursorlineopt = 'both'  -- Enable cursorline
This file extends NvChad’s default options. Uncomment lines to enable features.

Keybindings

Universal Exit: zx

~/.config/nvim/init.lua
vim.keymap.set('i', 'zx', '<Esc>', { noremap = true, desc = "Salir del modo inserción" })
vim.keymap.set('v', 'zx', '<Esc>', { noremap = true, desc = "Salir del modo visual" })
vim.keymap.set('c', 'zx', '<C-c>', { noremap = true, desc = "Cancelar comando" })
vim.keymap.set('t', 'zx', '<C-\\><C-n>', { noremap = true, desc = "Salir del modo terminal" })
Usage: Press zx in any mode to return to Normal mode.
Modezx Effect
InsertExit to Normal mode
VisualExit to Normal mode
CommandCancel command
TerminalExit to Normal mode
This creates a consistent escape mechanism across all modes, as an alternative to Esc or Ctrl+C.

Split Navigation

~/.config/nvim/init.lua
vim.keymap.set('n', '<C-h>', '<C-w>h', { desc = "Mover al panel izquierdo" })
vim.keymap.set('n', '<C-l>', '<C-w>l', { desc = "Mover al panel derecho" })
  • Ctrl + H - Move to left split
  • Ctrl + L - Move to right split
NvChad provides Ctrl+J and Ctrl+K for vertical navigation by default.
~/.config/nvim/lua/mappings.lua
require "nvchad.mappings"

local map = vim.keymap.set

map("n", ";", ":", { desc = "CMD enter command mode" })
map("i", "jk", "<ESC>")

Custom Additions

  • ; in Normal mode - Enter command mode (alternative to :)
  • jk in Insert mode - Quick exit to Normal mode

Common NvChad Mappings

KeyModeAction
Space + eNormalToggle NvimTree file explorer
Space + ffNormalFind files (Telescope)
Space + fwNormalFind word in files (live grep)
Space + fbNormalFind buffers
Space + fhNormalFind help tags
Space + thNormalChange theme
Space + chNormalNvChad cheatsheet
Ctrl + nNormalToggle file explorer
TabNormalNext buffer
Shift + TabNormalPrevious buffer
Space + xNormalClose buffer

LSP Configuration

Language Server Setup

~/.config/nvim/lua/configs/lspconfig.lua
-- Configure language servers here
-- Example: lua_ls, pyright, tsserver, etc.
NvChad automatically configures common language servers. Install them with Mason: Open Mason: :Mason Install servers:
:MasonInstall lua-language-server
:MasonInstall pyright
:MasonInstall typescript-language-server

LSP Keybindings

Once LSP is active in a buffer:
KeyAction
gdGo to definition
grGo to references
KHover documentation
Space + caCode actions
Space + rnRename symbol
[dPrevious diagnostic
]dNext diagnostic
Space + qShow diagnostics list

Code Formatting

Conform.nvim

~/.config/nvim/lua/configs/conform.lua
-- Configure formatters here
-- Example: prettier, black, stylua, etc.
Format on save or manually: Manual format: Space + fm Auto-format on save:
autocmd BufWritePre * lua vim.lsp.buf.format()

File Explorer (NvimTree)

Opening NvimTree

  • Ctrl + N - Toggle file explorer
  • Space + e - Focus file explorer

NvimTree Navigation

KeyAction
EnterOpen file or folder
oOpen file
aCreate new file/folder
dDelete file/folder
rRename
xCut
cCopy
pPaste
RRefresh
HToggle hidden files
?Show help

Fuzzy Finding (Telescope)

Search Commands

:Telescope find_files     " Find files by name
:Telescope live_grep      " Search text in files
:Telescope buffers        " List open buffers
:Telescope help_tags      " Search help documentation
:Telescope oldfiles       " Recently opened files
:Telescope git_status     " Git changed files

Quick Keybindings

  • Space + ff - Find files
  • Space + fw - Find word (live grep)
  • Space + fb - Find buffers
  • Space + fh - Find help
  • Space + fo - Find old files
  • Space + fz - Find in current buffer

Telescope Navigation

KeyAction
Ctrl + J/KMove up/down in results
Ctrl + U/DScroll preview up/down
EnterOpen file
Ctrl + XOpen in horizontal split
Ctrl + VOpen in vertical split
Ctrl + TOpen in new tab
EscClose Telescope

Syntax Highlighting (Treesitter)

NvChad includes Treesitter for advanced syntax highlighting and code understanding.

Installing Parsers

:TSInstall lua
:TSInstall python
:TSInstall javascript
:TSInstall bash
Install all maintained parsers:
:TSInstall all

Treesitter Features

  • Syntax highlighting - Context-aware colors
  • Code folding - Fold functions, classes, blocks
  • Incremental selection - Expand selection based on syntax tree
  • Indentation - Smart auto-indent

Customization

Edit ~/.config/nvim/lua/plugins/init.lua:
return {
  -- Example: Add GitHub Copilot
  {
    "github/copilot.vim",
    lazy = false,
  },
  
  -- Example: Add better commenting
  {
    "numToStr/Comment.nvim",
    config = function()
      require("Comment").setup()
    end,
  },
}
Restart Neovim to install new plugins.
NvChad includes multiple themes:List themes:
:Telescope themes
Or use keybinding: Space + thSet default theme:Edit ~/.config/nvim/lua/chadrc.lua:
local M = {}

M.ui = {
  theme = "catppuccin",  -- or "onedark", "gruvbox", etc.
}

return M
Edit ~/.config/nvim/lua/autocmds.lua:
-- Auto-save on focus lost
vim.api.nvim_create_autocmd("FocusLost", {
  pattern = "*",
  command = "silent! wa",
})

-- Highlight yanked text
vim.api.nvim_create_autocmd("TextYankPost", {
  pattern = "*",
  callback = function()
    vim.highlight.on_yank({ higroup = "IncSearch", timeout = 200 })
  end,
})

-- Remove trailing whitespace on save
vim.api.nvim_create_autocmd("BufWritePre", {
  pattern = "*",
  command = "%s/\\s\\+$//e",
})

Useful Commands

NvChad Commands

:NvChadUpdate       " Update NvChad
:NvChadSnapshotCreate " Create config snapshot
:NvChadSnapshotDelete " Delete snapshot
:NvChadSnapshotRestore " Restore from snapshot

Plugin Management

:Lazy               " Open plugin manager
:Lazy sync          " Install/update/clean plugins
:Lazy clean         " Remove unused plugins
:Lazy update        " Update all plugins

Mason (LSP/Tools)

:Mason              " Open Mason UI
:MasonInstall <name> " Install tool
:MasonUninstall <name> " Remove tool
:MasonUpdate        " Update all tools

Troubleshooting

Profile startup time:
nvim --startuptime startup.log
Optimize plugin loading:
  • Ensure plugins are set to lazy = true where possible
  • Use event, ft, or cmd triggers for lazy loading
Example:
{
  "plugin-name",
  lazy = true,
  event = "BufRead",  -- Load when reading a buffer
}
Check if LSP is attached:
:LspInfo
Install language server:
:Mason
Restart LSP:
:LspRestart
Check logs:
:LspLog
Update parsers:
:TSUpdate
Reinstall specific parser:
:TSInstall! python
Check health:
:checkhealth nvim-treesitter
Sync plugins:
:Lazy sync
Clear cache:
rm -rf ~/.local/share/nvim
rm -rf ~/.cache/nvim
Then restart Neovim.

Neovim Tips

Built-in tutor:
nvim +Tutor
Practice with:
  • ciw - Change inner word
  • di" - Delete inside quotes
  • va{ - Select around curly braces
  • gg=G - Auto-indent entire file
  • :%s/old/new/g - Replace all occurrences
  • . - Repeat last change
  • * - Search for word under cursor
  • <C-o> - Jump to previous location
  • <C-i> - Jump to next location
  1. Press q + letter (e.g., qa for register ‘a’)
  2. Perform actions
  3. Press q to stop recording
  4. Play macro with @a
  5. Repeat with @@
Example: Record qa, type :s/foo/bar<CR>, press q, then @a to replay.

Kitty Terminal

Terminal emulator where Neovim runs

Sway Keybindings

Window manager shortcuts

Additional Resources

Press Space + ch in Neovim to open the NvChad cheatsheet with all keybindings.

Build docs developers (and LLMs) love