Learn about Micro applications in Linux

For Linux users, Vi - text editing application is one of the indispensable support tools . Unlike Nano - a text editing application in Terminal format, Vi has a variety of useful and functional shortcut keys, with 2 main modes of operation: Insert and Command.

Micro editor in Linux

  1. Open Micro on Linux
  2. Command mode
  3. Insert mode
  4. Saving and Quiting
  5. Write a very small C program using Vi
  6. Common options for opening files in Vi
  7. Move between characters
  8. Common commands in Vi
  9. Copy and paste command in Vi (Practice!)
  10. Advanced micro command
  11. Work with two or more files (Practice!)

Open Micro on Linux

Vi is actually a Terminal application, so you will have to boot from the corresponding Terminal window. Use the vi / path / to / file syntax to open the text file available with Vi, and the command will also work if the specified text file is not available, instead Vi will create a text file with that name. .

Learn about Micro applications in Linux Picture 1

Note that we need to use the sudo command if we want to modify the file system, for example, if we want to edit the system's Fstab file, type:

sudo vi / etc / fstab

If you use a non-Ubuntu operating system version of Linux, replace sudo with su .

Command mode

Here is the image when we open the file with Vi, it looks like we can type the character here, but it's not really. Vi is actually a drafting application, and is opened in Command mode:

Learn about Micro applications in Linux Picture 2

When in Command mode, we can move the cursor by pressing the arrow key, pressing x to delete the character just below the cursor, and pressing dd to delete the entire character line. Besides, you can choose, copy, cut and save the text in this mode. Move the cursor to the left or right of the letter to copy and press the v key, press x to cut the text, then place the cursor where you need to move the text and press p to paste:

Learn about Micro applications in Linux Picture 3

Insert mode

This is Vi's operating mode that allows users to insert characters into the text. Just press the I button we have switched to Insert mode after defining the cursor position in Command mode:

Learn about Micro applications in Linux Picture 4

When entering the necessary text, press the Escape key to return to Command mode.

Saving and Quiting

You can save and exit the application in Command mode (press Escape to make sure we are in this mode). Type: wq to save the file after changing and closing Vi, or executing it separately into 2 steps: w to save the file and: q to exit the program without saving the changes:

Learn about Micro applications in Linux Picture 5

But Vi will not let the user close the application if it has changed since the last save, type: q! And press Enter to ignore this warning:

Learn about Micro applications in Linux Picture 6

Write a very small C program using Vi

Open a Terminal.

Please enter:

 vi file.c 

This will create a new file.

Learn about Micro applications in Linux Picture 7

Vi in Command mode by default. So if you want to write something, you can't do this.

Type 'i' to be able to write your code.

Learn about Micro applications in Linux Picture 8

Now, you will be in Insert mode , but if you want to delete a character, you cannot do it.

Type ESC to change to Command mode.

In Command mode, type 'x'. This will delete the character under the cursor.

Learn about Micro applications in Linux Picture 9

You can insert a character to the left of the cursor by typing 'i'.

You can insert the character to the right of the cursor by typing 'a'.

Insert a '>' in the text.

Learn about Micro applications in Linux Picture 10

Return to Command mode and type : wq, then return:

 wq 

Now you are at the command prompt. Please see the contents of your file using cat.

Learn about Micro applications in Linux Picture 11

You may be thinking that Vi is very complicated, but in reality it is not. Vi is a fairly simple editor, but it can only work in a single mode at a time.

Re-open your file ( vi file.c ) and write the following code:

 void main(void){ printf('vi is a great tool to write code faster '); } 

Save your file and if you have gcc installed, you should compile and run it.

Learn about Micro applications in Linux Picture 12

Learn about Micro applications in Linux Picture 13

Common options for opening files in Vi

  1. vi file: Create a new file if it does not exist. If not, it will open the existing file.
  2. vi -R file: Read-only mode (Read only)

Move between characters

  1. You must be in Command mode.
  2. You can use the keys: Up, down, left and right arrows.

Alternatively, you can use other keys:

k
Move the cursor up
j
Move the cursor down
hour
Move the cursor to the left
l
Move the cursor to the right

Common commands in Vi

Note : You must be in Command mode.

Order
Describe
i
Insert the text before the current cursor position.
l
Insert text at the beginning of the current line.
a
Insert text after the current cursor position.
A
Insert text at the end of the current line.
o
Create a new line for the text entry below the cursor.
O
Create a new line for the text entry above the cursor.
x
Delete the character below the cursor.
X
Delete the character before the cursor.
dd
Delete the cursor line being placed.
cc
Delete the content of the line, to the user in Insert mode.
r
Replace the character below the cursor.

Copy and paste command in Vi (Practice!)

