Explaining My Vimrc
Line by line breakdown of my vimrc file.
This is my .vimrc as of 2025-12-10. It’s a vanilla Vim setup that I believe is decently minimal.
1set viminfo=
2set noswapfile
3filetype plugin indent on
4
5set rnu nu
6set hlsearch
7set linebreak
8
9set tabstop=4 shiftwidth=4 expandtab smarttab
10set autoindent smartindent
11
12set laststatus=2
13set showcmd
14
15highlight TrailingWhitespace ctermbg=red
16autocmd BufWinEnter * match TrailingWhitespace /\s\+$/
17
18let mapleader=' '
19
20nnoremap <leader>q :q<CR>
21nnoremap <leader>w :x<CR>
22nnoremap <leader>f :up<CR>
23nnoremap <leader>d :bd<CR>
24
25nnoremap <leader>E :E<CR>
26nnoremap <leader>e :Te<CR>
27let g:netrw_fastbrowse=2
28
29noremap <leader>y "+y
30noremap <leader>p "+p
31noremap <leader>P "+P
32
33inoremap <expr> <Tab> getline('.')[0 : col('.')-2] =~ '\S' ? "\<C-n>" : "\<Tab>"
34
35nnoremap <C-l> :noh<CR><C-l>
36
37nnoremap <leader>s :set spell!<CR>
38nnoremap <leader>z z=
39inoremap <C-l> <c-g>u<Esc>[s1z=gi<c-g>u
40
41autocmd FileType markdown setlocal spell
42autocmd FileType netrw setlocal nu rnu
1set viminfo=
2set noswapfile
Disable the viminfo and swap file, I’ve never found them useful.
1filetype plugin indent on
Enable language specific plugins and indentation.
1set rnu nu
Enable relative line numbers whilst keeping the current line number.
1set hlsearch
Highlight searches.
1set linebreak
Wrap lines via words rather than characters, I find this wrapping more natural.
1set tabstop=4 shiftwidth=4 expandtab smarttab
Set tabs to 4 spaces and delete 4 spaces at a time.
1set autoindent smartindent
Enable smart automatic indentation.
1set laststatus=2
2set showcmd
Always show the status bar and current command being typed. I find the both information to have.
1highlight TrailingWhitespace ctermbg=red
2autocmd BufWinEnter * match TrailingWhitespace /\s\+$/
Create a highlight group that highlights trailing spaces in red. An autocommand because buffers spawned from Netrw lack the highlight group, so this just ensures they have it.
1let mapleader=' '
Set leader key to space.
1nnoremap <leader>q :q<CR>
2nnoremap <leader>w :x<CR>
3nnoremap <leader>f :up<CR>
4nnoremap <leader>d :bd<CR>
More convenient leader key bindings for quit, save and quit, save, and delete current buffer. f and d are notably on the home row.
1nnoremap <leader>E :E<CR>
2nnoremap <leader>e :Te<CR>
Leader key bindings to open Netrw in the current window or new tab respectively.
1let g:netrw_fastbrowse=2
Enable fast directory browsing for Netrw, which only obtains directory listings when the directory has never been seen before (or on refresh).
1noremap <leader>y "+y
2noremap <leader>p "+p
3noremap <leader>P "+P
Convenient leader key bindings for yanking to and pasting from system clipboard.
1inoremap <expr> <Tab> getline('.')[0 : col('.')-2] =~ '\S' ? "\<C-n>" : "\<Tab>"
Text completion on non-empty lines when pressing tab. The condition checks if the character is not whitespace, pressing <C-n> for text completion or a tab otherwise.
1nnoremap <C-l> :noh<CR><C-l>
Also clear last search highlight when refreshing display.
1nnoremap <leader>s :set spell!<CR>
2nnoremap <leader>z z=
Leader key bindings for toggling spell check and displaying spelling options.
1inoremap <C-l> <c-g>u<Esc>[s1z=gi<c-g>u
Spell check the last misspelling with the first suggestion, whilst retaining cursor position. <c-g>u creates and finishes a new undo group, so I can do undo the suggestion in one go. [s take the cursor to the last misspelling, 1z= uses the first suggestion. gi brings you back to the last place insertion mode was exited, in insert mode.
1autocmd FileType markdown setlocal spell
Enable spell check on markdown files.
1autocmd FileType netrw setlocal nu rnu
Enable relative line numbers because Netrw disables the setting.