Last Updated on April 27, 2023 by mishou
I. Open Neovim
nvim Open Neovim
nvim sample.txt Open sample.txt with Neovim
II. Modes
1.Normal mode
Esc The default mode that allows for navigation and executing commands.
2.Insert Mode
i or a The mode for inserting text into the document.
3.Visual Mode
v The mode for selecting and manipulating text.
4.Command Mode
: The mode for entering commands that affect the entire document or the editor itself.
5.Replace Mode
R The mode for replacing existing text by directly typing over it.
III. Command Mode
:e sample.txt Open a file in Neovim
:setlocal nonumber norelativenumber Remove the number setting
:set nu Set absolute line number
:set rnu Set relative line number
:10 Go to line 10
:viw Select a word
:%s/a/b/gci Find and replace (to replace a with b)
notes:
- To search and replace the pattern in the entire file, use %.
- To replace all occurrences of the search pattern in the current line, add the g flag.
- To substitute text, but want a confirmation every time you do it, you can use the c in the substitute command.
- To ignore case for the search pattern, use the i flag
:set spell Enable spell check
:term Open the terminal
:r !date Insert date and time on Unix-based systems
IV. Navigating – Normal Mode
Here are the basic keys for navigating.

h Move left
j Move down
k Move up
l Move right
w Jump to the beginning of the next word
b Jump to the beginning of the current or previous word
e Jump to the end of the current or next word
f find character after cursor in current line
F backwards version of “f”
t same as “f” but cursor moves to just before found character
T backwards version of “t”
0 (zero) Move to the beginning of the line
$ Move to the end of the line
Shift-a Start writing at the end of the line
gg Move to the beginning of the file
G Move to the end of the file
:10 Move to line 10
gi Move down in a long line
gk Move up in a long line
V.Editing – Normal Mode
i Enter Insert mode before the cursor
a Enter Insert mode after the cursor
o Open a line below the line and enter Insert mode
O Open a line above the line and enter Insert mode
U Undo
Ctrl-r Redo
dd Delete the line
D Delete from the cursor to the end of the line
C Delete from the cursor to the end of the line and enter Insert mode
yy Yank (copy) the line
p Pase the yanked text after the cursor
P Paste the yanked text before the cursor
r Replace the character with a new character
R Enter replace mode
s Delete the character and enter Insert mode
S Delete the line and enter Insert mode
x Deleter character under the cursor
VI. Find and Replace – Normal Mode
/ Search for a pattern
n Move to the next occurrence
N Move to the previous occurrence
:%s/a/b/gci Find and replace (to replace a with b)
notes:
- To search and replace the pattern in the entire file, use %.
- To replace all occurrences of the search pattern in the current line, add the g flag.
- To substitute text, but want a confirmation every time you do it, you can use the c in the substitute command.
- To ignore case for the search pattern, use the i flag
VII. Clipboard – Normal Mode
Copy to clipboard
“+y
Paste from clipboard
“+p
VIII. Saving – Normal Mode
:w Save
:wq Save and close the file
:w sample.txt Save as sample.txt
:qa! Force quit all files
- Begin recording a macro named “c” by typing “qc“.
- Type the keys to perform the actions you want to record, which in this case are “gg0vG$”+y“.
- Stop recording the macro by typing “q“.
- To copy all text to the system clipboard, just type “@c” in normal mode.
You can use “:%y+” instead of “gg0vG$”+y“
:reg Dislplay the content of the registers
IX. Visual Mode
v Enter Visual mode to select text character-wise
V Enter Visual mode to select whole lines
Ctrl-v Enter Visual mode to select text in a rectangular block
y Yank (copy) the selected text
d Delete the selected text
X. Registers
Register copied content
“ayy: Copy the line and register it as a
“ap: Paste the line registered as a
:reg Dislplay the content of the registers
XI. Macros
Creating a macro to copy all text to the system clipboard
- Begin recording a macro named c by typing qc
- Type the keys to perform the actions you want to record, which in this case are gg0vG$”+y
- Stop recording the macro by typing q
- To copy all text to the system clipboard, just type @c in Normal mode
You can use :%y+ instead of gg0vG$”+y
References
5 illustrated uses of VIM for DevOps