My Neovim Setup w/ .vimrc
Neovim Setup + .vimrc
This is my current laptop setup, which differs from my PC setup to account for UNIX, portability and automation testing:
- Macbook M1 Pro 2021 (16", Sonoma 14.5)
- iTerm w/ Neovim installed using Homebrew
- NVChad w/ Cattppuccin Theme
- git clone -b v2.0 https://github.com/NvChad/NvChad ~/.config/nvim --depth 1
- .vimrc symlinked
-----
Plugin Manager
I am fan of vim-plug on vanilla Vim + Windows, but with Neovim I will use NVChad's inbuilt package manager (packer.nvim) and Mason.nvim to manage/install third-party dependencies and plugins. My plugins.lua:
local plugins = {
{
"nvim-neotest/nvim-nio",
},
{
"rcarriga/nvim-dap-ui",
event = "VeryLazy",
dependencies = "mfussenegger/nvim-dap",
config = function()
local dap = require("dap")
local dapui = require("dapui")
dapui.setup()
dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close()
end
end
},
{
"jay-babu/mason-nvim-dap.nvim",
event = "VeryLazy",
dependencies = {
"williamboman/mason.nvim",
"mfussenegger/nvim-dap",
},
opts = {
handlers = {}
},
},
{
"mfussenegger/nvim-dap",
config = function(_, _)
require("core.utils").load_mappings("dap")
end
},
{
"jose-elias-alvarez/null-ls.nvim",
event = "VeryLazy",
opts = function()
return require "custom.configs.null-ls"
end,
},
{
"neovim/nvim-lspconfig",
config = function()
require "plugins.configs.lspconfig"
require "custom.configs.lspconfig"
end,
},
{
"williamboman/mason.nvim",
opts = {
ensure_installed = {
"clangd",
"clang-format",
"codelldb",
}
}
}
}
return plugins
-----Install script for dependencies
#!/bin/bash
# Define colors
RED='\033[0;31m'
WHITE='\033[0;37m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
clear
# Backup Operation
echo -e "${GREEN}-==Backup Operation==-${NC}"
# Ask user if they want to create a backup
read -p "Do you want to create a backup of your current .config/nvim directory? (yes/no) " response
case "$response" in
[yY][eE][sS]|[yY])
# Check if the backup directory exists
if [ ! -d ~/.config/nvim-backup ]; then
mkdir ~/.config/nvim-backup
fi
# Create a timestamped backup of the .config/nvim directory
timestamp=$(date +%Y%m%d-%H%M%S)
cp -r ~/.config/nvim ~/.config/nvim-backup/$timestamp
;;
*)
echo -e "${WHITE}Skipping backup...${NC}"
;;
esac
# Install NvChad
echo -e "${GREEN}-==Installing NvChad ...==-${NC}"
git clone https://github.com/NvChad/NvChad ~/.config/nvim --depth 1 > /dev/null 2>&1
# Cloning Repository
echo -e "${GREEN}-==Cloning Repository ...==-${NC}"
git clone https://github.com/dreamsofcode-io/neovim-cpp.git > /dev/null 2>&1
# Navigate to the cloned directory
cd neovim-cpp
# Copying Files
echo -e "${GREEN}-==Copying Files==-${NC}"
rsync -av --exclude='README.md' --exclude='.git/' --exclude='install.sh' . ~/.config/nvim/lua/custom
# Adding Command
# Display a warning message (for MasonInstallAll)
echo -e "${WHITE}Neovim is about to open to install needed packages, after it downloaded the packages, quit neovim with quit command! and wait for script to do the rest.${NC}"
# Ask user for confirmation
read -p "Do you understand the instructions? (yes/no) " response
case "$response" in
[yY][eE][sS]|[yY])
echo -e "${GREEN}-==Adding MasonInstallAll Command==-${NC}"
# Append the MasonInstallAll command to the init.lua file
echo 'vim.cmd("MasonInstallAll")' >> ~/.config/nvim/init.lua
# Open Neovim
nvim
;;
*)
echo -e "${RED}Exiting...${NC}"
exit 1
;;
esac
# Removing Command
echo -e "${GREEN}-==Removing MasonInstallAll Command==-${NC}"
# Remove the command from init.lua
sed -i '/^vim.cmd("MasonInstallAll")$/d' ~/.config/nvim/init.lua
# Removing Directory
echo -e "${GREEN}-==Removing necessary files==-${NC}"
# Remove the cloned directory
rm -rf ../neovim-cpp
-----Minimal Vimrmc + settings.lua
NVChad uses Lua files instead of a standard .vimrc so here's both of mine for reference, keep in mind that I've encountered an error that set my 'hjkl' keys to different commands so I used settings.lua to overwrite the keys to their default values.
After `:verbose map j` I get this output:n j * v:count || mode(1)[0:1] == "no" ? "j" : "gj"
Move down
Last set from Lua (run Nvim with -V1 for more details)
x j * v:count || mode(1)[0:1] == "no" ? "j" : "gj"
Move down
Last set from Lua (run Nvim with -V1 for more details)
Press ENTER or type command to continue
.vimrc
set mouse=
autocmd BufEnter * set mouse=
if exists('py2') && has('python')
elseif has('python3')
endif
au GUIEnter * simalt ~x
set hls
set is
set cb=unnamed
set ts=4
set sw=4
set si
set nu
set relativenumber
set hlsearch "Highlight all search results
set smartcase "Enable smart-case search
set ignorecase "Always case-insensitive
set incsearch "Searches for strings incrementally
set enc=utf-8
set fenc=utf-8
set termencoding=utf-8
" disable vi compatibility (emulation of old bugs)
set nocompatible
set autoindent
set smartindent
" configure tabwidth and insert spaces instead of tabs
set tabstop=4
set shiftwidth=4
set expandtab
set textwidth=120
" turn syntax highlighting on
set t_Co=256
syntax on
set number
" highlight matching braces
set showmatch
" intelligent comments
set comments=sl:/*,mb:\ *,elx:\ */
cd ~/Users/hins/vim_projects
settings.lua
-- Tab and indentation settings
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.autoindent = true
vim.opt.smartindent = true
-- Display settings
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.textwidth = 120
vim.opt.showmatch = true
-- Search settings
vim.opt.hlsearch = true
vim.opt.smartcase = true
vim.opt.ignorecase = true
vim.opt.incsearch = true
-- Encoding settings
vim.opt.encoding = "utf-8"
vim.opt.fileencoding = "utf-8"
-- Compatibility settings
vim.opt.compatible = false
-- Other settings
vim.opt.syntax = "on"
vim.opt.comments = "sl:/*,mb:\\ *,elx:\\ */"
vim.opt.termguicolors = true -- For setting 256 colors
-- Change directory on startup
vim.cmd("cd /Users/hins/vim_projects")
-- Open NvimTree on startup
vim.api.nvim_create_autocmd("VimEnter", {
callback = function()
vim.cmd("NvimTreeFocus")
end,
})
return M