Introduction to Vim & Vi editor

Christober S
3 min readNov 15, 2023

--

vim is an improved version of vi

Vim editor
  • vim is by far the most distributed and used text editor in the Linux
  • Depending on your Linux distro, vim may or may not be installed
  • They are terminal applications, So you’ll have to start and used them in the terminal with commands

Use cases to use text editor in CLI:

  1. Small modifications can be faster, especially when you are currently working in the CLI
  2. Supports multiple formats
  3. When working on a remote server

Installation of Vim editor

$sudo apt install vim

Opening a file

$vim <filename> = open file with vim
open file in vim

In vim editor there are 2 mode

  1. Command mode
  2. Insert mode

Command mode:

  • This is the default mode
  • You can’t edit the text
  • Whatever you type is interpreted as command
  • Navigate, Search, Delete, Undo and etc..
  • To switch to command mode press esk key
esc key

Insert mode

  • Allows you to enter text
  • To switch to insert mode press i key
i key

Write and Save

  • After writing in the insert mode we can save and quit
:wq

This will write files to the disk and quit vim

write & quit

Without saving the changes

:q!

Type :q! => Quit vim without saving changes

without saving files

Delete entire line

dd

dd => Delete the entire line

Delete next lines

d10

d10 => Delete the next 10 lines

Undo

u

u => undo the changes

End of line

A

Type ‘A’ => Jump to end of line and switch to insert mode

Start of line

0

Type ‘0’ => Jump to start of the line

Specific Line

<linenumber>G
10G

Type 10G => Go to line 10

Pattern

Type /pattern => search for pattern (enter)

pattern

Type n = Jump to the next match

Type N = Search in the opposite direction

--

--

Christober S
Christober S

Written by Christober S

Student | Cloud | DevOps | Tech Blogger | Public Speaker

No responses yet