Vim has several modes:
i
(insert before cursor), a
(append after cursor)Esc
or Ctrl+[
v
(character-wise), V
(line-wise), Ctrl+v
(block-wise):
(ex commands), /
(forward search), ?
(backward search)h
j
k
l
w
e
b
0
^
$
H
M
L
:n
(e.g., :5
goes to line 5)gg
G
Ctrl+d
Ctrl+u
Example:
(In Normal mode)
5j # Move down 5 lines
3w # Move forward 3 words
$ # Move to end of line
gg # Go to start of file
i
I
a
A
o
O
x
dd
D
dw
r
cw
C
cc
u
Ctrl+r
Example:
(In Normal mode)
i Hello, World! # Insert "Hello, World!"
Esc # Return to Normal mode
cw Vim # Change word to "Vim"
/pattern
?pattern
n
N
:s/old/new/
:%s/old/new/g
:%s/old/new/gc
Example:
/TODO # Search for "TODO"
:%s/foo/bar/g # Replace all "foo" with "bar" in the file
yy
yw
dd
dw
p
P
Example:
yy # Yank current line
3j # Move down 3 lines
p # Paste the yanked line
:ls
:bn
:bp
:b<number>
:sp
or :split
:vsp
or :vsplit
Ctrl+w
followed by h
, j
, k
, or l
:q
:tabnew
gt
gT
:tabclose
Example:
:vsp newfile.txt # Open newfile.txt in vertical split
Ctrl+w l # Move to right window
:tabnew # Open new tab
gt # Go to next tab
v
V
Ctrl+v
y
d
c
Example:
v3w # Select three words
y # Yank selection
p # Paste selection
q<letter>
to start, q
to stop@<letter>
@@
Example:
qa # Start recording macro 'a'
i( ) # Insert parentheses
Escf) # Move cursor to closing parenthesis
@a # Play macro 'a'
za
zo
zc
zR
zM
m<letter>
'<letter>
Example:
ma # Set mark 'a'
'a # Jump to line of mark 'a'
`a # Jump to exact position of mark 'a'
"<letter>y
"<letter>p
:reg
Example:
"ayy # Yank current line into register 'a'
"ap # Paste content of register 'a'
Vim configuration file: ~/.vimrc
Common settings:
set number " Show line numbers
set syntax=on " Enable syntax highlighting
set autoindent " Enable auto-indenting
set tabstop=4 " Set tab width to 4 spaces
set expandtab " Use spaces instead of tabs
.
:!command
!!
gf
Ctrl+]
Ctrl+t
Ctrl+n
(in Insert mode)Example:
:!ls # Run 'ls' command
!!sort # Sort current line using external 'sort' command
2024 © All rights reserved - buraxta.com