Linux Commands Practical
Linux Commands Practical
(Degree Wing)
Submitted By Submitted To
Ravi Verma Dr. Dheerendra Singh
Roll No: CO19352 Professor
CSE 4th Semester
Aim: Learning and working with Vi Editor
Introduction
The VI editor is the most popular and classic text editor in the Linux family. Below, are some
reasons which make it a widely used editor –
1. It is available in almost all Linux Distributions
2. It works the same across different platforms and Distributions
3. It is user-friendly. Hence, millions of Linux users love it and use it for their editing needs
There are advanced versions of the vi editor available, and the most popular one is VIM which is
Vi Improved. Some of the other ones are Elvis, Nvi, Nano, and Vile. It is wise to learn vi because
it is feature-rich and offers endless possibilities to edit a file.
● The vi editor is the most popular and commonly used Unix text editor
● It is usually available in all Linux Distributions.
● It works in two modes, Command and Insert
● Command mode takes the user commands, and the Insert mode is for editing text
● You should know the commands to work on your file easily
● Learning to use this editor can benefit you in creating scripts and editing files.
● It's usually available on all flavors of Unix system.
● Its implementations are very similar across the board.
● It requires very few resources.
● It is more user-friendly than other editors such as the ed or the ex.
Operation modes
1. Command mode
The vi editor opens in this mode, and it only understands commands
In this mode, you can, move the cursor and cut, copy, paste the text
This mode also saves the changes you have made to the file
Commands are case-sensitive. You should use the right letter case.
2. Insert mode
This mode is for inserting text in the file.
You can switch to the Insert mode from the command mode by pressing 'i' on the
keyboard. Once you are in Insert mode, any key would be taken as an input for the file on which
you are currently working. To return to the command mode and save the changes you have made
you need to press the Esc key.
Vi Editor Functions
1. Inserting text: - After creating a new file or opening an already existing file, you can
write text in it by first shifting to insert mode by hitting the i key. You will notice that the
vi command itself generally does not appear on the screen. You can type a few lines and
press <return> at the end of each line. For longer lines, vi does not word wrap the text; it
breaks the line at the edge of the screen.
2. Moving cursor across a file: - We can usually move the cursor across text in your files
with the up, down, left and right arrow keys of your keyboard. In case you are using a
remote terminal and the arrow keys fail to behave in the desired manner, you can use the
following keys as substitutes: Move left: h, Move right: l, Move up: k, Move down: j.
3. Selecting text: - We can select a text for copying, cutting and pasting only in command
mode. For selecting text, position the cursor at the left or right side of the text you want to
select and press the v key. You can then move the cursor to select the text.
4. Copying text: - Once you have selected the text, as described above, you can press y to
copy the text and x to cut the text. In order to paste the text, position the cursor at the
desired location and press the p key to paste your copied or cut text. Remember you
should be in the command mode to perform these operations.
5. Deleting text: - In order to delete a character from your file, move the cursor until it is on
the incorrect letter and then type x key. To remove more characters, say three, type 3x.
6. Saving and quitting a file: - In the command mode type :wq and press enter to write the
file to disk and quit vi. The command :w will only write the file to the disk and :q will
quit vi without saving the file. You can also split this command for example, type :w and
press enter to write the file to disk without quitting or type :q to quit vi without saving the
file. When you have made changes to your file and quit without saving your changes, vi
will give you a warning. You can ignore the warning by using the command :q! And
press enter.
7. Switching between modes: -
Then you first create or open a file in Vi, you are in Command mode. Although it seems
that you can type here, you can’t. To write anything, you need to shift to Insert mode by
hitting the i key. In order to shift back to Command mode you simply need to hit the esc
key.
Starting vi editor
1. To launch vi editor in command-line interface
Syntax
vi filename
2.Nano Editor
Nano is an easy to use text editor, especially for both new and advanced Linux users. It enhances
usability by providing customizable key binding.
Nano has the following features:
1. Highly customizable key bindings
2. Syntax highlighting
3. Undo and redo options
4. Full line display on the standard output
5. Pager support to read from standard input
3.GNU Emacs
Emacs is a highly extensible and customizable text editor that also offers an interpretation of the
Lisp programming language at its core. Different extensions can be added to support text editing
functionalities.
Emacs has the following features:
4.Kate/Kwrite
Kate is a feature-rich and highly pluggable text editor that comes with KDesktop Environment
(KDE). The Kate project aims at the development of two main products that are: KatePart and
Kate.
KatePart is an advanced text editor component included in many KDE applications that may
require users to edit text whereas Kate is a multiple document interface (MDI) text, editor.
The following are some of its general features:
1. Extensible through scripting
2. Encoding support such as Unicode mode
3. Text rendering in bi-directional mode
4. Line ending support with auto-detection functionalities
Disadvantages
1. Take time to get to use to it especially for people who haven’t worked on terminal or
linux before.
2. Complex command to write to do some advanced things inside editor
3. Case and spaces sensitive: - sometimes waste a lot of time even if we put a space extra
4. High effort to customize - I like to say that configuring Vim is a never-ending effort.
There’s always something that can be tweaked or improved.
5. Poor support for external tooling - Many plugins depend on optional Python and Lua
features, which may or may not be included in whatever binaries are available in the
machine.
6. Poor Feature Discoverability - Though basic features like syntax checking,
autocompletion, and file management are all available out of the box or with minimal
configuration, this is not obvious. The help is very well written but it’s hard to guess
where can the documentation for these features can be found.
7. Script does not run due to spaces many time so we have to write commands again and
again to enter or exit the vi editor and check the running of program.
Conclusion
We can now insert content into a file, move the file around, remove content and undo it then save
and exit. We can now do basic editing in vi. There are lots of vi cheat sheets available online so
you can take your time in learning all of the various commands and concepts. In this practical,
we explored the interesting world of Linux vi editor. After reviewing basic concepts, we learned
how to search for text.
Vim is a really powerful editor and now you can get your hands dirty with it. Mastering Vim will
really improve your productivity. Using Vim you can solve many complex tasks with few
commands. We can refer following documentation to know more about Vim.