Neovim Configuration Manual: Essential init.vim Settings

Introduction to init.vim

The init.vim file is where you can tailor Neovim to meet your specific coding and editing needs. Here are the essentials to help you customize Neovim effectively.

Syntax and Filetype Settings

  • Enable Syntax Highlighting: syntax on for basic enabling and syntax enable for re-enabling if turned off.
  • Filetype Detection and Indentation: filetype plugin indent on to activate plugins and indentation based on the filetype.

Appearance and User Interface

  • Color Scheme: colorscheme hackertheme sets your preferred theme.
  • Control Visuals: set termguicolors for true color support; set guifont=Dank\ Mono sets the GUI font.
  • Line Numbering: Toggle between absolute (set nu), relative (set relativenumber), and both.

Operational Behavior

  • Auto-Saving and Backup: set autowriteall to save all modified buffers automatically; use set nobackup and set noswapfile to disable backup and swap files.
  • Undo Management: set undodir=~/.vim/undodir and set undofile to keep undo history across sessions.
  • Clipboard Integration: set clipboard=unnamedplus to integrate with the system clipboard.

Editing Enhancements

  • Indentation and Tabs: set tabstop=2 softtabstop=2 shiftwidth=2 for consistent tab sizes; set expandtab converts tabs to spaces.
  • Smart Features: set smartindent for intelligent indentation; set smartcase for case-sensitive search only if search string contains uppercase letters.

Interaction and Accessibility

  • Mouse and Cursor Settings: set mouse=a enables mouse in all modes; set guicursor= configures cursor appearance and behavior.
  • Visual Adjustments: set nowrap to prevent line wrapping; set scrolloff=0 to adjust the visible buffer around the cursor.
  • Accessibility: set noerrorbells and set belloff=all to disable all bell sounds.

Advanced Configurations

  • Key Mappings and Commands: Create mappings for efficiency, like nnoremap <key combination> <commands>.
  • Event-Driven Automation: Use autocommands like au CursorHold * checktime | redraw! for dynamic updates.
  • Customizing Searches: set incsearch for incremental search, enhancing the search interaction.

Optimizing Performance

  • Timers and Delays: set timeoutlen=1000 and set ttimeoutlen=0 manage delays after keystrokes and escape sequences.
  • Performance Tweaks: set updatetime=100 reduces the update time, making Neovim more responsive.

Miscellaneous

  • Security and Permissions: set exrc allows Neovim to read the .vimrc file from the current directory; set modifiable permits modifications to the buffer.
  • Status and Information Display: set laststatus=2 ensures the status line is always visible.
" Enable syntax highlighting.
syntax on

" Enable syntax highlighting if it was previously turned off.
syntax enable

" Enable filetype detection, plugin, and indentation rules.
filetype plugin indent on

" Set the color scheme to 'hackertheme'.
colorscheme hackertheme

" Automatically save changes to all modified buffers.
set autowriteall

" Disable line wrapping.
set nowrap

" Set the number of lines to keep above and below the cursor. Here, it is 0.
set scrolloff=0

" Enable true color support.
set termguicolors

" The time Vim waits after a key is pressed to see if it is part of a key code.
set timeoutlen=1000

" Time Vim waits after an escape sequence to decide it is not a key code.
set ttimeoutlen=0

" Show line numbers relative to the current cursor position.
set relativenumber

" Disable the error bell sound.
set noerrorbells

" Set tab stops, and the width for soft tab stops.
set tabstop=2 softtabstop=2

" Set the number of spaces to use for each step of (auto)indent.
set shiftwidth=2

" Function to be used for omni-completion.
set omnifunc=syntaxcomplete#Complete

" Use spaces instead of tabs.
set expandtab

" Enable smart indentation.
set smartindent

" Show absolute line numbers.
set nu

" Show both absolute and relative line numbers.
set number relativenumber

" Set the time after which the swap file is written to disk.
set updatetime=2000

" Adjust the completeopt setting to enhance completion menu behavior.
set completeopt+=menuone,noselect,noinsert

" Enable smart case sensitivity for searches.
set smartcase

" Disable swap file creation.
set noswapfile

" Disable backup file creation.
set nobackup

" Set the directory for undo files.
set undodir=~/.vim/undodir

" Enable undo file creation to make undo information persistent.
set undofile

" Enable incremental search.
set incsearch

" Toggle the display of line numbers.
set invnumber

" Turn off highlighting search matches.
set nohlsearch

" Disable all bell sounds.
set belloff=all

" Enable mouse support in all modes.
set mouse=a

" Allow Vim to read .vimrc file in the current directory.
set exrc

" Allow modifications to the buffer.
set modifiable

" Set the background color scheme to dark.
set background=dark

" Set the sign column to display next to line numbers.
set signcolumn=number

" Set the clipboard to use the system clipboard (+ register).
set clipboard=unnamedplus

" Reduce the update time to make Vim more responsive.
set updatetime=100

" Set the GUI font to 'Dank Mono'.
set guifont=Dank\ Mono

" Define cursor shapes and behaviors in different modes.
set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
           \,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor
           \,sm:block-blinkwait175-blinkoff150-blinkon175

" Repeat clipboard setting; unnecessary if already set.
set clipboard=unnamedplus

" Run checktime and redraw commands when cursor is held in one place.
au CursorHold * checktime | redraw!

" Always display the status line.
set laststatus=2

" Enable handling mouse move events.
set mousemoveevent

" Set manual fold method.
set foldmethod=manual

" Enable folding based on the 'foldmethod'.
set foldenable

" Reset cursor settings (possibly by mistake or intentionally empty).
set guicursor=