1

  1. The cursor is moved using either the arrow keys or the hjkl keys.
    h (left) j (down) k (up) l (right)

  2. To delete the character at the cursor type: x

  3. To insert or append text type:
    i type inserted text insert before the cursor
    A type appended text append after the line

2

  1. To delete from the cursor up to the next word type: dw

  2. To delete from the cursor up to the end of the word type: de

  3. To delete from the cursor to the end of a line type: d$

  4. To delete a whole line type: dd

  5. To repeat a motion prepend it with a number: 2w

  6. The format for a change command is:
    operator [number] motion
    where:
    operator - is what to do, such as d for delete
    [number] - is an optional count to repeat the motion
    motion - moves over the text to operate on, such as w (word),
    e (end of word), $ (end of the line), etc.

  7. To move to the start of the line use a zero: 0

  8. To undo previous actions, type: u (lowercase u)
    To undo the undo’s, type: CTRL-R

3

  1. To put back text that has just been deleted, type p . This puts the
    deleted text AFTER the cursor (if a line was deleted it will go on the
    line below the cursor).

  2. To replace the character under the cursor, type r and then the
    character you want to have there.

  3. The change operator allows you to change from the cursor to where the
    motion takes you. eg. Type ce to change from the cursor to the end of
    the word, c$ to change to the end of a line.

  4. The format for change is:

    c   [number]   motion
    

4

  1. G moves to the end of the file.
    number G moves to that line number.
    gg moves to the first line.

  2. Typing / followed by a phrase searches FORWARD for the phrase.
    Typing ? followed by a phrase searches BACKWARD for the phrase.
    After a search type n to find the next occurrence in the same direction
    or N to search in the opposite direction.

  3. Typing % while the cursor is on a (,),[,],{, or } goes to its match.

  4. To substitute new for the first old in a line type :s/old/new
    To substitute new for all ‘old’s on a line type :s/old/new/g
    To substitute phrases between two line #’s type :#,#s/old/new/g
    To substitute all occurrences in the file type :%s/old/new/g
    To ask for confirmation each time add ‘c’ :%s/old/new/gc

5

  1. Type o to open a line BELOW the cursor and start Insert mode.
    Type O to open a line ABOVE the cursor.

  2. Type a to insert text AFTER the cursor.
    Type A to insert text after the end of the line.

  3. The e command moves to the end of a word.

  4. The y operator yanks (copies) text, p puts (pastes) it.

  5. Typing a capital R enters Replace mode until is pressed.

  6. Typing “:set xxx” sets the option “xxx”. Some options are:

    ‘ic’ ‘ignorecase’ ignore upper/lower case when searching
    ‘is’ ‘incsearch’ show partial matches for a search phrase
    ‘hls’ ‘hlsearch’ highlight all matching phrases
    You can either use the long or the short option name.

  7. Prepend “no” to switch an option off: :set noic

vim cheat sheet
![Advanced Vim](/img/Advanced vim.png)
vim2
vim-text-ver
vi-vim-tutorial-1
vi-vim-tutorial-2
vi-vim-tutorial-3
vi-vim-tutorial-4
vi-vim-tutorial-5
vi-vim-tutorial-6
vi-vim-tutorial-7

tips

Basic

1.命令模式
2.输入模式
3.底线命令模式
:wq save and quit
:w filename ave as other file
:set nu line number
:set nonu

i/I 输入字符
a/A 输入字符
o/O 新起一行
r/R 替换字符

移动光标操作

移动光标 hjkl/⬅️⬇️⬆️➡️
G 移动到最后一行
gg 移动到第一行
0 移动到行首
$ 移动到行尾

nG n为数字,移动到第n行(配合:set nu显示行号)
n n为数字,光标向下移动n行
ctr+f page down
ctr+b page up
ctr+d half page down
ctr+u half page up

文本操作

dd 删除当前行
ndd n为数字,删除n行
x delete
X Backspace
nx/nX 连续删除n个字符
yy 复制当前行
nyy n为数字,复制n行
p/P 粘贴复制的内容
v/V/Ctr+v 可视化模式
/word 搜索关键词,n下N上,从当前光标往下搜索(:set hlsearch 高亮显示)
?word 搜索关键词,从当前光标往上搜索
u,Ctr+r u撤销,ctr+r重做
:n1,n2s/wd1/wd2/g 搜索替换关键词 【eg. :1,$s/wd1/wd2/g :1,$s/wd1/wd2/gc】

Resources

Viemu
vim.org