Create a new file named "linux-distro".

Write the following list:

  1. Ubuntu
  2. Linux Mint
  3. Debian
  4. Slackware
  5. Red Hat

Learn about Micro applications in Linux Picture 14

Change to Command mode (ESC).

Move the cursor to "Ubuntu".

Type yy (this is a command to copy a line).

Type G.

Insert a new line by typing o.

Change to Command mode (ESC).

Type P (This command is for pasting lines).

Learn about Micro applications in Linux Picture 15

Type 1G

Type 4yy.

Type G.

Type P.

Learn about Micro applications in Linux Picture 16

Alternatively, you can use other copy - paste commands:

  1. yw: Copy from current.
  2. p : Set the copied text after the cursor.

Advanced micro command

<<
Join the current line and the next line. Some participate in multiple lines.
>>
Align the current line to the left with a variable width.
: nr file
Read the file and insert it after the line n.
~
Convert case / lower case of characters below the cursor.
^ G
Press CTRL and G keys at the same time to display the file name and current status.
U
Restore the current line to the state before the cursor enters the line.
u
Undo the last change to the file. Re-enter "u" again to make changes again.
J
Join the current line and the next line. Some participate in multiple lines.
: f
Displays the current location in the file with% and file name, total file.
: f filename
Rename the current file to filename.
: filename w
Write the filename of the file.
: e filename
Open a file other than filename.
: cd dirname
Change the current working directory to dirname.
: e #
Use to switch between open files.
: n
In case you open multiple files with Vi, use: n to move to the next file in the string.
: N
In case you open multiple files using vi, use: N to move to the previous file in the string.
: r file
Read the file and insert it after the current line

Work with two or more files (Practice!)

Open the linux-distros file

In Command mode, type:

 :e unix 

Write " UNIX is a good OS " and save it.

Go to the linux-distros file with the command:

 :e # 

Exit Vi by typing:

 :q 

Good luck!

See more:

  1. Basic Shell commands in Linux
  2. Certain deadly commands never run on Linux
  3. How to use the Vim editor
  4. 5 best free code editors
4 ★ | 1 Vote

May be interested

  • Instructions for installing software and applications on LinuxInstructions for installing software and applications on Linux
    installing software on linux will be a little different from installing software on windows or macos. instead of accessing the website, users will have to get the application from the linux distribution's software store through the program. to manage library packages, the article below tipsmake will guide you how to install software and applications on linux.
  • Intel released Microcode for CPU Linux to fix Meltdown and SpecterIntel released Microcode for CPU Linux to fix Meltdown and Specter
    on january 8, intel released micro-data files for linux microprocessors to mitigate the effects of meltdown and specter vulnerabilities.
  • Run Windows applications on Linux, macOS and other platformsRun Windows applications on Linux, macOS and other platforms
    you can dual boot on linux or use bootcamp or parallels on mac. if not, you can install the following applications we suggest. these applications will allow you to install and run windows applications directly on non-windows operating systems, for example: mac os x, gnu / linux, ubuntu, bsd and solaris.
  • Regular Expression in Unix / LinuxRegular Expression in Unix / Linux
    a regular expression is a string that can be used to describe different sequences (arrangement) of characters. regular expression is often used by various unix commands, including ed, sed, awk, grep and micro domains.
  • Learn about Hibernate mode in LinuxLearn about Hibernate mode in Linux
    when it comes to source options in linux distributions, there are logout, shutdown, suspend and hibernate functions. in today's article, let's learn about hibernate mode in linux.
  • How to Format a micro SD cardHow to Format a micro SD card
    micro sd is a very small memory card, often used to add more memory to devices such as cameras, gps devices and mobile phones. in most cases, you can format a micro sd card using the device's built-in commands. however, you can also format the micro sd card right on your windows or mac computer.
  • Appears many standalone applications on FacebookAppears many standalone applications on Facebook
    trend micro security firm has warned facebook users about the emergence of some fraudulent software, hijacking access credentials ..
  • Linux GUI applications can run on Windows 10Linux GUI applications can run on Windows 10
    on april 21, microsoft announced that linux gui applications can now run on windows 10 using windows subsystem for linux (wsl). using this feature, you can run any possible gui application on linux or run your own applications or test on linux.
  • Difference between HDMI, Mini HDMI and Micro HDMIDifference between HDMI, Mini HDMI and Micro HDMI
    the hdmi standard has become the mainstay of the post-hd digital age. while new versions have appeared and have significantly increased speed, the connectors have remained the same as the first introduction.
  • How to choose a microphone on Windows 11How to choose a microphone on Windows 11
    while using windows 11, you may need to set up audio input switching between several microphones that are connected to your pc for work or play purposes.