Using Numbers with Commands in vi Editor

Using Numbers with Commands in vi Editor

Vi is one of the most powerful text editors available to the programmer today. It comes with a number of features and is highly flexible. This is what makes it such a powerful programming tool. vi comes installed by default on a number of Linux distributions. If you are using a mainstream distribution, you already have it installed. You can always install it by following instructions specific to your Linux distribution.

In vi, you can precede most vi commands with numbers to have the command repeated that number of times. Putting a number in front of the command will run the command those number of times. This comes very handy while dealing with several lines, words, or characters at a time.

Here are some examples that show how to use numbers with commands in the vi editor:

* 3dw — This will delete the next three words.

* 5cl — This will change the next five letters. That is, this will remove the letters and enters input mode.

* 12j — This will move down 12 lines.

Putting a number in front on most commands just repeats those commands the number of times specified.

If you would like further instructions, I suggest you try the VIM Tutor by running the vimtutor command.

Note: When you invoke vi on most Linux distros, you are actually invoking the vim text editor, which runs in vi compatibility mode. vim is an improvised version of vi. In other words, it is vi with a lot of bells and whistles.

Programmers and Linux geeks usually prefer vim over viĀ  because comes with color coding. vim also comes with other useful features such as the ability to open a document with the cursor at the same place where it was when you last exited that file.

If you are using Windows, you can still use vi editor on your system. There are two ways to do this–you can either install CygWin or use gvim (a Windows port is available).

Subscribe / Share

Article by Admin

Authors bio is coming up shortly. Admin tagged this post with: , , , , , , , , Read 515 articles by Admin
It's very calm over here, why not leave a comment?

Leave a Reply

You must be logged in to post a comment.