The installation of neovim on macOS is covered in a separate post. This one is about actually using the editor. If you’ve never really used vi, vim or neovim, or it’s been a while, this is a quick rundown of the commands you’ll need day to day. It applies to vim and neovim equally, the basics are identical.

Starting the Editor

On most systems, vi launches vim directly these days. Neovim is started with nvim. By default these editors live in the command line, so Terminal, iTerm2, or whatever terminal you use.

You can pass a file to open right at startup, e.g. nvim ~/.zshrc.

On the Mac there’s MacVim as a GUI for classic vim and VimR as a GUI for neovim. If you mostly live in the terminal, you don’t need either.

When you start the editor, you land in Normal mode.

Neovim right after the first launch

Neovim right after the first launch.

Normal, Insert, Command?

ModeWhat it’s for
normalNavigation and text manipulation. Press ESC to get back here.
insertThe actual mode for typing text. Enter it with i (and others).
visualSelect a region to act on.
commandThe editor’s command line. From normal mode press :.
Ex modeOriginally for batch processing and the ancestor of vi.

ESC always brings you back to normal mode. There you move around and run commands like dd to delete a line. In insert mode you actually type.

It sounds awkward at first but becomes second nature quickly.

The Most Important Commands in Command Mode

The first thing people struggle with is quitting the editor, so let’s start there.

In command mode (: from normal mode) you type real commands. Saving, opening, quitting and so on. I always write a leading colon so it’s clear the command goes into command mode.

Listing every command would explode this post. These are the essentials to actually operate vim or neovim.

Help

Take a look at :help at some point. vim ships with extremely thorough documentation. If a help window blocks part of the screen, :q usually gets you out.

Open, Save, Quit

CommandWhat it does
:qQuits the editor. Won’t quit if there are unsaved changes.
:q!Quits even with unsaved changes. Data loss possible.
:wSaves without quitting. :w filename saves under a new name.
:w! filenameSaves and overwrites an existing file, without quitting.
:wqSave and quit. The cool kids press ZZ in normal mode.
:wqaSave and close all tabs. Useful once you start using tabs.
:e filenameOpens a file in another buffer. Think of a buffer as another layer in the editor.

Search and Replace

Searching itself happens from normal mode, that’s covered further down.

CommandWhat it does
:%s/needle/replacement/gSearches and replaces across the whole document.
:%s/needle/replacement/gcSame, but asks before each replacement.
:%s/needle/replacementWithout /g, only the next occurrence is replaced.
:s/needle/replacement/gSearch and replace only in the current line.
:set ignorecaseSearches case-insensitively. Active for the current session only.
:set smartcasePairs with ignorecase. If you use uppercase, case is respected again.

For set commands to stick, they need to go into your vim or neovim config.

Buffers

CommandWhat it does
:bnJumps to the next buffer. You can have multiple files open in different buffers.
:bpJumps to the previous buffer.
:bfJumps to the first buffer.
:blJumps to the last buffer.
:buffersLists all open files (buffers).

That looks clunky but you can map it to keys. Splits and tabs are also a thing, but that’s a different topic.

Keyboard Commands for Normal, Insert, Visual and Friends

Moving Around in Normal Mode

CommandWhat it does
hCursor left. Arrow keys also work.
jCursor down.
kup.
lright.
$Jumps to the end of the line.
0Jumps to the start of the line.
^Jumps to the first non-whitespace character of the line.
ggJumps to the start of the document.
GJumps to the end of the document.
wMoves to the first character of the next word. Special characters count as words.
WJumps to the next word after a whitespace.
bLike w, but backwards.
BLike W, but backwards.
eLike w, but lands on the last character of the word.
ELike W, but on the last character of the word.
geLike b, but backwards.
gELike B, but backwards.
)Jumps to the first character of the next sentence.
(Jumps to the first character of the previous sentence.
}Jumps to the next paragraph.
{Jumps to the previous paragraph.
+Cursor to the first character of the next line.
-Cursor to the previous line.
HJumps to the first line of the visible window.
MJumps to the line in the middle of the visible area.
LJumps to the last line of the visible area.
fxJumps to the next occurrence of x in the current line. f, jumps to the next comma.
FxLike fx, but backwards.
txLike fx, but lands one character before.
TxLike Fx, but one character after.
%Jumps to the matching bracket, brace or comment partner at the cursor.

Moving in Normal and Insert Mode

CommandWhat it does
Arrow keysBehave like in any other editor.
Ctrl+uHalf a page up.
Ctrl+dHalf a page down.
Ctrl+bFull page up.
Ctrl+fFull page down.

Searching in Normal Mode

CommandWhat it does
*Searches for the next occurrence of the word under the cursor.
#Same backwards.
/needleForward search. Case sensitivity depends on settings.
?needleBackward search.
nJumps to the next match.
NJumps to the previous match.

From Normal to Insert Mode

CommandWhat it does
iEnters insert mode to type text.
aMoves one character forward, then enters insert mode.
IJumps to the first character of the line and enters insert mode.
AGoes to the end of the line and enters insert mode.
oAdds a line below the current one and enters insert mode.
OAdds a line above and enters insert mode.
cwReplaces the current word. Deletes it and enters insert mode.
ccDeletes the entire line and enters insert mode.
CDeletes everything from the cursor to the end of the line and enters insert mode.
sDeletes the character under the cursor and enters insert mode.

Deleting in Normal Mode

CommandWhat it does
xDeletes the character under the cursor. Backspace works too.
rReplaces the character under the cursor and stays in normal mode. ra puts an a there.
dwDeletes the word. dW, db and other combinations work too.
ddDeletes the entire line.
DDeletes from the cursor to the end of the line.

Copy and Paste in Normal Mode

CommandWhat it does
yYanks (copies) the selected text (see v and V).
yyYanks the entire line.
ywYanks the word under the cursor. The combinations keep repeating.
5yyYanks 5 lines. Works with other numbers too.
y$Yanks to the end of the line.
pPastes after the cursor.
PPastes before the cursor.
JJoins the current and next line.

Visual Mode

CommandWhat it does
vVisual mode, select text.
VVisual mode for whole lines.
oMoves the cursor in visual mode between the first and last character of the selection.
~Toggles case of the selection.
>Indents the selection to the right.
<Outdents the selection.

Case

CommandWhat it does
g~Toggles case of the character under the cursor.
g~$Toggles case from cursor to end of line.
g~~Toggles case for the current line.
gUUWhole line to uppercase.
guuWhole line to lowercase.

Undo, Redo, Repeat

CommandWhat it does
uUndo.
UReverts all changes on the current line.
Ctrl+rRedo.
.Repeats the last change. Delete a line, hit ., and another line is gone.
;Repeats the last f, t, F or T command.
,Like ;, but in the other direction.

More

You can prefix many movement and editing commands with a number. 5dd deletes 5 lines, 2dw deletes two words, 5j jumps 5 lines down.

For a much longer list, see tuxfight3r’s vim Keyboard Shortcuts. It goes well beyond what makes sense to dump here.