Here’s a cheat sheet for using Neovim (nvim), a modern and extensible text editor:
Modes
- Normal Mode:
- Default mode for navigating and manipulating text.
- Press
Esc
to enter Normal Mode.
- Insert Mode:
- Mode for inserting and editing text.
- Press
i
in Normal Mode to enter Insert Mode.
- Visual Mode:
- Used for selecting and manipulating text.
- Press
v
in Normal Mode to enter Visual Mode.
- Command-Line Mode:
- Mode for entering commands.
- Press
:
in Normal Mode to enter Command-Line Mode.
Navigation
- Basic Movement:
h
: Move leftj
: Move downk
: Move upl
: Move right
- Word Movement:
w
: Move to the beginning of the next wordb
: Move to the beginning of the previous worde
: Move to the end of the current word
- Line Movement:
0
: Move to the beginning of the line^
: Move to the first non-blank character of the line$
: Move to the end of the line
- Page Movement:
Ctrl + u
: Move half a page upCtrl + d
: Move half a page downCtrl + b
: Move one page upCtrl + f
: Move one page downgg
: Move to the beginning of the fileG
: Move to the end of the file:<line-number>
: Move to a specific line
Editing
- Inserting Text:
i
: Insert before the cursorI
: Insert at the beginning of the linea
: Insert after the cursorA
: Insert at the end of the lineo
: Open a new line belowO
: Open a new line above
- Deleting Text:
x
: Delete the character under the cursordd
: Delete the current linedw
: Delete from the cursor to the next wordD
: Delete from the cursor to the end of the line
- Copying and Pasting:
yy
: Copy the current lineyw
: Copy from the cursor to the end of the current wordp
: Paste after the cursorP
: Paste before the cursor
Visual Mode
- Selecting Text:
v
: Enter Visual ModeV
: Enter Visual Line ModeCtrl + v
: Enter Visual Block Mode
- Indentation:
>
: Indent selected lines<
: Unindent selected lines
Saving and Quitting
- Saving:
:w
: Save changes
- Quitting:
:q
: Quit (close the current window):q!
: Quit without saving changes:wq
or:x
: Save and quitZZ
: Save and quit
- Multiple Files:
:e <file>
: Open a new file:ls
: List open buffers:b <buffer>
: Switch to a specific buffer:bd
: Close the current buffer
Search and Replace
- Searching:
/
: Enter search moden
: Move to the next search resultN
: Move to the previous search result
- Replace:
:s/old/new/g
: Replace all occurrences of “old” with “new” in the current line:%s/old/new/g
: Replace all occurrences in the entire file
Miscellaneous
- Undo and Redo:
u
: UndoCtrl + r
: Redo
- Help:
:help
: Open the help documentation
This cheat sheet covers some essential Neovim commands. Neovim is highly extensible, and there are many plugins and configurations available to enhance its functionality. For more in-depth information, refer to the official Neovim documentation.