You are on page 1of 16

gvim [1] [installation and basic use]

blog.csdn.net/qq_42759162/article/details/124733389

For the specific introduction of Vim, please refer to: Vim of


Linux Virtual Machine
(CentOS5) Study Notes (3) , which will not be introduced in detail here, but only some
installation and basic use of GVIM will be explained.

1. Installation
GVIM download: GVIM
opens the above webpage
(may be slow), and then click the red box in the figure below to
download the installation package:

Double-click the .exe program to start the installation, click Next:


1/16

check "I accept...", and then click Next:


Default:

2/16

Compatibility and extension selection: Vim original version and all extensions (default), it
is best to choose this option here, otherwise the installed GVIM may not be easy to use in
Windows.

Keymap selection: Map some keys.


Mouse selection: as shown in the figure.


3/16

The next step is to choose the installation location, it is best to choose a location other
than the C drive.

4/16

Click to install. After the installation is complete, there should be a few more GVIM icons
on the desktop, but don’t worry about it, just drag it to the recycle bin (I personally think
it’s useless, so you can keep it if you want).

2. Basic use

(1) Model introduction


Create a new test.v on the desktop (of course you can also create other text files), then
right click and use GVIM to open.

5/16

It should look like this after opening (maybe your interface is slightly different from mine,
don’t panic, it’s basically the same):

Well, at this time, we can start to explain the basic usage of GVIM. Students who have
never been in contact with it may find it very strange. Unlike ordinary editors, you can
directly enter the characters you want. On the contrary, if you press a few times casually,
there may be garbled characters.

Don't panic if you encounter problems~ GVIM has three modes: command mode, edit
mode and last line mode.

The interface you are now in is called 命令模式 , in this mode is Cannot edit files directly ,
but you can enter shortcut keys to perform some operations (delete lines, copy lines, move
the cursor, paste, etc.) [this is the default mode after opening the file]. As shown in the
figure above, you can see that in the command mode, the cursor of the mouse is a small
black square.

If you want to enter text like a normal editor, you need to enter it 编辑模式 . In this mode,
you can edit the content of the file.

Entering from the command mode to the editing mode is very simple, you only need to
press the button the English input method , you can try it. i

6/16
As shown in the figure below, you can see that after entering the editing mode, the mouse
cursor becomes like a normal editor, and it is displayed under GVIM --插入-- ,
indicating that you are now in editing mode.

Of course, if you want to return to command mode from edit mode at this time, just press
a esc key.

The line shown in the figure above --插入-- is the last line, 末行模式 where commands
can be entered to operate on the file (search, replace, save, exit, undo, highlight, etc.). To
enter the last line mode, you must first be in the command mode, that is, the mouse
cursor must be a small black square. In the command mode, press : or /(表示查找) to
enter the last line mode; press esc to return to the command mode from the last line
mode.

Okay, that’s the end of the explanation of the three modes of GVIM. Let’s practice more,
and we must be proficient in these operations.

(2) Edit mode


First of all, let me explain some operations of the editing mode. The operation of the
editing mode is no operation (/doge), hahaha, it is actually an ordinary editor.

Press i the key to enter, and enter the following text:

7/16
module add(

a,

b,

);

input a;

input b;

output c;

wire a;

wire b;

wire c;

assign c = a + b;

endmodule

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

This is a simple addition operation, regardless of syntax. Select my code above, copy, go
into test.v, and ctrl+v paste. If ctrl+v you can't paste it, don't worry, you can click on
the toolbar first 从剪贴板粘贴 .

8/16
(3) Command mode
Press Escape from edit mode to esc enter command mode. Here we only introduce some
commonly used operations. It is enough to use these operations to complete daily tasks.
When you want to expand other usages, you can just go to Baidu at that time.

1. Cursor movement

Order Behavior

gg move the cursor to the beginning of the line

G move the cursor to the last line

Number+G Move the cursor to the specified line

Cursor movement, so much is enough for the time being.

2. Copy/cut/delete/paste operations

Order Behavior

yy copy current line

number+yy Based on the line where the cursor is (including the current line), copy
the specified number of lines down

9/16
Order Behavior

p Paste what you copied

number+p Paste copied content multiple times

