Getting Familiar
Vim modes
- Command mode
- insert mode
- Command line mode
- Visual mode: switch from command mode to visual node type
v
operate with file
create new file or load file
1 | :edit message.txt |
open file in read-only mode
use -R option
1 | $ vim -R message.txt |
edit existing file
quit editor without saving changes
1
:q!
save changes and quit editor
1
:wq
editing
insert text before cursor
i
switch to insert mode
insert text at the beginning of line
problem: you want to insert text at the beginning of current line
solve: use I
append text after cursor
a
append text at the end of line
A
open new line below cursor
o
open new line above cursor
O
change text
problem: want to change text in current line then insert
solve: cc
or C
replace text
problem: want to replace character or entire line
solve: r
or R
Join text
problem: want to merge two line (this line and next line)
solve: J
Navigating
problem: how to quickly move cursor
Basic navigation (move cursor)
h
: leftl
: rightj
: upk
: down
more: navigation use number with those basic command, like 10j
0
: move cursor to the beginning of current line. likeI
but not to insert mode$
: move cursor to the end of current linectrl + f
: scroll down entire pagectrl + b
: scroll up entire page
navigate to lines
:n
: jump to the nth line:0
: jump to the start of file:$
: jump to the end of file
word navigation
w
: move cursor to the beginning of next wordb
: move cursor to the end of previous worde
: move cursor to the end of current word
revisiting editing
cut, copy and paste
x
: delete character from cursor positionX
: delete previous character from cursor positiony
: copy single characterp
: paste character after cursor positionP
: paste character before cursor position
multi-position command
dw
: Delete word from cursor positionD
: Delete entire line from cursor positiondd
: Delete entire lineY
oryy
: Copies entire line
more: 3dw
or d3w
delete 3 words
u
: undo likectrl + z
:red
orctrl + r
: redo likectrl + shift + z
searching
search in current file
search in forward direction
/<expression>
n
: nextN
: previous//
: repeat search
search in backward direction
?<expression>
n
: previousN
: next??
: repeat
search word under cursor
*
: next#
: previous
macros
start recording
- press
q
start - use single character as a macros name
stop recording
press q
again
use macros
@{macros name}
or number@{name}
list macros
:registers
vimrc
1 | let mapleader=" " |
- Post title:vim 基础学习
- Post author:auggie
- Create time:2022-04-18 09:30:43
- Post link:https://ruanjiancheng.github.io/2022/04/18/vim/
- Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.