Common operations for Vim
I. Find and Replace in vim
Modify when moving forward
:s/str1/str2/
Modifies the first str1 of the current line to STR2
:s/str1/str2/g
Modifies all str1 of the current line to STR2
Modify line N to line M
:n,ms/str1/str2/
Modify the first str1 of line N to line m to str2
:n,.s/str1/str2/
Modifies the first str1 of the nth row to the current line as str2
:.,ms/str1/str2/
Modifies the first str1 of the current line to row m to str2
:n,$s/str1/str2/
Modify the first str1 of the nth line to the last line as str2
PS: If you are modifying all of the lines str1
str2
, add g to the back
PS: If you are modifying all of the lines str1
str2
, add g to the back
ranges: The above has been mentioned
From : regular expressions can be used
To : the character to be replaced
flags: as shown below, these several combinations can be used
无 : 只对指定范围内的第一个匹配项进行替换。g : 对指定范围内的所有匹配项进行替换。c : 在替换前请求用户确认。e : 忽略执行过程中的错误。
Two. Vim's common shortcut keys
1. Basic upper and lower left and right
j
: On
k
: The next
h
: Left
l
: Right
2. Turn One page
ctrl + f
: Turn one page forward (forward)
ctrl + b
: one page back (backward)
3. Turn Half page
ctrl + u
: Turn half page forward (UP)
ctrl + d
: Half page backward (down)
4. Turn the line
ctrl + e
: Turn down one line
ctrl + y
: Turn up one line
5. Jump to the definition of functions and variables
[ + ctrl + i
: Jump To Definition
[ + ctrl + d
: Jump to # define place
6. Cursor Jumps
ctrl + i
: Jump Forward
ctrl + o
: Jump Backwards
7. Jump in function body
[{
: Jump to function Body header
]}
: Jumps to the end of the function body
[[
,,, ]]
{{
}}
, invert function body
8. Jump Words
b
: Go to the [B]eginnig of this word
e
: Go to the [e]nd of this word
w
: Go to the start of the following word
1. Selected ctrl + v
by the adjustment of the upper and lower left and right commands
2. shift + v
Select in the mode
vi(
: Select the contents of the parentheses, excluding the parentheses
va(
: Select the contents of the small brackets, including the parentheses , below
vi[
va[
vi{
va{
vi‘
va‘
vi"
va"
Common actions for Vim