Converting init.vim to init.lua

Converting init.vim to init.lua

One config file, not two

Neovim loads init.vim or init.lua, never both. Move the old file aside and start clean:

mv ~/.config/nvim/init.vim ~/.config/nvim/init.vim.bak

The conversion

Every set option becomes vim.opt.option = value:

vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.termguicolors = true
vim.opt.cursorline = true
vim.opt.scrolloff = 8

vim.g.mapleader = " "

vim.cmd("colorscheme hackertheme")

vim.keymap.set("n", "<leader>e", vim.cmd.Ex, {desc="File explorer"})

vim.opt.clipboard = "unnamedplus"

Three patterns cover almost everything:

  • Options: set numbervim.opt.number = true; paired settings like tabstop=4 shiftwidth=4 become two assignments.
  • Leader first: vim.g.mapleader must run before any mapping is defined, because mappings capture the leader at definition time.
  • Escape hatch: anything without a Lua API yet runs through vim.cmd("...") — the colorscheme line is the classic example.

The desc field on keymaps is worth the habit early: it is what which-key and :map display later, making your config self-documenting.

This exact file is available as a checkpoint in the course repo under stages/12-lua-config/.