vim

How to use arrow keys for scrolling in VIM?

Vim stands for “Vi improved.” It is a commendable text editor for Linux and Unix-like operating systems. It provides several improvements over vi, including syntax highlighting, multi-level undo, command-line editing, multiple buffers and windows, filename completion, visual selection, a comprehensive support system, and more.

Primary modes of vim

  1. Insert mode: vim user can utilize its insert mode for inserting and editing text into a file.
  2. Command mode: The commands are typed with “:” as a starting symbol. In command mode, the input command performs specific functions. The command mode also allows you to copy, paste, undo, redo, delete text and move around in the file.

Switching from one mode to another

To switch from insert mode to command mode, you have to press the escapeEsc” key.

Vim installation command:
Execute the below-given commands for installing Vim editor if you don’t have it already.

$ sudo apt search vim
$ sudo apt install vim

Using arrow keys for scrolling in vim

Bill Joy” used the ADM-3A terminal for creating the vi text editor. The hjkl keys on the ADM-3A terminal already have arrows. That’s why he used the same keys to move around in the vi text editor. Here is a picture of how hjkl looked in the ADM-3A terminal.

The vim editor is derived from vi. It also utilizes the same hjkl keys to replace the functionality of arrow keys. Among vim users, hjkl keys are preferred and advantageous to use. You never have to leave the first row, allowing you to be speedier while working in vim editor. In addition, someone who has already dealt with wrist pain does not have to shift his hands to arrow keys, which is a great relief for them.

Now let us show you how the hjkl keys work as same as arrow keys in vim editor. For that, firstly, we will create a sample file using the vim command.

$ vim sample.txt

In vim editor, for inserting text in this “sample.txt” file, we will switch to the Insert mode by pressing “i.”

We have added some text to this file.

Press “ESC” to switch back to the command mode, then type “😡” to save the file.

Now you are using vim editor in command mode. Use the hjkl in the following manner:

    ^

    k

< h    l >

    j

    v
  • For moving left, press h.
  • For moving right, press l.
  • To scroll down, press j.
  • To scroll up, press k.

Note: For scrolling in vim editor, you can utilize the arrow keys too, but hjkl keys usage will make you scroll faster in the vim editor.

Conclusion

Vim is a text editor that several Linux users use for its incredible features, including syntax highlighting, multi-level undo, command-line editing, multiple buffers and windows, filename completion, visual selection, and a comprehensive support system. However, vim is derived from vi editors; it prefers hjkl keys for scrolling and moving in the text editor. These hjkl keys usage will make you scroll faster in the vim editor.

About the author

Talha Saif Malik

Talha is a contributor at Linux Hint with a vision to bring value and do useful things for the world. He loves to read, write and speak about Linux, Data, Computers and Technology.