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.

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

翻译自: https://www.journaldev.com/29013/vim-tutorial-command-examples

vim 自带教程命令

vim 自带教程命令_vim教程和命令示例相关推荐

  1. ubuntu vim保存退出命令_vim极为详细的教程(一)基本操作

    vim的总体介绍 我以前是坚定的vim党,但后来用了一次vscode,便再也出不来了.vscode虽然功能强大,但本质上任然是个编译器,它强大的功能来自于对各种经典工具的灵活调用,vscode开发C+ ...

  2. vim自带的练习教程(vimtutor)

    声明:本文源于Centos 7.2系统vim自带的练习教程--vimtutor 欢迎阅 读< V I M  教  程 > - 版本 1.7 Vim 是一个具有很多命令的功能非常强大的编辑器 ...

  3. Vim 自带教程中文版 —— vimtutor

    文章目录 前言 第一讲 第一讲第一节:移动光标 第一讲第二节:VIM的进入和退出 第一讲第三节:文本编辑之删除 第一讲第四节:文本编辑之插入 第一讲第五节:文本编辑之添加 第一讲第六节:编辑文件 第一 ...

  4. Linux 常用命令与教程

    http://c.biancheng.net/view/705.html C语言编程网的教程很好 还有菜鸟教程的 https://baike.baidu.com/item/PS/8850709 百度百 ...

  5. screen 命令基本操作教程

    与 tmux 工具较为类似,sreen 命令同样提供在唯一个的命令行终端上进行多窗口切换和管理的基本功能( 关于 tmux 基本操作可参见笔者的博文 终端复用工具 tmux 基本操作教程 ).scre ...

  6. 运行caffe自带的mnist实例教程

    运行caffe自带的mnist实例教程 1.先进入caffe文件目录,(指令:cd ./caffe),再用data/mnist下的get_mnist.sh下載MNIST数据集,代码如下: cd ./c ...

  7. 只要 8 个步骤,学会这个 Docker 命令终极教程!

    作者 | Timothy Mugayi 译者 | 弯月 责编 | 徐威龙 封图| CSDN 下载于视觉中国 Docker容器已经从一种锦上添花的技术转变成了部署环境的必需品.有时,作为开发人员,我们需 ...

  8. 新一代 OIer 的快速入门命令行教程

    前言:为啥写这篇教程 几位家长:"欸wwh,你比赛时用啥写程序啊?" 我:"gedit + 命令行编译." (一番解释之后) 几位家长:"哦哦哦我明白 ...

  9. 计算机网络丢包排查,ping命令图文教程,电脑测试网络丢包延迟,检测网络故障通不通...

    原标题:ping命令图文教程,电脑测试网络丢包延迟,检测网络故障通不通 你好,我是老盖,首先感谢你观看本文,本篇文章我做的有视频,视频讲述的比较详细,也可以看我发布的视频. 这里演示一下ping的命令 ...

最新文章

  1. 实时荧光定量聚合酶链式反应和2-▲CT方法分析相关基因表达数据
  2. 赶考在线执业药师,7-8月提分策略,化繁为简
  3. VR/AR会是微信后马化腾进军的战场吗
  4. linux完整面授视频,Linux面授实战
  5. OpenGL® ES 3.0 Programming Guide - Book Website
  6. 将 WinForms 应用从 .NET Core 3.0 升级到 3.1
  7. jdk1.8 ::构造函数_在JDK 8中可通过反射获得构造函数/方法参数元数据
  8. python 保存图片代码_最简单的selenium+Python自动右键保存图片
  9. Altova XMLSpy2011的破解出现的问题
  10. Python代码画哆啦A梦战斗猫--Turtle画图
  11. sin1用计算机怎么算,sin1等于多少?
  12. c语言编程培训都是小学,小学编程培训班明故宫哪里有C语言培训
  13. Apple ID到期续费问题及验证手机(开启双重认证)
  14. android 前后同时预览_GitHub 上优质项目整理,不只 Android
  15. 1000瓶水有1瓶水有毒,老鼠喝一滴就会死,但是需要一周毒发,请问最少需要多少老鼠多少时间才能找到那瓶有毒的水。
  16. day06ViewPager
  17. 市净率PB,市盈率PE
  18. TSP之动态规划找最优解
  19. FDTD Solutions-边界条件
  20. linux trac git,trac安装、配置、中文化、支持git(Linux,Mac)

热门文章

  1. OpenGL使用Frame Buffer Object(FBO)来进行离屏渲染
  2. linphone呼叫流程分析
  3. Ubuntu系统下C语言的简单使用及gcc和Makefile编译C程序
  4. html如何将input上下移动,JS实现表格使用上下左右键在input移动
  5. 能链科技深耕苏州,受邀参加中国金融科技产业峰会
  6. java下载 xls xlsx遇到的问题
  7. 影响流水线性能的因素
  8. 4月第2周榜单丨飞瓜数据B站UP主排行榜(哔哩哔哩平台)发布!
  9. 你必须知道 开区间 闭区间 半开区间 是什么?如何表示?
  10. Delphi版本的淘宝接口(TopAPI)开发