Getting to Black Belt in Vim – Part 4 – Blue Belt

Great work for coming this far! We covered a lot at green belt level.
At blue belt level, we’ll cover visual mode, a couple of advanced motions, searching and some more editing commands.

Blue Belt

Visual Mode

  • Type v to enter visual mode. Now, we can use any motion, such as “w” or “j” to highlight text. Once highlighted, we can perform an operation on it, such as copy (yy) or delete (d). Some examples:
    • Type v, then w to highlight from where the cursor is to the end of the word.
    • Type v, followed by $ to highlight from the cursor to the end of the line.
  • Type V to highlight the entire line.

We’ll see how to use visual mode with counts and motions later on.

Vertical Motions

  • Type gg to go to the top of the file, from anywhere in the file.
  • Type G to go to the bottom of the file, from anywhere in the file.

Searching

  • Type / (forward slash) followed by search term, type <Enter> to search forwards for a specific item. We can go to the next match by typing n, or previous match by typing N.
  • Type ? followed by search term, type <Enter> to search backwards. We can go to the next match by typing n, or previous match by typing N.

Horizontal Motions

  • f + <character> to move cursor to the first match.
  • F + <character> to move cursor backwards to the first match.
  • t + <character> to move cursor just before the first match.
  • T + <character> to move cursor backwards just before first match.
  • For all of the above commands, we can repeat the search by typing ; (semi colon). If we go past our target character, we can press , (comma) to go backwards.

Operator Count Motion

  • Certain commands are called operators, such as delete (d) or copy (y) or change (c). These work with counts and motions:
    • d5w – deletes 5 words.
    • V10j – highlight 10 lines below.
    • y4b – copy 4 words backwards from cursor.
    • c2W – change 2 WORDS.

Useful Shortcuts

  • Type D to delete text from the cursor to the end of line. It’s the equivalent of typing d$.
  • Type C to cut text from the cursor to the end of line and go into insert mode. It’s the shortcut for typing c$.
  • Tap cc to cut a whole line, from wherever the cursor is on the line. It’s like typing 0D.

We can see how learning Vim is a lot like learning a language. Once we know the grammar, we can tell what we want Vim to do. In the next part, we’ll introduce a powerful concept.

Published
Categorized as Vim Tagged