dd Cut/delete, dd is strictly a cut command, but if it is cut and not pasted, it


will delete the effect

number+dd Cut/delete the line where the cursor is located (including the current line),
delete/cut the specified line downward

In the newly created file, try these operations more, and you will be able to remember
them after a few times.

3. Undo/Redo

Order Behavior

u revoke (undo)

ctrl+r Redo previous undo

4. Other

Order Behavior

j Move the cursor down one line

k Move the cursor up one line

h Move the cursor one column to the left

l Move the cursor one column to the right

ctrl+p Completion command, which can complete keywords that have appeared in
your current document

ctrl+q Column selection mode. After entering this mode, you can select columns
through h, j, k, l. After column selection, you can perform operations such as
inserting and copying (you can also directly select with the mouse in command
mode, and then ctrl+q)

10/16
Search keywords: click the keyword with the mouse, then *, n to search down, N to
search up

column insert:

1. ctrl+q enters the column selection mode, hjkl (or up, down, left, and right
keys) selects the left, bottom, upper and right range (you can also directly
select the mouse in the command mode, and then ctrl+q)
2. Uppercase I edit input text
3. esc to exit

The effect is as follows:


11/16
12/16
Recording command
qa,q,100@a

q start recording
a recording name

q end recording

100 repeat 100 times


@a, a is the name

and try a few more


times according to the above command, this recording method
GVIM is simply repeating what you just did Actions. The effect is as follows (press
qa to start recording, then press i to enter edit mode, then enter one or more
characters, esc to exit, move the cursor to the beginning of the next line, and then
press q to end recording, press the number to be the number of times you want to
repeat, Then press @a to achieve it, here is the picture below to add i characters at
the beginning of the 3 lines):

(4) Last line mode


从命令模式进入末行模式只需按 : 或 / ,退出末行模式只需按 esc ,或者删除末行命令
和冒号,就可以退出了。

Order Behavior

:w save document

:w path save file as

:q exit file

13/16
Order Behavior

:wq 保存并退出文件

:q! 强制退出文件且不保存

:!外部命令 调用外部命令,当外部命令执行结束之后按下任意键回到vim编辑
器打开的内容

/关键词 搜索/查找关键词

N/n 在搜索结果中切换上(N)/下(n)一个结果

:nohl 取消高亮(no highlight)

:行数 跳到指定行数或者直接在命令窗口行数加G

:ab Zhushi /***** < :ab 使用后面的快捷命令就可以得到后面的结果,< Enter >表示换


enter >******/ 行,类似于C语言宏定义,就是起个别名

下图首先显示了通过 :nohl 取消高亮,然后给 input a; 取个别名叫 mb ,然后进入编辑


模式,输入 mb 即可实现 input a; 的替换。

==别名非常好用!!!==如果你是一个Verilog开发者,可以通过起别名的方式来保存一
些Verilog模板,可以极大地提升你的编程效率!具体请参考: gvim【二】:ab命令快速制
作verilog模板

文本替换

14/16
:s/搜索的关键词/新的内容 替换光标所在行的第一处符合条件的内容

:s/搜索的关键词/新的内容/g 替换光标所在行的全部符合条件的内容

:%s/搜索的关键词/新的内容 替换整个文档中每行第一个符合条件的内容

:%s/搜索的关键词/新的内容/g 替换整个文档的符合条件的内容

1
2
3
4

%表示整个文件

g表示全局(global)

1
2

常用:

替换整个文档中的字符 :%s/xx/yy/gc
%s:作用在整个文档

xx:要被替换的字符

yy:替换为yy

gc:一个一个的进行替换,如果只有g的话就是全部替换

替换某个部分的字符
:10,15s/xx/yy/gc

10,15表示10到15行

下图表示了通过 / 进行搜索关键词,以及 %s 进行文本替换的操作。


15/16
You can use the command echo $VIM to determine the installation directory of Vim. The
user home directory can be determined using the command echo $HOME. The user
configuration file takes precedence over the system configuration file. When Vim starts, it
will read the .vimrc file in the root directory of the current user first. Therefore, the
personalized configuration related to individual users is generally placed in ~/.vimrc.

3. Other blogs in this series

16/16

You might also like