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
- Open Micro on Linux
- Command mode
- Insert mode
- Saving and Quiting
- Write a very small C program using Vi
- Common options for opening files in Vi
- Move between characters
- Common commands in Vi
- Copy and paste command in Vi (Practice!)
- Advanced micro command
- 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. .
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:
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:
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:
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:
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:
Write a very small C program using Vi
Open a Terminal.
Please enter:
vi file.c
This will create a new file.
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.
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.
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.
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.
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.
Common options for opening files in Vi
- vi file: Create a new file if it does not exist. If not, it will open the existing file.
- vi -R file: Read-only mode (Read only)
Move between characters
- You must be in Command mode.
- You can use the keys: Up, down, left and right arrows.
Alternatively, you can use other keys:
Common commands in Vi
Note : You must be in Command mode.
Copy and paste command in Vi (Practice!)
Create a new file named "linux-distro".
Write the following list:
- Ubuntu
- Linux Mint
- Debian
- Slackware
- Red Hat
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).
Type 1G
Type 4yy.
Type G.
Type P.
Alternatively, you can use other copy - paste commands:
- yw: Copy from current.
- p : Set the copied text after the cursor.
Advanced micro command
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:
- Basic Shell commands in Linux
- Certain deadly commands never run on Linux
- How to use the Vim editor
- 5 best free code editors
You should read it
- Create and edit Text boxes in Word
- Insert text into pictures with Word
- How to edit configuration files in Ubuntu
- Insert and edit drawings in Word
- Lesson 22: Working with the Text Box
- How to Create and Edit Text Files Using Terminal on Linux
- How to quickly create new blank text files on Windows, Mac and Linux
- How to insert images into Word documents
May be interested
- Instructions for installing software and applications on Linuxinstalling 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 Specteron 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 platformsyou 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 / Linuxa 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 Linuxwhen 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 cardmicro 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 Facebooktrend micro security firm has warned facebook users about the emergence of some fraudulent software, hijacking access credentials ..
- Linux GUI applications can run on Windows 10on 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 HDMIthe 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 11while 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.