translated

This commit is contained in:
geekpi 2022-03-02 09:51:20 +08:00
parent f44d182994
commit 4175f47883
2 changed files with 106 additions and 107 deletions

View File

@ -1,107 +0,0 @@
[#]: subject: "4 Vim features to use to improve productivity"
[#]: via: "https://opensource.com/article/22/3/vim-features-productivity"
[#]: author: "Hunter Coleman https://opensource.com/users/hunterc"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
4 Vim features to use to improve productivity
======
Vim has so many tricks up its sleeve that even people who have used it
for years can still learn new things.
![Person using a laptop][1]
There's always Vim. Vim is one of the most popular text editors in use today. This is in large part because it's available everywhere. When you SSH into another system, you may not find [Emacs][2], [Nano][3], or [VSCodium][4] installed, but you can rest assured that Vim is there for you. 
In this article, I cover some intermediate things that you can do with Vim to speed up your workflow and generally make your day easier. This article assumes that you have used Vim before, already know the editor's basics, and are looking to take your Vim skills up a notch. Vim is full of useful tricks, and no one ever truly masters it, but the five tips in this article can boost your skills and, hopefully, make you fall just a bit more in love with one of the most popular and loved text editors.
### Vim bookmarks
Vim provides an easy way to add bookmarks to your text. Suppose that you are editing a large file, and your current edit session requires you to jump back and forth between two sections of text in different locations within the file. 
First, you set a bookmark to your current location by typing `m` (for mark) and then give it a name. For example, if the file I'm editing has a list of names in it that I will want to jump back to later, I could use `mn` (n for names) to add a bookmark to that part of the file. 
Later, I have two options when editing another part of the file and wish to jump back to that list of names. I can type ``n` (backtick-n) to go to the bookmark's location, or I can type `'n` (single quote-n) to go to the beginning of the line that the bookmark is on.
When I no longer need the bookmark, I can delete it with `:delmarks n`. And `:marks` shows me all of my bookmarks.
Notice above that I use a lowercase letter to name my bookmark. This was deliberate. You use lowercase letters for local bookmarks and capital letters to make a bookmark global across several files.
### Vim user-defined abbreviations
If the text you are working on has a long word or phrase that appears several times, then typing it out in full each time could quickly grow irritating. Luckily, Vim provides a simple way to create abbreviations. 
To set a user-defined abbreviation for _Acme Painted Fake Roadways, Inc._ to _apfr_, you type `:ab apfr Acme Painted Fake Roadways, Inc.` Now, when in edit mode, and you type the letters _apfr_ followed by a space, _apfr_ gets converted to _Acme Painted Fake Roadways, Inc._
Any abbreviations you set with `:ab` get lost when you close your Vim session. If you want to unset the abbreviation before then, you can simply type `:una apfr`.
### Vim autocomplete
Many people don't realize that Vim comes with an autocomplete feature. If you are typing a long word you used before in the file, this is a handy tool. 
Suppose you are writing an article that uses the word _Antarctica_ multiple times. After you have used it once, the next time you can type just the first few letters. For example, you type _Ant_ and then use **Ctrl+P**. Vim either completes the word (if there is only one option that it could be) or provides you with a list of words that you can select with the arrow keys—keep typing to narrow down the search further and use the **Tab** key to select the word. 
### Vim range selection
With Vim, you can easily perform an action on a range of lines in your file. You indicate ranges by a starting line number, a comma, and an ending line number (inclusive). In addition to literal line numbers, you can use a period (`.`) to represent the current line, a dollar sign (`$`) to represent the last line in the file buffer, and a percent sign (`%`) to represent the entire file.
Here are a few examples for clarification.
If you want to delete lines 2 through 10, then type (in command mode):
```
`:2,10d`
```
To delete every line from line 25 to the end of the file:
```
`:25,$d`
```
You can delete every line with:
```
`:%d`
```
To copy (or transfer) lines 5 through 10 to just after line 15:
```
`:5,10t 15`
```
To move lines 5 through 10 to just after line 15 (instead of copying):
```
`:5,10m 15`
```
### Vim for productivity
I hope this article has taught you something new about the Vim text editor. Vim has so many tricks up its sleeve that even people who have used it for years can still learn new things. There is always something new and useful to learn.
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/3/vim-features-productivity
作者:[Hunter Coleman][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/hunterc
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/laptop_screen_desk_work_chat_text.png?itok=UXqIDRDD (Person using a laptop)
[2]: https://opensource.com/article/20/3/getting-started-emacs
[3]: https://opensource.com/article/20/12/gnu-nano
[4]: https://opensource.com/article/20/6/open-source-alternatives-vs-code

View File

@ -0,0 +1,106 @@
[#]: subject: "4 Vim features to use to improve productivity"
[#]: via: "https://opensource.com/article/22/3/vim-features-productivity"
[#]: author: "Hunter Coleman https://opensource.com/users/hunterc"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
4 个用于提高生产力的 Vim 功能
======
Vim 有很多技巧,即使是用过它很多年的人仍然可以学习新东西。
![Person using a laptop][1]
总是有 Vim。 Vim 是当今最流行的文本编辑器之一。这在很大程度上是因为它随处可见。当你通过 SSH 连接到另一个系统时,你可能找不到 [Emacs][2]、[Nano][3] 或 [VSCodium][4]但你可以放心Vim 就在那里。
在本文中,我介绍了一些你可以用 Vim 做的中级事情,以加快你的工作流程并通常让你的一天更轻松。本文假设你以前使用过 Vim已经了解编辑器的基础知识并希望将你的 Vim 技能提高一个档次。 Vim 充满了有用的技巧,没有人真正掌握它,但本文中的五个技巧可以提高你的技能,并希望让你更加爱上最受欢迎和喜爱的文本编辑器之一。
### Vim 书签
Vim 提供了一种在文本中添加书签的简单方法。假设你正在编辑一个大文件,并且当前的编辑会话要求你在文件中不同位置的两段文本之间来回跳转。
首先,你输入 `m`(用于标记)为当前位置设置一个书签,然后为其命名。例如,如果我正在编辑的文件中有一个名称列表,我想稍后再跳回,我可以使用 `mn`n 表示名称)为文件的该部分添加书签。
稍后,在编辑文件的另一部分并希望跳回该名称列表时,我有两个选项。我可以输入 \``n`(反引号 n转到书签的位置或者我可以键入 `'n`(单引号 n转到书签所在行的开头。
当我不再需要书签时,我可以使用 `:delmarks n` 将其删除。 `:marks` 会显示我所有的书签。
请注意,我使用小写字母来命名我的书签。这是故意的。你可以使用小写字母作为本地书签,使用大写字母来使书签在多个文件中具有全局性。
### Vim 用户定义的缩写
如果你正在处理的文本有一个长词或短语多次出现那么每次都完整地输入它会很快变得烦人。幸运的是Vim 提供了一种创建缩写的简单方法。
要将 _Acme Painted Fake Roadways, Inc._ 的用户定义缩写设置为 _apfr_ 你需要输入 `:ab apfr Acme Painted Fake Roadways, Inc.`。现在当在编辑模式时,当你在输入 _apfr_ 后面更上空格,就会变成 _Acme Painted Fake Roadways, Inc._
当你关闭 Vim 会话时,你使用 `:ab` 设置的任何缩写都会丢失。如果你想在此之前取消设置缩写,你可输入 `:una apfr`
### Vim 自动补全
许多人没有意识到 Vim 带有自动补全功能。如果你在文件中输入以前使用过的长词,这是一个方便的工具。
假设你正在撰写一篇文章,多次使用 _Antarctica_ 一词。使用一次后,下次你可以只输入前几个字母。例如,你输入 _Ant_ 然后使用 **Ctrl+P**。 Vim 要么补全单词(如果只有一个选项),要么为你提供可以用箭头键选择的单词列表,继续输入以进一步缩小搜索范围并使用 **Tab** 键选择单词。
### Vim 范围选择
使用 Vim你可以轻松地对文件中的一系列行执行操作。你可以通过起始行号、逗号和结束行号包括来指示范围。除了文字行号之外你还可以使用句点`.`)表示当前行,使用美元符号 `$` 表示文件缓冲区中的最后一行,以及使用百分号(`%`)表示整个文件。
这里举几个例子来说明。
如果要删除第 2 到 10 行,请输入(在命令模式下):
```
`:2,10d`
```
要删除从第 25 行到文件末尾的每一行:
```
`:25,$d`
```
你可以使用以下命令删除每一行:
```
`:%d`
```
要将第 5 到 10 行复制(或转移)到第 15 行之后:
```
`:5,10t 15`
```
要将第 5 行到第 10 行移动到第 15 行之后(而不是复制):
```
`:5,10m 15`
```
### Vim 提高生产力
我希望这篇文章教会了你一些关于 Vim 文本编辑器的新知识。 Vim 有很多技巧,即使是使用了多年的人仍然可以学习新事物。总有一些新的和有用的东西可以学习。
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/3/vim-features-productivity
作者:[Hunter Coleman][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/hunterc
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/laptop_screen_desk_work_chat_text.png?itok=UXqIDRDD (Person using a laptop)
[2]: https://opensource.com/article/20/3/getting-started-emacs
[3]: https://opensource.com/article/20/12/gnu-nano
[4]: https://opensource.com/article/20/6/open-source-alternatives-vs-code