博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vim 自带教程命令_vim教程和命令示例
阅读量:2530 次
发布时间:2019-05-11

本文共 6236 字,大约阅读时间需要 20 分钟。

vim 自带教程命令

vim, short for Vi Improved is a command-line text editor that is used for creating and viewing text files. In this vim tutorial, you are going to learn useful tips in using the vim text editor. Without much ado, let’s jump right in.

viVi改进的缩写, vim是一个命令行文本编辑器,用于创建和查看文本文件。 在本vim教程中,您将学习有关使用vim文本编辑器的有用提示。 事不宜迟,让我们直接进入。

Vim模式 (Vim modes)

vim has 2 modes; insert mode and command mode.

vim有2种模式; 插入模式和命令模式。

  1. Insert mode allows you to enter text into the text file like you would in a normal file editor.

    插入模式使您可以像在普通文件编辑器中一样在文本文件中输入文本。
  2. Normal mode gives you the power to navigate and make modifications to the text.

    普通模式使您能够导航和修改文本。

To navigate between the 2 modes, use the ESC character or i .

要在两种模式之间导航,请使用ESC字符或i

Once you open a text file you get into normal mode. To change to insert mode and start typing or inserting text, press the letter i on your keyboard.

打开文本文件后,您将进入普通模式。 要更改为插入模式并开始输入或插入文本,请按键盘上的字母i

To go back again to command mode, hit the Esc key.

要再次返回命令模式,请按Esc键。

插入方式 (Insert mode)

Insert mode allows you to interact with the text. For example, you can enter text, delete text and navigate up and down, left or right.

Once you’ve opened a text file using vim editor, you immediately land in command mode.

插入模式使您可以与文本进行交互。 例如,您可以输入文本,删除文本以及上下左右导航。

使用vim编辑器打开文本文件后,您立即进入命令模式。

To enter into Insert mode and start inserting text, follow the command below.

要进入插入模式并开始插入文本,请遵循以下命令。

插入文字 (Inserting text)

Press i key to insert text at the current cursor position.

i键在当前光标位置插入文本。

Press a key to insert text one character after the current position of the cursor.

a键在光标的当前位置之后插入一个字符的文本。

Press A key to insert text at the end of the current line.

A键在当前行的末尾插入文本。

Press o key to insert text on a new line below the current line.

o键在当前行下方的新行中插入文本。

Press O key to insert text on a new line above the current line.

O键在当前行上方的新行中插入文本。

删除文字 (Deleting text)

Press s key to delete the current letter on the cursor and insert text.

s键删除光标上的当前字母并插入文本。

Press S key to delete the current line and insert text.

S键删除当前行并插入文本。

vim命令模式下的命令 (Commands in vim command mode)

Let’s now look at the command mode. Arguably, this is the mode that you can perform most of the operations.

现在让我们看一下命令模式。 可以说,这是您可以执行大多数操作的模式。

在命令模式下导航(上/下,左/右) (Navigating in command mode (up/down, left/right))

To navigate up/down, left/right use the keys h, j, k, and l.

要上下左右导航,请使用键hjkl

k – Moves the cursor up by one line.

k –将光标向上移动一行。

j – Moves the cursor down by one line.

j –将光标向下移动一行。

l – Moves the cursor to the right by one character

l –将光标向右移动一个字符

h – Moves the cursor to the left by one character

h –将光标向左移动一个字符

In command mode, you can also navigate to the beginning and end of a line/file. Let’s dive into the commands for achieving this.

在命令模式下,您也可以导航到行/文件的开头和结尾。 让我们深入了解实现此目的的命令。

在命令模式下导航到行/文件的开头和结尾 (Navigating to the beginning and end of a line/file in command mode)

^ – Moves the cursor to the beginning of a line

^ –将光标移动到行首

$ – Moves the cursor to the end of a line

$ –将光标移动到行尾

1G – Moves the cursor to the beginning of a file.

1G –将光标移动到文件的开头。

G – Moves the cursor to the end of a file

G –将光标移到文件末尾

nG – Moves the cursor to the start of line number “n” in the file

nG –将光标移动到文件中行号“ n”的开头

搜索和替换文字 (Searching and replacing text)

Command mode also gives the user the ability to search and replace text in a file

命令模式还使用户能够搜索和替换文件中的文本

To search for text in a file, press the ESC key and use the / (forward slash) followed by the search term e.g

要在文件中搜索文本,请按ESC键并使用/ (forward slash)后跟搜索词,例如

:/Linux

To search backwards in the text file, again press the ESC key and use the ? followed by the search term e.g

要向后搜索文本文件,请再次按ESC键,然后使用? 后跟搜索词,例如

:?Linux

If you want to search a string and replace it with another string in the file, use the syntax

如果要搜索字符串并将其替换为文件中的另一个字符串,请使用以下语法

