diff --git a/en/chapter03.md b/en/chapter03.md index e57953f..955831f 100644 --- a/en/chapter03.md +++ b/en/chapter03.md @@ -1,91 +1,99 @@ # Chapter 3: Modifying and Saving Files -## 修改文档 +## Modify the document -你现在已经学会了控制光标、打开文件、切换文件、并在文件中查找内容,这些操作都是在 -Vim 的 normal 模式下进行的。现在,是时候进入 Vim 的另外一种模式 —— insert 模式, -学习一下如何修改文件了。 +You have learned how to control the cursor, open files, switch files, and find +content in files. These operations are all performed in Vim's normal mode. Now, +it's time to enter another mode of Vim - insert mode, and learn how to modify +the file. -### 插入 +### Insert -- `i` 当前字符前插入 -- `a` 当前字符后插入 -- `I` 行首插入 -- `A` 行尾插入 -- `o` 在下一行插入 -- `O` 在上一行插入 +- `i` insert before the current character +- `a` insert after the current character +- `I` insert at the beginning of the line +- `A` insert at the end of the line +- `o` insert in the next line +- `O` insert in the previous line -_注意:以上任何一个命令都会使 Vim 进入 insert 模式,进入该模式后光标会发生变化, -这时输入的文字会直接出现在文档中,按 `Esc` 键或 `Ctrl-[` 或 `Ctrl-C` 退出 insert -模式。_ +_Note: Any of the above commands will cause Vim to enter insert mode. After +entering this mode, the cursor will change, and the text you enter will appear +directly in the document. Press `Esc` or `Ctrl-[` or `Ctrl-C` to exit insert +mode._ -### 删除(并保存到 Vim 剪贴板) +### Delete (and save to Vim clipboard) -- `s` 删除当前字符,并进入 `INSERT` 模式 -- `S` 删除当前行并保存到 Vim 剪贴板,同时进入 `INSERT` 模式(等同于 `cc`) -- `x` 删除当前字符,相当于 insert 模式下的 `Delete` -- `X` 删除前一个字符,相当于 insert 模式下的 `Backspace` -- `dd` 删除当前行,并将删除的内容保存到 Vim 剪贴板 -- `d` 删除指定内容并保存到 Vim 剪贴板 -- `cc` 删除当前行并保存到 Vim 剪贴板,同时进入 `INSERT` 模式 -- `c` 删除指定内容并保存到 Vim 剪贴板,同时进入 `INSERT` 模式 +- `s` delete the current character and enter `INSERT` mode +- `S` delete the current line and save it to the Vim clipboard, and enter + `INSERT` mode (equivalent to `cc`) +- `x` delete the current character, equivalent to `Delete` in insert mode +- `X` delete the previous character, equivalent to `Backspace` in insert mode +- `dd` delete the current line and save it to the Vim clipboard +- `d` delete the specified content and save it to the Vim clipboard +- `cc` delete the current line and save it to the Vim clipboard, and enter + `INSERT` mode +- `c` delete the specified content and save it to the Vim clipboard, and + enter -_说明: `` 部分是对操作内容的描述,如果要删除一个单词,就输入 `dw` 或者 -`de`,要复制当前位置到行尾的内容,就输入 `y$`,要删除后面 3 个字符并插入,就输入 -`c3l` 诸如此类。_ +_Note: The `` part is a description of the operation content. If you want to +delete a word, enter `dw` or `de`. If you want to copy the content from the +current position to the end of the line, enter `y$`. If you want to delete the +next 3 characters and insert them, enter `c3l`, and so on._ -### 复制 +### Copy -- `yy` 复制当前行到 Vim 剪贴板 -- `y` 复制指定内容到 Vim 剪贴板 +- `yy` copy the current line to the Vim clipboard +- `y` copy the specified content to the Vim clipboard -### 粘贴 +### Paste -- `p` 在当前位置后粘贴 -- `P` 在当前位置前粘贴 +- `p` paste after the current position +- `P` paste before the current position -### 合并 +### Merge -- `J` 将当前行与下一行合并 +- `J` merge the current line with the next line -> 尝试在下面的文本中进行复制粘贴练习 +> Try copying and pasting in the text below ``` -删除这一行 -粘贴到这一行下面 -剪切 ABC 并把它粘贴到 XYZ 前面,使这部分内容看起来像 -剪切 并把它粘贴到 ABC XYZ 前面。 +Delete this line +Paste below this line +Cut ABC and paste it in front of XYZ to make this part look like +Cut and paste it in front of ABC XYZ. ``` -### 替换 +### Replace -- `r` 将当前字符替换为 X -- `gu` 将指定的文本转换为小写 -- `gU` 将指定的文本转换为大写 -- `:%s///` 查找 search 内容并替换为 replace 内容 +- `r` replace the current character with X +- `gu` convert the specified text to lowercase +- `gU` convert the specified text to uppercase +- `:%s///` find the search content and replace it with the + replace content -> 尝试修改下列文本的大小写 +> Try changing the case of the following text ``` Change this line to UPPERCASE, THEN TO lowercase. ``` -> 还有个更好玩的命令 `g~`,先将光标定位到上面那行文本,执行 `0g~$` 看看发生了 -> 什么。 +> There is a more interesting command `g~`, first locate the cursor to the +> line of text above, execute `0g~$` to see what happened. -### 撤销、重做 +### Undo, Redo -- `u` 撤销 -- `Ctrl-r` 重做 +- `u` undo +- `Ctrl-r` redo -### 保存文件 +### Save file -- `:w` 保存当前文件 -- `:wa` 保存全部文件 -- `:wq` or `ZZ` 保存并退出 -- `:q!` or `ZQ` 强制退出,不保存 -- `:saveas ` 文件另存为 -- `:w ` 文件另存一份名为 `` 的副本并继续编辑原文件 +- `:w` save the current file +- `:wa` save all files +- `:wq` or `ZZ` save and exit +- `:q!` or `ZQ` force exit without saving +- `:saveas ` save the file as `` +- `:w ` save a copy of the file as `` and continue + editing the original file -> 你可以试着把当前(也许已经改得面目全非的)文件另存一份,然后继 -> 续[下一章](chapter04.md)的学习。 +> You can try to save the current (perhaps already changed beyond recognition) +> file as a copy, and then continue learning the [next chapter](chapter04.md). diff --git a/en/chapter04.md b/en/chapter04.md index b9a9c34..2b51f85 100644 --- a/en/chapter04.md +++ b/en/chapter04.md @@ -1,100 +1,119 @@ # Chapter 4: Some Tips -## 简单设置 Vim - -“工欲善其事,必先利其器”。尽管 Vim 非常强大,但默认配置的 Vim 看起来还是比较朴素的,为了适合 -我们的开发需求,要对 Vim 进行一些简单的配置。 - -- `:set number` 显示行号 -- `:set relativenumber` 显示相对行号(这个非常重要,慢慢体会) -- `:set hlsearch` 搜索结果高亮 -- `:set autoindent` 自动缩进 -- `:set smartindent` 智能缩进 -- `:set tabstop=4` 设置 tab 制表符所占宽度为 4 -- `:set softtabstop=4` 设置按 `tab` 时缩进的宽度为 4 -- `:set shiftwidth=4` 设置自动缩进宽度为 4 -- `:set expandtab` 缩进时将 tab 制表符转换为空格 -- `:filetype on` 开启文件类型检测 -- `:syntax on` 开启语法高亮 - -这里列出的是命令,你可以通过在 Vim 中输入进行设置,但这种方式设置的参数只在本次关闭 Vim 前生效, -如果你退出 Vim 再打开,之前的设置就失效了。 - -若要永久生效,需要修改 Vim 的一个自动配置文件,一般文件路径是 `/home//.vimrc`(Linux -系统)或 `/Users//.vimrc`(Mac OS 系统) - -如果没有就新建一个,以 Mac OS 系统为例: - -> 在控制台执行如下命令,每行结尾记得回车 +## Simple setup of Vim + +"Work well, must first sharpen his tools." Although Vim is very powerful, the +default configuration of Vim looks relatively simple. In order to meet our +development needs, we need to do some simple configuration to Vim. + +- `:set number` display line number +- `:set relativenumber` display relative line number (this is very important, + slowly experience) +- `:set hlsearch` search result highlight +- `:set autoindent` automatic indentation +- `:set smartindent` smart indentation +- `:set tabstop=4` set tab tab width to 4 +- `:set softtabstop=4` set the width of the indentation when pressing `tab` to 4 +- `:set shiftwidth=4` set the automatic indentation width to 4 +- `:set expandtab` indent tab to space +- `:filetype on` open file type detection +- `:syntax on` open syntax highlighting + +Here are the commands that you can use to set up Vim, but the parameters set in +this way only take effect before closing Vim this time. If you exit Vim and open +it again, the previous settings will be invalid. + +If you want to take effect permanently, you need to modify an automatic +configuration file of Vim. The general file path is `/home//.vimrc` (Linux +system) or `/Users//.vimrc` (Mac OS system) + +If not, create a new one. Take Mac OS system as an example: + +> Execute the following command in the console, remember to press Enter at the +> end of each line ```bash cd ~ vim .vimrc ``` -> 现在你已经在 Vim 中打开了你的 Vim 专属配置文件,将上面提到的配置复制到你的文件中,记得要删除 -> 每行开头的 `:` +> Now you have opened your Vim exclusive configuration file in Vim, copy the +> configuration mentioned above to your file, remember to delete the `:` at the +> beginning of each line > -> 修改完成执行 `:wq` 或者 `ZZ` 保存退出,再次进入 Vim 时,你的这些配置就已经生效了 +> After the modification is completed, execute `:wq` or `ZZ` to save and exit. +> When you enter Vim again, your configuration should take effect > -> 当然,机智如我也为你准备好了一份 [vimrc](vimrc.vim) 样本文件,你可以在控制台执行 -> `cp vimrc.vim ~/.vimrc` 直接使用,再次启动 Vim 或在 Vim 中执行 `:source ~/.vimrc`你的配置就 -> 应该生效了。 +> Of course, I have prepared a sample file [vimrc](vimrc.vim) for you. You can +> use it directly by executing `cp vimrc.vim ~/.vimrc`, and start Vim again or +> execute `:source ~/.vimrc` in Vim. Your configuration should take effect. -_**[ AD ]** 当然你也可以在我维护的另外一个项目 [The 7th Vim](https://github.com/dofy/7th-vim) 中找到一个更为完整的配置方案。_ +_**[AD]** Of course, you can also find a more complete configuration scheme in +another project maintained by me +[The 7th Vim](https://github.com/dofy/7th-vim)._ -## 清除搜索高亮 +### Clear search highlight -前面提到的配置中,有一项是高亮全部搜索结果 `:set hlsearch`,其作用是当你执行 `/` -、`?`、`*` 或 `#` 搜索后高亮所有匹配结果。 +In the configuration mentioned above, there is an option to highlight all search +results `:set hlsearch`, its function is when you execute `/`, `?`, `*` or `#` +search and highlight all matching results. -> 如果你已经设置了这个选项,尝试执行 `/set` +> If you have set this option, try executing `/set` -看到效果了吧,搜索结果一目了然,但这有时候也是一种困扰,因为知道搜索结果后高亮就没用了,但高亮 -本人并不这样认为,它会一直高亮下去,直到你用 `:set nohlsearch` 将其关闭。 +See the effect, the search results are clear at a glance, but this is sometimes +a kind of trouble, because the highlight does not think so, it will always +highlight, until you use `:set nohlsearch` to turn it off. -但这样需要就打开,不需要就关闭也不是个办法,有没有更好的解决方案呢?当然!请看下面的终极答案: +But this requires you to turn it on when you need it, and turn it off when you +don't need it. Is there a better solution? of course! See the ultimate answer +below: -> **再搜一个不存在的字符串** +> **Search for a string that does not exist** -通常我用来清除搜索高亮的命令是 `/lfw`,一是因为 `lfw` 这个组合一般不会出现(不适用于 -本文档...),二是这三个字母的组合按起来比较舒服,手指基本不需要怎么移动(你感受一下)。 +Usually I use the command `/lfw` to clear the search highlight. One is because +the combination of `lfw` is generally not available (not applicable to this +document...), and the other is that the combination of these three letters is +more comfortable to press, and the fingers basically do not need to move (you +feel it). -## 重复上一次命令 +## Repeat the last command -Vim 有一个特殊的命令 `.`,你可以用它重复执行上一个命令。 +Vim has a special command `.`, you can use it to repeat the last command. -> 按下面的说明进行操作 +> Follow the instructions below to operate ``` -按 dd 删除本行 -按 . 重复删除操作 -2. 再删除两行 -这行也没了 -p 把刚才删掉的粘回来 -3. 又多出 6 行 +Press dd to delete this line +Press . to repeat the delete operation +Press 2. to delete two more lines +This line is gone +Press p to paste it back +Press 3. to add 6 more lines ``` -## 缩进 +## Indentation -- `>>` 向右缩进当前行 -- `<<` 向左缩进当前行 +- `>>` indent the current line to the right +- `<<` indent the current line to the left -> 在这一行上依次按 `3>>`,`<<` 和 ` On this line, press `3>>`, `<<` and ` -> 打酱油行 +> Go to the soy sauce line -## 自动排版 +## Automatic typesetting -- `==` 自动排版当前行 -- `gg=G` 当前文档全文自动排版 -- `==` 对从当前行开始的 N 行进行自动排版 -- `=j` 对当前行以及向下 N 行进行自动排版 -- `=k` 对当前行以及向上 N 行进行自动排版 +- `==` automatic typesetting of the current line +- `gg=G` automatic typesetting of the current document +- `==` automatic typesetting for N lines starting from the current line +- `=j` automatic typesetting for the current line and N lines below +- `=k` automatic typesetting for the current line and N lines above -> 另外,还可以利用[第二章](chapter02.md)中提到的匹配搜索对代码块进行批量排版,尝试用 -> `gf` 命令打开 [chapter04-demo.js](chapter04-demo.js) 按照里面的说明进行操作 +> In addition, you can also use the matching search mentioned in +> [Chapter 2](chapter02.md) to batch typeset the code block. Try using the `gf` +> command to open [chapter04-demo.js](chapter04-demo.js) according to the +> instructions in it. -如果智能缩进设置生效了,执行后会看到如[第二章](chapter02.md)中一样的排版效果。 +If the smart indentation setting takes effect, you will see the same typesetting +effect as in [Chapter 2](chapter02.md). -[下一章](chapter05.md)将介绍分屏和标签页。 +The [next Chapter](chapter05.md) will introduce split screen and tab page. diff --git a/en/chapter05.md b/en/chapter05.md index 6ffb60d..0fb6600 100644 --- a/en/chapter05.md +++ b/en/chapter05.md @@ -1,70 +1,83 @@ # Chapter 5: Splitting Windows and Tabs -## 窗口分屏 +## Splitting Windows and Tabs -工作中经常会遇到这种情况,就是需要参照其他文档编辑当前文档(场景:翻译),或者从另外一个文档 -copy 代码到当前文档(场景:复制 html 元素类名到 css 文档),这时候就是你最需要分屏的时候。 +You will often encounter situations where you need to edit the current document +with reference to another document (scenario: translation), or copy code from +another document to the current document (scenario: copying html element class +names to a css document). copy code from another document to the current +document (scenario: copying html element class names to a css document), this is +when you need to split the screen the most. -### 分屏方式 +### Splitting -- `:split` 缩写 `:sp` or `Ctrl-w s` 上下分屏 -- `:vsplit` 缩写 `:vs` or `Ctrl-w v` 左右分屏 -- `:diffsplit` 缩写 `:diffs` diff 模式打开一个分屏,后面可以加上 {filename} +- `:split` abbreviation `:sp` or `Ctrl-w s` split up and down. +- `:vsplit` Abbreviation `:vs` or `Ctrl-w v` Split left and right. +- `:diffsplit` Abbreviation `:diffs` Diff mode opens a split screen and can be + followed by {filename}. -### 窗口跳转 +### Window jumping -- `Ctrl-w w` 激活下一个窗口 -- `Ctrl-w j` 激活下方窗口 -- `Ctrl-w k` 激活上方窗口 -- `Ctrl-w h` 激活左侧窗口 -- `Ctrl-w l` 激活右侧窗口 +- `Ctrl-w w` Activate next window. +- `Ctrl-w j` Activates the next window. +- `Ctrl-w k` Activate the upper window. +- `Ctrl-w h` Activate left window +- `Ctrl-w l` activates the right window -### 移动分屏 +### Move split screen -- `Ctrl-w L` 移动到最右侧 -- `Ctrl-w H` 移动到最左侧 -- `Ctrl-w K` 移动到顶部 -- `Ctrl-w J` 移动到底部 +- `Ctrl-w l` Moves to rightmost window +- `Ctrl-w H` Moves to the leftmost side. +- `Ctrl-w K` Move to the top +- `Ctrl-w J` Move to the bottom -_注意:区分大小写。另外,可以将底部的屏幕移动到右侧,实现上下分屏到左右分屏的转换。_ +_Note: Case sensitive. Alternatively, you can move the bottom screen to the +right side for a top/bottom to left/right split screen conversion. _ -### 屏幕缩放 +### Screen zoom -- `Ctrl-w =` 平均窗口尺寸 -- `Ctrl-w +` 增加高度 -- `Ctrl-w -` 缩减高度 -- `Ctrl-w _` 最大高度 -- `Ctrl-w >` 增加宽度 -- `Ctrl-w <` 缩减宽度 -- `Ctrl-w |` 最大宽度 +- `Ctrl-w =` Average window size +- `Ctrl-w +` Increase height +- `Ctrl-w -` Reduce height +- `Ctrl-w _` Maximum height +- `Ctrl-w >` Increase width +- `Ctrl-w <` Reduce width +- `Ctrl-w |` Maximum width -> 实践!实践!实践! +> Practice! Practice! Practice! -## 标签页 +## Tagged pages -[第二章](chapter02.md)中提到过的 buffer 和刚刚讲到的分屏操作都很适合在少量文件之间进行切换, -文件超过 3 个我觉得就不方便了,而标签页则更适合多文件之间的切换。 +The buffer mentioned in [Chapter 2](chapter02.md) and the split-screen operation +just mentioned are good for switching between a small number of files. I don't +think it's convenient to have more than 3 files, but tabs are better for +switching between multiple files. -### 创建标签页 +### Create a tab -- `:tabnew` or `:tabedit` 缩写 `:tabe` 打开新标签页 -- `Ctrl-w gf` 在新标签页中打开当前光标所在位置的文件名 +- `:tabnew` or `:tabedit` abbreviation `:tabe` opens a new tab. +- `Ctrl-w gf` opens a new tab with the name of the file at the current cursor + position -_注意:`:tabnew` 和 `:tabedit` 后面都可以跟一个 <空格><文件名> 用以在新标签页中 -打开指定文件,还可以在 `:` 后面加一个数字,指出新标签页在列表中的位置(从 0 开始)。_ +Note: Both `:tabnew` and `:tabedit` can be followed by a to +open the specified file in a new tab. to open the specified file in a new tab, +and `:` can be followed by a number indicating the position of the new tab in +the list (starting from 0). \_ -### 切换标签页 +### Switch tabs -- `gt` or `:tabnext` 缩写 `:tabn` 下一个标签页(最后一个会循环到第一个) -- `gT` or `:tabprevious` 缩写 `:tabp` 上一个标签页(第一个会循环到最后一个) -- `:tabrewind` 缩写 `:tabr` or `:tabfirst` 缩写 `:tabfir` 到第一个 -- `:tablast` 缩写 `:tabl` 到最后一个标签页 +- `gt` or `:tabnext` Abbreviation `:tabn` Next tab (last one loops to first) +- `gT` or `:tabprevious` Abbreviation `:tabp` Previous tab (first one loops to + last) +- `:tabrewind` abbreviation `:tabr` or `:tabfirst` abbreviation `:tabfir` to the + first one +- `:tablast` abbreviation `:tabl` to the last tab -### 关闭标签页 +### Close a tab. -- `:tabclose` 缩写 `:tabc` 关闭当前标签页 -- `:-tabc` 关闭上一个标签页 -- `:+tabc` 关闭下一个标签页 -- `:tabonly` 缩写 `:tabo` 关闭其他标签页 +- `:tabclose` Abbreviation `:tabc` to close the current tab +- `:-tabc` Close previous tab +- `:+tabc` Close the next tab +- `:tabonly` abbreviation `:tabo` close other tabs -[下一章](chapter06.md)将介绍块操作。 +The [next chapter](chapter06.md) will cover block operations. diff --git a/en/chapter06.md b/en/chapter06.md index 673a578..47ebb80 100644 --- a/en/chapter06.md +++ b/en/chapter06.md @@ -1,39 +1,48 @@ # Chapter 6: Block Operations -我们经常会遇到这种情况:某处有一个多行文本,我们要把他复制到代码中用来初始化一个 -数组。 大部分时候我们会这么做: +We often come across a situation where we have a multi-line text somewhere and +we want to copy it into our code to initialize an array of array. Most of the +time we do this: -- 写好数组声明; -- 把内容复制到中括号内(大概长成下面那段文本的样子) -- 然后行首加 `'` 行尾加 `',`,重复直到最后一行(想象一下这段文本有 50 行) +- Write the array declaration; +- copy the contents into parentheses (roughly the length of the text below) +- Then add `'` at the beginning of the line, `',` at the end of the line, and + repeat until the last line (imagine 50 lines of text). -> 有了 Vim 块操作就不用这么麻烦了,按 `014gg`,然后跟着选中那一行的指示操作。 +> With Vim, you don't have to do this, just press `014gg` and follow the +> instructions for the selected line. ```javascript -var myArray = [ -Ctrl-v 进入块操作,$ 到行尾,j 到下一行(做!)。 -按 j 到下一行 -下面还好多行,干脆来个 4j 多跳几行 +const myArray = [ +Ctrl-v to enter block operation, $ to the end of the line, j to the next line (do it!). +Press j to the next line +There are many lines below, so let's jump a few more lines with 4j https://www.yahaha.net https://www.yahaha.net -以后看好行号再跳!现在按 A 插入,然后输入 <单引号><逗号> 完成第一步。 -// Oops... 跳多了,没事,按 k 回到上一行 +Look at the line number later and jump! Now press A to insert, then enter to complete the first step. +// Oops... Jump too much, no problem, press k to go back to the previous line ]; ``` -> 现在已经完成了第一步,还需要补前面的 `'`,按 `14gg` 回到那一行,再操作一次,但 -> 是这次有三个地方要变化一下: +> Now that you've completed the first step, you still need to make up the +> previous `'`, press `17gg` to go back to that line and do it again, but but +> this time there are three things to change: > -> 1. 第一行按 `$` 时改按 `0`,因为这次要在行首插入; -> 1. 末行按 `A` 时改按 `I`,块操作中 `A` 是字符后插入, `I` 是字符前插入; -> 1. 最后按 `<单引号>`。 +> 1. +> 1. press `0` when you press `$` on the first line, because this time you want +> to insert at the beginning of the line. > 1. press `0` at the end of the +> line; +> 1. when pressing `A` at the end of the line, press `I` instead, because in +> block operations `A` is inserted after the character, and `I` is inserted +> before the character; +> 1. press `` at the end. > -> 最后再做些收尾工作,`19gg$x` 删掉最后一行结尾处的 `,`,然后 `14gg7==` 把代码缩 -> 进一下。 +> Finally, to finish up, `22gg$x` deletes `,` at the end of the last line, and +> then `17gg7==` indents the code > a bit. indent the code a bit. > > Done! -_注意:选择行首行尾的操作也可以在选择完要处理的内容之后执行,即 -`Ctrl-v jjj$A',`_ +_Note: Selecting the beginning and end of a line can also be done after +selecting what to work with, i.e. `Ctrl-v jjj$A',`_ -接下来我们说说 [Vim 中的宏](chapter07.md)。 +Next we talk about [macros in Vim](chapter07.md).