首页 > 编程知识 正文

linuxvi编辑器命令,vi和vim编辑器的区别

时间:2023-05-04 14:25:57 阅读:151899 作者:4374

Vim是从vi发展而来的文本编辑器,可以用颜色和下划线等表示特殊的信息。 Vim是Linux中不可缺少的工具,在构建网站和修改配置文件时经常使用。 本教程介绍Vim的模式和常规操作。

背景信息Vim的各模式的介绍如下表所示。 模式作用模式转变正常模式(Normal Mode ) )。

在此模式下,可以复制、粘贴和删除字符或行。 运行vim打开文件时,将进入正常模式。 在其他四种模式下,按Esc键将进入普通模式。 插入模式(insert模式)

在此模式下,可以插入字符。 在通常模式下,按下I、I、a、a、o、o中的任意一个文字即可进入插入模式。 进入插入模式后,编辑器左下角会显示----insert----。 替换模式(Replace Mode )

在此模式下,可以替换字符。 正常模式下,按r键进入更换模式。 说明进入替换模式后,编辑器左下角会显示----replace---- replace。 视觉模式(Visual Mode )

在此模式下,可以选择文本。 复制、替换和删除等命令仅适用于选定的文档。 在通常模式下,按v键进入可视模式。 说明进入可视模式后,编辑器左下角将显示----visual---visual。 命令模式(Command Mode )

在此模式下,可以搜索字符串、替换字符串、显示行号、保存更改、退出编辑器等。 在普通模式下,按:进入命令模式。 Vim的三种常见操作: 插入替换删除插入的基本命令: I :在当前字符的左侧插入。 I :插入到当前行的开头。 答:插入当前字符的右侧。 答:插入当前行的末尾。 o :在当前行下方插入新行。 o :在当前行上方插入新行。 此示例中使用的example.conf文件如下所示:

tobeabletousethefunctionalityofamodulewhichwasbuiltasadsoyou

havetoplacecorresponding ` load module ' linesatthislocationsothe

directivescontainedinitareactuallyavailablebeforetheyareused。

staticallycompiledmodules (thoselistedby ` httpd-l ' ) do not need

待加载的人。

Example:

load module foo _ module modules/mod _ foo.so

Include conf.modules.d/*.conf示例1 :在配置文件example.conf的第一行中插入Location。 步骤如下。 运行vim example.conf命令打开文件并进入正常模式。 按I进入插入模式。 输入Location。 按回车键换行。 按Esc键退出插入模式。 用:wq保存文件并退出。 插入完成后,example.conf文件应如下所示: 位置

tobeabletousethefunctionalityofamodulewhichwasbuiltasadsoyou

havetoplacecorresponding ` load module ' linesatthislocationsothe

directivescontainedinitareactuallyavailablebeforetheyareused。

staticallycompiledmodules (thoselistedby ` httpd-l ' ) do not need

待加载的人。

Example:

load module foo _ module modules/mod _ foo.so

Include conf.modules.d/*.conf示例2 :在配置文件example.conf的第10行的开头插入#。 步骤如下。 运行vim example.conf命令打开文件并进入正常模式。 按:10键,将光标对准第10行。 按I进入插入模式。 输入#。 按Esc键退出插入模式。 用:wq保存文件并退出。 插入操作完成后,example.conf文件将如下所示:

tobeabletousethefunctionalityofamodulewhichwasbuiltasadsoyou

havetoplacecorresponding ` load module ' linesatthislocationsothe

directivescontainedinitareactuallyavailablebeforetheyareused。

staticallycompiledmodules (thoselistedby ` httpd-l ' ) do

not need

to be loaded here.

Example:

LoadModule foo_module modules/mod_foo.so

#Include conf.modules.d/.conf 示例三:在配置文件example.conf中,在Include conf.modules.d/.conf行的下一行插入LoadModule rewrite_module modules/mod_rewrite.so。步骤如下: 运行vim example.conf命令打开文件,进入普通模式。 运行/Include conf.modules.d/*.conf找到目标行。 按o进入插入模式。 输入LoadModule rewrite_module modules/mod_rewrite.so。 按Esc键退出插入模式。 按:wq保存文件并退出。 插入完成后,example.conf文件如下所示:

To be able to use the functionality of a module which was built as a DSO you

have to place corresponding `LoadModule' lines at this location so the

directives contained in it are actually available before they are used.

Statically compiled modules (those listed by `httpd -l') do not need

to be loaded here.

Example:

LoadModule foo_module modules/mod_foo.so

Include conf.modules.d/*.conf LoadModule rewrite_module modules/mod_rewrite.so 替换 基本命令:

R:替换光标高亮的字符,直至按下Esc键退出替换模式。

本示例使用的example.conf文件,如下所示:

AllowOverride controls what directives may be placed in .htaccess files.

It can be "All", "None", or any combination of the keywords:

Options FileInfo AuthConfig Limit

AllowOverride None 示例:将配置文件example.conf中的AllowOverride None更改为AllowOverride All。

运行vim example.conf命令打开文件,进入普通模式。 运行/AllowOverride None找到目标。 移动光标至None的首字母。 按R进入替换模式。 输入All和一个空格。 说明 None中共包含4个字符,而All只包含3个字符,因此输入All之后,需再输入一个空格。 按Esc键退出替换模式。 按:wq保存文件并退出。 更改后的example.conf文件,如下所示:

AllowOverride controls what directives may be placed in .htaccess files.

It can be "All", "None", or any combination of the keywords:

Options FileInfo AuthConfig Limit

AllowOverride All 删除 基本命令: x:删除光标高亮的那一个字符。 nx(n为数字): 删除光标高亮的字符及其后面的n-1个字符。 dd:删除光标所在的那一行。 ndd(n为数字):删除光标所在行及其下面的n-1行。 本示例中使用的example.conf文件如下所示:

Listen: Allows you to bind Apache to specific IP addresses and/or

ports, instead of the default. See also the

directive.

Change this to Listen on specific IP addresses as shown below to

prevent Apache from glomming onto all bound IP addresses.

#Listen 12.34.56.78:80 Listen 80 示例一:在配置文件example.conf中,将#Listen 12.34.56.78:80行首的#删除。步骤如下: 运行vim example.conf命令打开文件,进入普通模式。 运行/#Listen 12.34.56.78:80找到目标,光标此时定位在#字符上。 按x删除#。 按:wq保存文件并退出。 删除完成后,example.conf文件如下所示:

Listen: Allows you to bind Apache to specific IP addresses and/or

ports, instead of the default. See also the

directive.

Change this to Listen on specific IP addresses as shown below to

prevent Apache from glomming onto all bound IP addresses.

Listen 12.34.56.78:80 Listen 80 示例二:在配置文件example.conf中,将#Listen 12.34.56.78:80行和下一行的内容删掉。步骤如下: 运行vim example.conf命令打开文件,进入普通模式。 运行/#Listen 12.34.56.78:80找到目标。 按2dd删除以下内容。 #Listen 12.34.56.78:80 Listen 80 按:wq保存文件并退出。 删除完成后,example.conf文件如下所示:

Listen: Allows you to bind Apache to specific IP addresses and/or

ports, instead of the default. See also the

directive.

Change this to Listen on specific IP addresses as shown below to

prevent Apache from glomming onto all bound IP addresses.

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。