【Linux】Start using vim! ! !

1 what is vim ?

Let’s first understand vi.
To put it simply, the difference between vi/vim is that they are both multi-mode editors. The difference is that vim is an upgraded version of vi. It is not only compatible with all instructions of vi, but also has some new features. in. For example, syntax highlighting and visual operations can be run not only on the terminal, but also on x window, mac os, and windows.

vim is equivalent to an upgraded version of vi . Vim has program editing capabilities. It can actively mark the correctness of grammar with font color, which is convenient for code writing. The program is simple and the editing speed is very fast.
In summary, this is an old-fashioned word processing tool, but It has a complete set of functions. It is not only a text processing tool, but also a program editing tool.

The most important thing is that vim has a rich ecology and is very convenient to use.

2 basic concepts of vim

vim has three main modes (vim has many modes):
command mode, bottom line mode, insertion mode

1. 命令/正常模式 (Normal mode):
   控制屏幕光标的移动,字符、字或行的删除,移动复制某区段及进入Insert mode下,或者到 last line mode
2. 插入模式 (Insert mode):
	只有在Insert mode下,才可以做文字输入,按「ESC」键可回到命令行模式。该模式是使用的最频繁的编辑模式。
3. 末行模式(last line mode)
	文件保存或退出,也可以进行文件替换,找字符串,列出行号等操作。 在命令模式下,shift+: 即可进入该模式。要查看你的所有模式:打开vim,底行模式直接输入


(My vim has been configured, and the interface is slightly different)

3 basic operations of vim!

After we understand vim, the next step is to learn how to use this practical tool.
We will explain it in detail in two parts, just like the mouse and keyboard shortcuts of Windows.

3.1 vim shortcut

3.1.1 Copy and paste

Copy and paste operation in vim:

yy 复制当前行
n + yy 连续复制 n 行
p 粘贴到光标下一行
n + p 粘贴 n 次

Let’s take a look at the specific operation effect:
(I won’t put the animation here when I copy and paste it, the picture is quite intuitive)
Insert image description here

The effect is more powerful than Ctrl c and Ctrl v!

3.1.2 Undo and cut

Undo cut operation in vim:
u 撤销操作
dd 剪切 / 删除 指定行
n + dd 剪切 / 删除 n 行

Let’s take a look at the operation effect:
Undo
Insert image description here
cut/Delete
Insert image description here
cut/Delete n lines
Insert image description here

3.1.3 Character operations

Character operations in vim:

shift + ` 切换大小写
n + x 删除 光标后 n 个字符 (一行内)
n + shift + x 删除 光标前 n 个字符 (一行内)
n + r 光标位置进行指定切换 一次可替换多个
shift + r 进入 替换模式 直接进行文本替换

Let’s see the operation effect

Switch case
Insert image description here
Delete characters
Insert image description here
Replace characters
Insert image description here

3.2 Cursor operation in vim

It's as flexible as a mouse.
Cursor operations in vim:

shift + 4 = $ 光标移动到当前行的结尾
shift + 6 = ^ 光标移动到当前行的开头
gg 移动光标到文本开头
shift + g 移动光标到文本最后一行
n + shift + g 移动光标到文本第 n 行
h j k l 左 下 上 右 移动光标
w 以单词为单位向后移动光标
b 以单词为单位向前移动光标

Let’s take a look at the operation effect:

Move to the beginning/end of the line
Insert image description here
Move to the beginning/
Insert image description here
end of the text Move the cursor up, down, left,
Insert image description here
and right in units of words
Insert image description here

3.3 vim file operations

File operations are operations such as saving, compiling, and forcing performed in bottom-line mode.
w 保存
q 退出
!强制进行操作
vs filename 多文件分屏操作
!command 不退出vim 进行 shell 指令操作

Let’s take a look at the operation effect:

Save and exit

bold style
Split screen operation
Insert image description here

Summarize

I have only introduced part of the operations of vim, and there are many more waiting for you to explore! ! !

Thanks♪(・ω・)ノThanks for reading

See you in the next article! ! !

Guess you like

Origin blog.csdn.net/JLX_1/article/details/135777245