Configuring Vim & Neovim

Out of the box, Vim and Neovim are capable editors, but they truly come alive once you start configuring them to match the way you think and work. Tailoring your settings is the first step toward making the editor feel like yours rather than a tool you're borrowing. In this chapter, you'll learn the essential options that most experienced users rely on, and you'll understand why each one matters so you can make informed choices for your own setup.

This chapter covers configuration that works in both Vim (vimrc) and Neovim (init.vim). For Lua-based Neovim configuration, see Chapter 11: Neovim with Lua.

What you'll learn in this chapter:

  • Set essential Vim/Neovim options for a productive editing experience

  • Configure search, indentation, and completion settings

  • Write autocommands to automate repetitive tasks

  • Manage your configuration with version control and bootstrapping

  • Apply colorschemes and customize visual appearance

Essential Settings

set number              " Show line numbers
set relativenumber      " Relative line numbers (great for motions!)
set hidden              " Allow switching buffers without saving
set path+=.,**          " Enable gf and :find to search recursively
set showcmd             " Show partial commands and selection count
set wildmenu            " Enhanced command-line completion
set wildmode=longest:full,full
set scrolloff=8         " Keep 8 lines visible above/below cursor
set sidescrolloff=8     " Keep 8 columns visible left/right
set signcolumn=yes      " Always show the sign column
set cursorline          " Highlight the current line
set termguicolors       " Enable 24-bit color
set undofile            " Persistent undo (survives closing Vim)
set updatetime=250      " Faster CursorHold events
set timeoutlen=300      " Faster key sequence completion

Search Settings

Indentation

Neovim: Many of these are already default in Neovim. Run :h vim-differences to see what Neovim sets by default (like autoindent, hlsearch, incsearch, wildmenu, etc.).

Colorschemes

Setting a Colorscheme

Change Background Based on Time

Resources for finding colorschemes:

Autocommands

Autocommands execute actions automatically when events occur. They pair well with custom key mappings (see Chapter 9: Mappings):

Tip: Always wrap autocommands in augroup with autocmd! to prevent duplicates when reloading your config.

Neovim Terminal Autocommands

Modelines

Modelines let you set file-specific options in the file itself:

Check your modeline settings:

Note: Modelines can be a security risk. Consider using securemodelinesarrow-up-right to restrict which options can be set via modelines.

Secure Modelines Configuration

The securemodelines plugin lets you whitelist specific options:

Only options in this list can be set via modelines — everything else is silently ignored.

Version Control for Config

Put your configuration under git version control (see Chapter 2: Modes, Navigation & Basics for information about $MYVIMRC and opening your config file):

Tip: Many Neovim users share their configs publicly -- searching GitHub for nvim dotfiles is a great way to learn.

Bootstrapping

Bootstrapping refers to scripts in your config that automatically install plugins and set up your environment on a fresh system.

Summary

A well-tuned configuration transforms Vim and Neovim from capable editors into deeply personal tools. By setting essential options, customizing search and indentation behavior, writing autocommands, and managing your dotfiles with version control, you build a setup that is fast, reproducible, and uniquely yours.

Key takeaways:

  • Core settings like number, relativenumber, hidden, undofile, and scrolloff form the foundation of a productive configuration.

  • Autocommands let you automate per-filetype settings, trailing whitespace removal, and other repetitive tasks -- always wrap them in augroup with autocmd! to avoid duplicates.

  • Keeping your configuration under version control ensures you can reproduce your setup on any machine and track changes over time.

  • For Lua-based Neovim configuration, see Chapter 11: Neovim with Lua.

Exercises

  1. Create a minimal configuration file -- Start from an empty vimrc or init.vim and add only the settings from the "Essential Settings" section. Open a source file and verify that line numbers, relative numbers, and cursor line highlighting are all working.

  2. Configure search behavior -- Add search settings so that searching is case-insensitive by default but becomes case-sensitive when you include an uppercase letter. Test by searching /hello and /Hello in a file containing both.

  3. Write a filetype autocommand -- Create an autocommand group that sets shiftwidth=2 and tabstop=2 for JavaScript and HTML files, while keeping shiftwidth=4 and tabstop=4 for Python files.

  4. Set up version-controlled dotfiles -- Move your Neovim configuration to a ~/.dotfiles directory, create a symlink back to ~/.config/nvim, initialize a git repository, and make your first commit.

  5. Install and apply a colorscheme -- Install a colorscheme plugin (such as gruvbox or catppuccin) and add the colorscheme command to your configuration. Set the background to dark and enable termguicolors.

Last updated

Was this helpful?