:[range]s/search/replace/

For example, if we want to search the string Linux and replace it with Unix from Line 1 to line 3 in code>linuxgeek.txt file , the command will be

例如,如果我们要搜索字符串Linux并在代码> linuxgeek.txt文件中从第1行到第3行将其替换为Unix ,则命令将为

:1,3 s/Linux/Unix/g

The /g ensures that all instances of the search string are replaced within the specified range. If you omit the /g option, only the first instance in each line will be replaced.

/g确保在指定范围内替换搜索字符串的所有实例。 如果省略/g选项,则仅替换每行中的第一个实例。

复制和粘贴文字 (Copying and pasting text)

Vim also gives you the ability to copy and paste text within the file.

Vim还使您能够在文件中复制和粘贴文本。

Copying text

To copy a string and paste it at another location in a file follow the steps below

复制文字

要复制字符串并将其粘贴到文件中的其他位置,请按照以下步骤操作

  1. Move the cursor to the beginning of the string or text

    将光标移到字符串或文本的开头
  2. Type v on your keyboard and press cursor forward to highlight text

    在键盘上键入v并向前按光标以突出显示文本
  3. Once you get to the end of text , hit y short for yank , to copy the text

    到达文本末尾时,按y代表yank即可复制文本
  4. Move the cursor to the location you want to paste the copied text

    将光标移到要粘贴复制的文本的位置
  5. Hit p short for paste, to paste the copied content

    点击p表示粘贴,以粘贴复制的内容

Additionally, you can use the commands below for copying lines.

此外,您可以使用以下命令复制行。

y$ – Copies text from current position to the end of the line

y$ –将文本从当前位置复制到行尾

yy – Copies the entire line

yy –复制整行

4yy – Copies 4 lines below

4yy –复制以下4行

剪切/删除文字 (Cutting/Deleting text)

If you want to delete a single character in command mode, hit the key x

如果要在命令模式下删除单个字符,请按x

To delete a word, place the cursor in front of the word and hit dw

要删除单词,请将光标放在单词前面,然后按dw

To delete text from the current word to the end of the line hit d$

要从当前单词到行尾删除文本,请按d$

To delete or cut the entire line hit dd

要删除或剪切整行,请按dd

NOTE:

You can delete a number of lines by preceding the dd command with a number. For example, to delete 3 lines including the current line, run 3dd

注意:

您可以通过在dd命令前添加数字来删除多行。 例如,要删除包括当前行的3行,请运行3dd

保存并退出vim编辑器 (Saving and Quitting vim Editor)

Below are different ways that you can use to quit the vim editor.

以下是退出vim编辑器的不同方法。

:wq – To save changes and quit the vim editor

:wq –保存更改并退出vim编辑器

:q! – To quit without saving changes

:q! –退出而不保存更改

:x or :exit or :e– To save and exit where changes exist

:x:exit:e –保存并退出存在更改的位置

结语 (Wrapping up)

We hope that you found this tutorial insightful. Feel free to take a test run on your editor and leave us feedback.

希望您对本教程有所了解。 随时在您的编辑器上进行测试,并给我们提供反馈。

翻译自:

vim 自带教程命令

转载地址:http://qjlzd.baihongyu.com/

你可能感兴趣的文章
阶段3 2.Spring_09.JdbcTemplate的基本使用_5 JdbcTemplate在spring的ioc中使用
查看>>
阶段3 3.SpringMVC·_07.SSM整合案例_02.ssm整合之搭建环境
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第1节零基础快速入门SpringBoot2.0_3、快速创建SpringBoot应用之手工创建web应用...
查看>>
阶段3 3.SpringMVC·_07.SSM整合案例_04.ssm整合之编写SpringMVC框架
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第1节零基础快速入门SpringBoot2.0_5、SpringBoot2.x的依赖默认Maven版本...
查看>>
阶段3 3.SpringMVC·_07.SSM整合案例_08.ssm整合之Spring整合MyBatis框架
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_9、SpringBoot基础HTTP其他提交方法请求实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_12、SpringBoot2.x文件上传实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_19、SpringBoot个性化启动banner设置debug日志...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_20、SpringBoot2.x配置全局异常实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第5节 SpringBoot部署war项目到tomcat9和启动原理讲解_23、SpringBoot2.x启动原理概述...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_21、SpringBoot2.x配置全局异常返回自定义页面...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_32..SpringBoot2.x持久化数据方式介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_34、SpringBoot整合Mybatis实操和打印SQL语句...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_35、事务介绍和常见的隔离级别,传播行为...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_40、Redis工具类封装讲解和实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_37、分布式缓存Redis介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_42、SpringBoot常用定时任务配置实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_39、SpringBoot2.x整合redis实战讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第14节 高级篇幅之SpringBoot多环境配置_59、SpringBoot多环境配置介绍和项目实战...
查看>>