Skip to content

Instantly share code, notes, and snippets.

@cdlhub
Last active July 15, 2026 15:54
Show Gist options
  • Select an option

  • Save cdlhub/8397990da850c18a4121b9c4a0de760d to your computer and use it in GitHub Desktop.

Select an option

Save cdlhub/8397990da850c18a4121b9c4a0de760d to your computer and use it in GitHub Desktop.
NeoVim useful commands to start with
set nocompatible
" set showmatch
set ignorecase
set hlsearch
set incsearch
set tabstop=4
set softtabstop=4
set expandtab
set shiftwidth=4
set autoindent
set number
" set <leader> to ',' instead of '\'
" which is more accessible
let mapleader=","
syntax on
" mapping
" i: insert mode
" n: normal mode
" v: visual mode
" 'nore' means no-recursion
inoremap kj <Esc>:w<CR>
" change surrounded text
nnoremap ci" T"ct"
nnoremap ci' T'ct'
nnoremap ci( T(ct)
nnoremap ci[ T[ct]
nnoremap ci) T(ct)
nnoremap ci] T[ct]
" remove surrounding characters
nnoremap d" F"xf"x
" surround selected text (visual mode)
" c: cut visual selection and enter insert mode
" <char>: insert starting <char>
" <C-r>": paste selection
" <char>: insert ending <char>
" <Esc>: back to normal mode
vnoremap s" c"<C-r>""<Esc>
vnoremap s' c'<C-r>"'<Esc>
vnoremap s( c(<C-r>")<Esc>
vnoremap s[ c[<C-r>"]<Esc>
" unhighlight search terms
nnoremap // :nohlsearch<CR>

Practical neovim

Objectives

Minimalistic approach (I don't want to spend 10000 hours to become a neovim guru):

  • Learn minimal set of commands to reduce cognitive load.
  • Install least number of plugins for the simplest configuration (avoid them as much as possible).
  • Easy switch to bare vi when needed.

Navigation

Quick navigation in the current line:

  • Search for the word you want to go to: /<word> (forward) or ?<word> (backward), press and n. If you set hlsearch and want to quickly unhighlight, you can add nnoremap // :nohlsearch<CR> to your init.vim file. Then you can double press // to unhighlight search.
  • Use f/t or F/T commands and ; to repeat the move. f<space> can be very convenient here.

I prefer this instead of w/b. This helps me keep the minimum number of commands in my muscle memory. I don't have to think which command is the best. I always use the same for all kind of things. The f/t is very useful in conjunction with d/c commands and . to repeat.

  • Jump to previous edit locations: g; (or just the last one with `., but why should I remember this one).
  • Jump forward to edit locations (in case you went to far with g;): g,.

Scroll

  • zz - move current line to the middle of the screen.

  • zt - move current line to the top of the screen.

  • zb - move current line to the bottom of the screen.

  • Ctrl-e - scroll one line down, constant pressing works.

  • Ctrl-y - scroll one line up, constant pressing works.

Less usefull to me:

  • Ctrl-d - scroll down half screen, constant pressing works.
  • Ctrl-u - scroll up half screen, constant pressing works.

I never use page down/up (Ctrl-b/Ctrl-f). If I then want to move the cursor to a specific line after scrolling, I use: <n>G (set number must be set in init.vim).

Modify

  • cc - replace current line.
  • C - replace to end of line.

Delete

Normal mode:

  • x - delete current character.
  • X - delete previous character.

Insert mode:

  • BACKSPACE - delete previous character.
  • Ctrl-w - delete previous word.

Copy / Paste

  • Ctrl-r" - Paste content of last y/d/c command.

Search and Replace

Search modifiers:

  • g - whole document.
  • c - confirm replacement.
  • I - case sensitive.
  • \<word\> - whole word only.

Useful tips:

  • s// - search previous pattern.
  • * - search word under cursor; then use :%s//<replacement>/gI to replace in the whole document.

Infos

Print list of last 100 changes: :changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment