How To: VIM, Using the Normal Mode Part 1

VIM, Using the Normal Mode Part 1

Hello there Nullbytes,

In my previous tutorial found here,
https://null-byte.wonderhowto.com/how-to/vim-as-ugly-as-is-fast-0168012/,
I wrote about using normal mode.

Today we will go trough the basics of using the Normal Mode.
The things we will be discussing:

  • Making VIM more sublime
  • Navigation

The point of todays tutorial is to get you to the point where you are faster using VIM than when using Gedit or Nano.
Note that VIM has a LOT more potential.

First we need to make sure we are in Normal Mode, press Esc to do so if you are in Insert Mode.

Making VIM More Sublime

When you go straight to Insert Mode in VIM to write your code, you'll notice it doesn't auto-indent or highlight syntax.

Luckily there is a way to include these options (and a lot more as well).

To set auto-indent in VIM, first, be sure that you are in Normal Mode and then type: :set autoindent, or if you are coding C or C++

:set cindent.

To highlight syntax simply type: :syntax on.

To set numbers type: :set number.

Navigation

There are a few ways to navigate in VIM:

  1. Using the arrow keys (bad habit)
  2. Using h, j, k and l
  3. Alternative options

We will be using h, j, k and l because of the positions of our hands and the fact that there are cool tricks to them.

To navigate using h, j, k and l:

  • h for left
  • j for down
  • k for up
  • l for right

Now when constantly tapping j or k to navigate, this starts to feel very inefficient.
Whenever something feels inefficient in VIM, believe me when I say:
There is a better way to do it.

Instead of tapping 'j' 5 times, tap '5' then 'j'.
This can be done with any integer.

Another way to navigate is to navigate trough words instead of single characters.

  • To navigate to the first letter of the next word, press w
  • To navigate backwards, press b
  • To navigate to the last letter of the next word, press e

Note that again you can combine this with integers.
So to navigate 2 words press '2', then 'w'.
Same for 'b' and 'e'.

That will be it for today, I've decided to make this a serie.
Next tutorial we will be discussing search, copy & past, and a few other tricks.

Feel free to post feedback, I know there is a LOT LOT LOT LOT that I've not included here, but I want to stick with the basics first and later the more 'advanced' features of VIM.

P.s. VIM has a built in help manual that is really well written.
To use it, type: :help

Just updated your iPhone? You'll find new features for TV, Messages, News, and Shortcuts, as well as important bug fixes and security patches. Find out what's new and changed on your iPhone with the iOS 17.6 update.

Be the First to Comment

Share Your Thoughts

  • Hot
  • Latest