- Mastering Vim
- Ruslan Osipov
- 422字
- 2021-06-10 18:51:26
Making simple edits in insert mode
When working with Vim, you usually want to spend as little time as possible in the insert mode (unless you're writing and not editing). Since most text operations involve editing, we'll focus on that.
You've already learned to enter the insert mode by pressing i. There are more ways to get to the insert mode. Often times you will want to change some piece of text for another one, and there's a command just for that c. The change command allows you to remove a portion of text and immediately enter an insert mode. Change is a compound command, meaning that it needs to be followed by a command which tells Vim what needs to be changed. You can combine it with any of the movement commands you've learned before. Here are some examples:

As you learn more complex movements commands, you can combine these with a change for quick and seamless editing. We'll also be covering a few plugins which will supercharge a change command to allow for even more powerful editing, like changing text within braces, or replacing the type of quotes on the go.
For example, if you wish to change farm = add_animal(farm, animal) to farm = add_animal(farm, creature), you can execute the following set of commands:

Sometimes we just want to cut things, without putting anything instead, and d does just that. It stands for delete. It behaves similarly to c, except that the behavior of w and e is more standard, as can be seen in the following example:

There are also two more nifty shortcuts which allow you to change or delete a whole line:

For example, look at the following piece:
By hitting dd you will completely remove a line, as demonstrated in the following example:
Hitting cc will clear the line and enter insert mode with the proper indent, as shown in the following example:
- C++程序設計教程
- DevOps with Kubernetes
- 基于Java技術的Web應用開發
- 深入淺出Windows API程序設計:編程基礎篇
- 精通網絡視頻核心開發技術
- Building an RPG with Unity 2018
- Hands-On JavaScript for Python Developers
- Red Hat Enterprise Linux Troubleshooting Guide
- Everyday Data Structures
- 區塊鏈國產化實踐指南:基于Fabric 2.0
- Instant Automapper
- 3D Printing Designs:The Sun Puzzle
- Oracle SOA Suite 12c Administrator's Guide
- Scratch超人漫游記:創意程序設計:STEAM創新教育指南
- Python編程基礎與數據分析