Sitemap
Carlhector

Carlhector

Linux & Vim Editor

5 min readJan 9, 2024

--

Linux is an operating system that is built around the open-source Linux kernel. Linux kernel is used by different operating systems and those are called Linux distributions. Open-Source means that, it is a software with source code that anyone can inspect, modify, and enhance. Linux was created in the early 1990s by Finnish- American software engineer Linus Benedict Torvalds.

Linux Principles

· Everything is considered as a file (Including Hardware)

· Small Single purpose Programs

· Ability to chain programs together for complex operations

· Avoid Captive User Interface

· Configuration data stored in text file

Why Linux?

· Opensource

· Community Support

· Support Wide Variety of Hardware

· Customization

· Most Servers runs on Linux

· Automation

· Security

Architecture of Linux

Press enter or click to view image in full size

Popular Linux distros

Popular Desktop Linux OS

· Ubuntu Linux

· Linux Mint

· Arch Linux

· Fedora

· Debian

· OpenSuse

Popular Server Linux OS

· Red Hat Enterprise Linux (most popular one, considerable most stable, not an open source)

· Ubuntu Server

· Centos

· SUSE Enterprise Linux

In Linux, there are two main packages managers RPM and Debian

RPM based distros- RHEL, Centos, Oracle Linux

Debian based distros- Ubuntu Server, Kali Linux

The difference between RPM based and Debian based:

DEB

DEB is the extension of the Debian software package format and the most often used name for such binary packages. DEB was developed by Bedian

RPM

It is a package management system. The name RPM variously refers to the .rpm file format, files in this format, software packaged in such files, and the package manager itself. RPM was intended primarily for Linux distributions; the file format is the baseline package format of the Linux Standard Base. RPM was developed by Community & Red Hat.

Some Important Linux Directories

VIM Editor

Vim is a free and open source, screen-based text editor for Unix. It is a very advanced and highly configured text editor built to enable efficient text editing

There are Four (3) modes to Vim Editor

1. Normal

2. Command Mode

3. Insert Modes

Normal Mode

Normal mode is the default mode that Vim opens with. It is used to perform actions such as navigation, text substitution, cut , copy paste, delete, etc. You get the picture.

In Normal mode key presses don’t work as one would expect. That is, they don’t insert text into the document; instead, certain key presses can:

Move the cursor

· h move one character left

· j move one row down

· k move one row up

· l move one character right

As many vim commands, row movement can be prefixed by a number to move s everal lines at a time:

Get Carlhector’s stories in your inbox

Join Medium for free to get updates from this writer.

· 4j move 4 rows down

· 6k move 6 rows up

Basic word movements:

· w move to beginning of next word

· b move to previous beginning of word

· e move to end of word

· W move to beginning of next word after a whitespace

· B move to beginning of previous word before a whitespace

· E move to end of word before a whitespace

Beginning/End of line movement:

· 0 move to the beginning of the line

· $ move to the end of the line

Command Mode

Command mode has numerous commands and can do do things that normal mode can’t do as easily. To enter command mode, you must type “:” from the normal mode and then type the command which should appear at the bottom of the window

· : Enters command mode

· % Means across all lines

· s Means substitute

· /foo is regex to find things to replace

· /bar/ is regex to replace things with

· /g means global, otherwise it would only execute once per line

Insert Mode:

Insert mode will be the most used mode. This is where typing and editing text, just like any other text editor. You can access insert mode by using one of a few available insert commands.

· i will immediately switch you to insert mode

· I (capital) moves the cursor to the beginning of the line and enters insert mode

· a stands for ‘append’ and will move the cursor to the end of the current word and enter insert mode

· A will move the cursor to the end of the line and enter insert mode

· inserts a new line below the current line and enters insert mode on the new line

· inserts a new line above the current one and enters insert mode on the new line

Installation of Vim Editor in Linux System

We will need to run the command sudo yum install vim-y

Press enter or click to view image in full size

Next, we will open a file

I will use this command vim filename.txt. to open a file. I will name mine carlfile. The command that I will then use is vim carlfile.txt.

It will look something like this

Press enter or click to view image in full size

This is the conclusion of the article. I know it looks overwhelming and confusing, but practice makes better. I will leave you guys a command line cheat sheet.

Changing mode from one to another :

  • Text Entry Commands :
Press enter or click to view image in full size

Command mode (Press ESC)

  • Cursor movement :
Press enter or click to view image in full size
Press enter or click to view image in full size
  • Exiting commands in Vim:
Press enter or click to view image in full size
  • Text Deletion Commands:
Press enter or click to view image in full size
  • The paste used after delete or yank to recover lines:
Press enter or click to view image in full size

Delete all the lines in vim:

Press enter or click to view image in full size
  • File Manipulation Commands
Press enter or click to view image in full size

Search:

Press enter or click to view image in full size

Search and Replace:

Press enter or click to view image in full size

--

--