Want to see the full-length video right now for free?Sign In with GitHub for Free Access
Vim is a "modal" editor meaning it has various modes which change its behavior in response to your key presses. This is in contrast to a more traditional modeless editor where each key combination always triggers the same behavior.
This modal nature is at the core of Vim's power and it is important to understand it in order to most efficiently use Vim.
Insert mode is the mode most similar to other editors' only "mode". In insert mode, characters appear immediately in the buffer as you type them. While you might expect this to be the default mode in Vim as well, Vim instead chooses to prioritize moving through a file and making targeted edits which are done in "normal mode".
Normal mode is named as such since it is the default mode Vim starts in, and the mode you are expected to be in the majority of the time.
In normal mode, each key is mapped to an operation or motion. This fits with the idea that as developers and designers, we actually spend the majority of our time moving and editing within a document, rather than simply adding long blocks of text.
You should try very hard to avoid the following:
Enter visual mode by pressing
v in normal mode. From there, you can move the
cursor using all the normal motions and Vim will highlight from where you
started to where you move the cursor. You can use a number of keys such as
c to operate on the visual selection similar to how these keys would
operate in normal mode.
Visual mode is a great tool when you are first learning the motions and text objects as it allows you to visually confirm the text you have targeted before operating.
That said, we recommend trying to move away from visual mode over time as comfort with text objects increases. Nearly any text you want to operate on can be targeted directly with a text object more-effeciently than a visual selection.
There are two main reasons to avoid visual mode:
viwd(visually select inner word, then delete) can be performed directly as
>ipwill indent any paragraph, and can be repeated with
.from anywhere in any Vim paragraph.
vip>will not repeat.
Occasionally visual mode is useful even to master Vimmers to target an odd range of characters that don't map to an existing text-object, but this should be considered a smell and avoided as much as possible.
Visual line mode operates on entire lines at a time. It can be started with
from normal mode. As discussed above, we recommend avoiding standard visual
mode, and we recommend that even more strongly for visual line mode. All the
caveats above still apply, but to an even greater extent. If you find yourself
using visual line mode, consider one of these alternatives instead:
d2j(delete down two lines)
4dd(4 times, delete line)
d25G(delete to line 25)
dap(delete inner-paragraph or "a-paragraph")
Visual block mode allows for selecting a column of text. Unlike standard (aka characterwise) and linewise visual mode, visual block mode is likely the best tool for certain jobs and we recommend using it. Some ideal use cases for visual block mode are editing a git rebase summary
Visual block mode can be started with
<C-v> from normal mode. Once started,
use normal mode motions to move the highlight region.
Visual block mode uses similar mappings to normal mode, but not identical. The following is a list of the common visual block operations and their mapping:
||Delete the visual block selection|
||Replace all characters in the block with the next character you type|
||Insert text before the block|
||Insert text after the block|
Note - When you change or add text, Vim will only show the change for the
first line of the block, but will then replicate to all lines after you
complete the change / insertion and hit
If you only take one thing from this video, let it be this: Normal mode is your friend!
Try to stay in normal mode as much as possible and you'll be fine.