Skip to content

Instantly share code, notes, and snippets.

@dwrodri
Created March 26, 2025 01:31
Show Gist options
  • Save dwrodri/14c69e300c8fcfedbda6bd41d5e30ed3 to your computer and use it in GitHub Desktop.
Save dwrodri/14c69e300c8fcfedbda6bd41d5e30ed3 to your computer and use it in GitHub Desktop.
-- Neovim Configuration
-- Basic UI Settings
vim.opt.number = true -- Show line numbers
vim.opt.shiftwidth = 4 -- Set indentation to 4 spaces
vim.opt.tabstop = 4 -- Set tab width to 4 spaces
vim.opt.expandtab = true -- Use spaces instead of tabs
vim.opt.autoindent = true -- Enable auto indentation
vim.opt.smartindent = true -- Enable smart indentation
-- Search Settings
vim.opt.incsearch = true -- Enable incremental search
vim.opt.hlsearch = true -- Highlight search results
-- Status Line Configuration
vim.opt.laststatus = 2 -- Always show statusline
vim.opt.showmode = false -- Hide default mode indicator (since it's in our statusline)
vim.opt.ruler = true -- Show cursor position
-- Define colors for different modes
local colors = {
normal = "StatusLineNormal",
insert = "StatusLineInsert",
visual = "StatusLineVisual",
visual_block = "StatusLineVisualBlock",
replace = "StatusLineReplace",
command = "StatusLineCommand",
terminal = "StatusLineTerminal"
}
-- Create highlight groups for different modes
local function set_highlights()
vim.api.nvim_set_hl(0, "StatusLineNormal", { bg = "white", fg = "black" })
vim.api.nvim_set_hl(0, "StatusLineInsert", { bg = "blue", fg = "white" })
vim.api.nvim_set_hl(0, "StatusLineVisual", { bg = "green", fg = "black" })
vim.api.nvim_set_hl(0, "StatusLineVisualBlock", { bg = "orange", fg = "black" })
vim.api.nvim_set_hl(0, "StatusLineReplace", { bg = "red", fg = "white" })
vim.api.nvim_set_hl(0, "StatusLineCommand", { bg = "purple", fg = "white" })
vim.api.nvim_set_hl(0, "StatusLineTerminal", { bg = "cyan", fg = "black" })
end
-- Call the function to set highlights
set_highlights()
-- Function to update statusline based on mode
local function update_statusline()
local mode = vim.api.nvim_get_mode().mode
local highlight = colors.normal
local mode_text = "NORMAL"
if mode == "n" then
highlight = colors.normal
mode_text = "NORMAL"
elseif mode == "i" then
highlight = colors.insert
mode_text = "INSERT"
elseif mode == "v" then
highlight = colors.visual
mode_text = "VISUAL"
elseif mode == "V" then
highlight = colors.visual
mode_text = "VISUAL LINE"
elseif mode == "\22" then -- ^V, visual block mode
highlight = colors.visual_block
mode_text = "VISUAL BLOCK"
elseif mode == "R" then
highlight = colors.replace
mode_text = "REPLACE"
elseif mode == "c" then
highlight = colors.command
mode_text = "COMMAND"
elseif mode == "t" then
highlight = colors.terminal
mode_text = "TERMINAL"
end
local statusline = "%#" .. highlight .. "#"
statusline = statusline .. " " .. mode_text .. " %="
statusline = statusline .. " %f | %y | %l:%c | %p%% "
vim.opt.statusline = statusline
end
-- Create autocommand to update statusline when mode changes
vim.api.nvim_create_autocmd({"ModeChanged"}, {
pattern = "*",
callback = function()
update_statusline()
end,
})
-- Create autocommand to update statusline when entering a buffer
vim.api.nvim_create_autocmd({"BufEnter", "VimEnter"}, {
pattern = "*",
callback = function()
update_statusline()
end,
})
-- Initial statusline setup
update_statusline()
-- Key Mappings
-- Clear search highlighting with <Esc><Esc>
vim.keymap.set('n', '<Esc><Esc>', ':nohlsearch<CR>', { silent = true })
-- Other Recommended Settings (commented out)
-- ----------------------------------------
-- Enable mouse support for all modes
-- vim.opt.mouse = 'a'
-- Enable true color support for terminals that support it
vim.opt.termguicolors = true
-- Set line at 80 characters to help with code formatting
-- vim.opt.colorcolumn = '80'
-- Show matching brackets/parentheses
vim.opt.showmatch = true
-- Enable persistent undo history
vim.opt.undofile = true
vim.opt.undodir = vim.fn.stdpath('data') .. '/undodir'
-- Disable swap files (reduces clutter in project directories)
-- vim.opt.swapfile = false
-- Better splitting behavior (open new splits below and to the right)
-- vim.opt.splitbelow = true
-- vim.opt.splitright = true
-- Set scroll offset to keep cursor from edges
-- vim.opt.scrolloff = 8
-- vim.opt.sidescrolloff = 8
-- Case-insensitive searching UNLESS capital letter included
vim.opt.ignorecase = true
vim.opt.smartcase = true
-- Auto reload files when changed outside of Neovim
vim.opt.autoread = true
vim.api.nvim_create_autocmd({ "FocusGained", "BufEnter" }, {
pattern = "*",
command = "checktime",
})
-- Enable folding based on indentation
-- vim.opt.foldmethod = 'indent'
-- vim.opt.foldlevelstart = 99 -- Start with all folds open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment