Open In App

Which are the four navigation keys in vi

Last Updated : 25 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will cover how to efficiently navigate in the vi editor along with the basic four navigation keys we will look into some additional navigation keys to navigate seamlessly within the vi editor. First, we look at what Linux and VI editors and why we use them, what are its features and how can we use them.

Linux

Linux was developed by Linus Torvalds in 1991 as a hobby project. It is an open-source (source code that can be used by anyone freely) kernel that is most popular and widely used in the industry as well as in personal systems. There are various operating systems based on Linux kernel, some of the popular Linux distributions are Ubuntu, Cent OS, Red Hat, Debian, and Kali Linux.

VI Editor

Vi Editor is a widely used text editor in Unix/Linux systems and is known for its efficiency and flexibility. Vi editor was developed in 1976 by Bill Joy and later in 1991, an improved version of Vi editor was released which is known as VI IMproved (VIM). There are two modes in Vi Editor:

  • Insert Mode
  • Command Mode

Navigation in Vi Editor

Vi editor provides a lot to commands/keys to navigates seamlessly within the editor but you must have to be in the command mode to navigate, to enter in command mode if you are in insert mode press Esc.

Basic 4 navigation keys

There are four basic navigation keys in vi editor to navigate in cardinal directions (up/down/left/right) which are as follow:

Key

Description

k

Moves the cursor up one line

j

Moves the cursor down one line

h

 Moves the cursor to the left one-character position.

l

 Moves the cursor to the right one-character position.

Examples:

We have discussed about the basic four navigation keys to move the cursor in four cardinal directions we have attached screenshots for each navigation key to demonstrate its moves:

1. To move cursor one line up (k)

up_merged

2. To move cursor one line down (j)

down_merged

3. To move cursor one character left (h)

left_merged

4. To move cursor one character right (l)

right_merged

Additional Navigation Keys

Apart from the basic navigation keys vi editor provides a lot commands/keys to navigate which are as follows:

Key

Description

0

Positions cursor at beginning of line

$

Positions cursor at end of line

W

Positions cursor to the next word

B

Positions cursor to previous work

(

Positions cursor to beginning of current sentence

)

Positions cursor to beginning of next sentence

H

Move to top of screen

nH

Moves to nth line from the top of the screen

M

Move to middle of screen

L

Move to bottom of screen

nL

Moves to nth line from the bottom of the screen

Colon followed by a number position

The cursor on the line number is represented by the number after the colon. For example, “:10” positions the cursor on line 10

Basic Vi Editor Guide

1. Create/Edit a file using Vi editor

vi filename

2. Insert Mode

To make any changes in the file first you need to enter in the insert mode to modify the file. To get into insert mode press button ‘i’ to enter in insert mode.

3. Command Mode

To run any command in the vi editor you have to first enter in the command mode if you are currently in the insert mode then press Esc and then ‘:’ colon followed by your command to run your command in the editor.

Conclusion

In this article we have covered how to effectively navigate in the vi editor using basic four navigation keys and additional navigation keys along with an example, later we discuss a basic vi editor guide. If you want to deep dive into vi editor you can checkout this GFG article.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads