How To: VIM, Using the Normal Mode Part 2

VIM, Using the Normal Mode Part 2

Hello there Nullbyters,

Last tutorial we discussed navigating and setting some options.

Today we will be discussing searching, copy/cut & paste and some quick editing techniques.

Important:
Use u to undo changes.
Use Ctrl + r to re-do changes.

Searching

First make sure you are in Normal Mode.
Now to navigate simply type / and then the word you want to search and press Enter.
To go to the next result, press n.
To go to the previous result (it loops), press N, (Shift + n).
Once again, you can combine this with integers to go to the n'th next result (for example tap 5 then n).

To quickly search the word that is under your cursor, press:
Aterisk (bounded).
g Aterisk (unbounded).
And then once again n and N to go the different results.

Copy, Cut and Paste

To Copy or Cut a piece of text in VIM you need to first select what you want to Copy / Cut.

To select (multiple) line(s), press V (Shift+v).
You'll see the line your cursor had selected get highlighted.
To select multiple lines, simply navigate downwards. (TIP: use an integer/navigation combo).

Once you've selected the lines of text you want to Copy/Cut press d to cut (d is for delete), or y to copy (y is for yank).

Now navigate to where you want to paste the lines and press P to paste it 'before' your cursor and p after the cursor (p will create a new-line if you're on an empty line, whereas P won't).

To select a piece of text, place your cursor on the beginning and press v, from here you can use the navigation (TIP: integers ;p ) to select your text.

Once again d to cut, y to copy and p/P to paste.

Some Tips and Tricks

  • Editing something in (), {}, Brackets (Goddamnit).

Navigate your cursor on the (, { or BRACKETOPEN ( ... ).
Now press c, i, ( (or { or BRACKETOPEN).
To simply delete what's in it replace c with d.
Think of it as change in (), that way the commands will be easier to remember.

  • Move to the n'th letter 'a' (this can be any letter).

For example move to 4th letter 'o' type:
4, f, o

Alright that will be it for today.

One important thing I would like to add is the importance of switching back and forth to Normal Mode. These techniques are useless if you keep spamming backspace and the arrow keys.

Personally I mapped Esc to the Caps Lock key, since I never use it. Alternatively there is a second way to go to Normal Mode using Ctrl+{.

Just updated your iPhone? You'll find new emoji, enhanced security, podcast transcripts, Apple Cash virtual numbers, and other useful features. There are even new additions hidden within Safari. Find out what's new and changed on your iPhone with the iOS 17.4 update.

1 Comment

You may also mention the block mode selection (CTRL+V)... that is pretty useful when dealing with data files

If you want to copy full lines there is no need to select the text. Just type the number of lines you want to copy and then press y.

Good work!

Share Your Thoughts

  • Hot
  • Latest