Vim 快速入门/备忘单 Vim 备忘单

2025-05-26

Vim 快速入门/速查表

Vim 备忘单

Vim 备忘单

内容
一般有用的东西
文本导航
处理多个文件
搜索
处理文本
视觉高级选择
使用 NERDTree
命令

一般有用的东西

Open a file for editing             :e path/to/file.txt
Return to Normal mode               ESC   or <CTRL>+C
Enter fullscreen mode Exit fullscreen mode

文本导航

您必须处于正常模式。使用 ESC 键退出可视、替换或插入模式。

(left)                       h
(down)                       j
(up)                         k
(right)                      l
next word                    e
Jump to the first line       gg
Jump to the last line        G
Enter fullscreen mode Exit fullscreen mode

输入文本

Insert text before cursor               i
Insert text after cursor                a
Enter fullscreen mode Exit fullscreen mode

处理多个文件

Open a file in a horizontal split   :sp path/to/file.txt
Open a file in a vertical split     :vsp path/to/file.txt
Move to a split window page         <CTRL>+w and a direction key (h, j, k, or l)
Move to next window pane            <CTRL>w w
Make selected pane bigger           CTRL>w +  (yes, you need the shift key for the plus)
Make selected pane smaller          <CTRL>w -
Enter fullscreen mode Exit fullscreen mode

搜索

Search for a word                           /<word>
Go to next match                            n
Find and replace on line                    :s/<find>/<replace>
Find and replace globally                   :%s/<find>/<replace>//gc
Go to first quote, replace text in quotes:  ci"
Enter fullscreen mode Exit fullscreen mode

处理文本

cut the current line                dd
copy the current line               yy
paste below current line            p
paste above current line            P
Remove the character under cursor   x
Remove the character before cursor  X
Delete the word under cursor        de
Delete to the end of the line       d$

Remove five lines starting here     5dd
Copy five lines starting here       5yy 

indent this line                    >>
indent five lines starting here     5>>

Replace mode (overtype)             r
Enter fullscreen mode Exit fullscreen mode

视觉高级选择

Visual mode                         v
Visual Line mode                    V
Visual Block mode                   <CTRL>v
Enter fullscreen mode Exit fullscreen mode

使用 NERDTree

Open the NERDTree                   :NERDTree
Toggle the NERDTree on and off      :NERDTreeToggle
Open selected file                  <ENTER>
Open selected file in horiz. split  i
Open selected file in vert. split   v
File menu                           m
Help                                ?
Enter fullscreen mode Exit fullscreen mode

命令:

Run a command                           :!<command>
Open a shell                            :sh
Enter fullscreen mode Exit fullscreen mode

如需交互式教程,请访问 openvim.com

在 Github 上关注我:www.github.com/rubiin

文章来源:https://dev.to/rubiin/vim-quickies-cheatsheet-30gm
PREV
声明式 vs 命令式
NEXT
很棒的 Nestjs