C.W.K.
Stream
Lesson 01 of 04 · published

Essential Settings — Vimscript and Lua

~14 min · vim, config, vimscript, lua

Level 0Trapped
0 XP0/35 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Where your config lives

Classic Vim reads ~/.vimrc at startup. Neovim reads ~/.config/nvim/init.vim if you want Vimscript, or ~/.config/nvim/init.lua if you want Lua (recommended for Neovim — Lua is a real programming language and the rest of the modern Neovim ecosystem is written in it).

The settings that change Vim from "weird editor" to "my editor"

You can have a comfortable, modern Vim with about 25 lines of configuration. The rest of this lesson is a walkthrough of what each essential setting does and why you want it on.

Line numbers — relative is the secret

set number shows the current line's absolute number. set relativenumber shows every other line's distance from the cursor. Combined, the cursor line shows the absolute number and everything else shows the count you'd type to get there. Want to delete down to that line marked "7"? 7dd. No mental math.

Tabs vs spaces — the eternal debate, settled per file

For most languages you want set expandtab (Tab key produces spaces), set tabstop=4 (a tab character displays as 4 spaces wide), set shiftwidth=4 (>> indents by 4), set softtabstop=4 (Tab in Insert mode acts like 4 spaces). Some languages (Go, Makefiles) want hard tabs — handle those per-filetype with autocommands.

Searching that doesn't fight you

set ignorecase + set smartcase means: lowercase searches are case-insensitive (/foo matches Foo, FOO, foo); uppercase searches are case-sensitive (/Foo matches only Foo). It's almost always what you want. Add incsearch (preview matches as you type) and hlsearch (highlight all matches).

The quality-of-life cluster

scrolloff=8 keeps 8 lines visible above and below the cursor — no more cursor sitting on the last line of the screen. signcolumn=yes reserves a column for git/LSP signs so the text doesn't jump when they appear. termguicolors enables true-color support. updatetime=250 makes CursorHold events (used by many plugins) feel instant. undofile persists your undo history across sessions.

Understand every line of your config. The biggest trap with Vim is copy-pasting a 2000-line .vimrc off the internet. Six months later it breaks, you don't know why, and you abandon Vim. Start small. Add a setting only when you've felt the absence of it. The 25-line config below is what you actually need to be productive on day one.

Code

Essential settings — Vimscript (~/.vimrc)·vim
" Display
set number
set relativenumber
set cursorline
set signcolumn=yes
set scrolloff=8
set sidescrolloff=8
set termguicolors
set wrap
set breakindent

" Indentation
set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
set autoindent
set smartindent

" Search
set ignorecase
set smartcase
set incsearch
set hlsearch

" Editing quality of life
set hidden
set mouse=a
set clipboard=unnamedplus
set splitright
set splitbelow
set undofile
set updatetime=250
set timeoutlen=300
set backspace=indent,eol,start
Same settings — Lua (~/.config/nvim/init.lua)·lua
-- Display
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.cursorline = true
vim.opt.signcolumn = "yes"
vim.opt.scrolloff = 8
vim.opt.sidescrolloff = 8
vim.opt.termguicolors = true
vim.opt.wrap = true
vim.opt.breakindent = true

-- Indentation
vim.opt.expandtab = true
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 4
vim.opt.autoindent = true
vim.opt.smartindent = true

-- Search
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.incsearch = true
vim.opt.hlsearch = true

-- Editing quality of life
vim.opt.hidden = true   -- default in Neovim, kept for clarity
vim.opt.mouse = "a"
vim.opt.clipboard = "unnamedplus"
vim.opt.splitright = true
vim.opt.splitbelow = true
vim.opt.undofile = true
vim.opt.updatetime = 250
vim.opt.timeoutlen = 300

External links

Exercise

Create or open ~/.config/nvim/init.lua. Paste the Lua essential-settings block above. Restart Neovim and verify each setting works: relative line numbers in the gutter, hlsearch highlighting after /, smartcase doing the right thing for /foo vs /Foo, undo history surviving a quit-and-reopen. Don't add anything else yet — feel the baseline.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.