Neovim Tutor
After going through Programming in Lua, I started watching a video series on learning Neovim. It really got me wanting to try out Neovim, so I started with the tutor. I’ll probably just throw in a few of the most important things I learn in each chapter of the tutor.
Chapter 1
- Moving can be done with the arrows or
h
,j
,k
, andl
to move left, down, up, and right respectively - You can open any file in Neovim with
nvim FILENAME
. - Exiting Neovim is done with
:q!
to discard changes, and:wq
to keep changes - Deleting characters outside of
insert
mode can be done with hittingx
- Entering
insert
mode can be done by hittingi
- You can append to any line by hitting
A
- You can append to any line by hitting
- Hitting
Esc
brings you back tonormal
mode
Chapter 2
- The
delete
operator can be used to quickly get rid of wordsdw
to delete from your cursor to the next wordd$
to delete from your cursor to the end of a linedd
to delete an entire line
- You can use numbers before operators to repeat operations
w
moves word to word by the first lettere
moves word to word by the last letter
- Change command syntax is as follows,
operator [number] motion
0
moves to the beginning of a line- Undo changes with
u
- Undo all changes to a line with
U
- Go forward in time with
Ctrl+r
- Go forward in time with
- Undo all changes to a line with
Chapter 3
- After deleting anything, you can put it anywhere with
p
, placing it after the cursor - Replace any character with
r
and the character you want c
is the change operator; it replaces a section with putting you intoinsert
mode to make changesce
orc#e
will delete from the cursor to the end of the word or # amount of words
Chapter 4
- If you want to display your current line location, you can with
Ctrl+g
gg
brings your cursor to the first line#G
brings your cursor to line number #G
brings your cursor to the end of the file
- You can search for text using
/
and text to search forward in the file- You search backwards using
?
- When searching, press
n
for the next occurrence andN
for the previous
- You search backwards using
- Use
%
to bring your cursor to the opening or closing of a pair of brackets - Use
:s/old/new
to substitute the first occurrence ofold
withnew
- You can specify what lines you want to effect with
:#,#s
- You can use
:s/old/new/g
to replace an entire linesold
withnew
- Use
:%s/old/new
to replace allold
withnew
- You can specify what lines you want to effect with
Chapter 5
- You can use external commands using the
!
operator;:!ls
will runls
- Usually opens it up in a smaller window
- We can create new files easily with
:w FILENAME
, and just as easily remove it with:!rm FILENAME
- Traditional highlighting can be accomplished using
v
orVisual Selection
- After highlighting a section of text, you can use
d
to simply delete the selection - You can even save and move selected text into a separate file, writing
:w FILENAME
- You’ll notice after writing the
:
, some more characters appeared after it,'<, '>
. I don’t know why this happens, but it does let you know nicely that you are in some modifier mode
- You’ll notice after writing the
- After highlighting a section of text, you can use
- You can retrieve and place the contents of any file using
:r FILENAME
- A cool trick is reading the output of external commands; you can use
:r !ls
to read in the output ofls
- A cool trick is reading the output of external commands; you can use
Chapter 6
- Open is a command you can use to insert a new line under or above an existing line
- On a line, type
o
to insert a new line under the line your cursor exists on - Typing
O
will do the same but above the line your cursor is on
- On a line, type
- You can append to any line
a
brings you to the end of the word of your cursorA
brings you to the end of the line your cursor is on
- A new mode,
Replace
mode, can be entered not usingr
, butR
. It works likeInsert
mode but replaces over characters instead of inserting them into the line - Copy using
y
and paste withp
- You can use
v
to select andy
to copy it - You could also use
yank
as an operator, like usingyw
to copy a word P
places before your cursor instead of after
- You can use
- The
:set
operator can be used to configure other commands:set ic
ignores casing when searching:set is
shows partial matches:set hls
highlights all matching phrases- Use
no
in front of any of these options to switch them off
- Use