OS Mod 4 (8m)
OS Mod 4 (8m)
Vim is a text editor that is commonly used in Unix and Linux operating
systems. It is a powerful and highly configurable editor that can be used for a
wide range of text editing tasks, including code editing, document creation, and
system administration tasks.
Vim stands for "Vi Improved", and it is an enhanced version of the Vi editor
that was developed in the 1970s as part of the Unix operating system. Vim is
designed to be a modal editor, which means that it has different modes for
navigating and editing text.
In Vim, you can navigate and edit text using the keyboard, without needing to
use a mouse or other pointing device. Vim has a wide range of features and
commands, and it can be customized extensively to suit the needs of individual
users.
Features of Vim
To create a Vim file and perform searching and substituting on a particular part
of the text, you can follow these steps:
1. Open the Vim editor by running the command vim in your terminal.
2. To create a new file, press the i key to enter the Insert mode. Now you
can start typing your text.
3. Enter the desired text, including the part where you want to perform the
search and substitution.
4. To save the file, press the Esc key to exit Insert mode. Then type :wq and
press Enter. This command writes the changes to the file and quits Vim.
5. Now let's perform searching and substituting on the specific part of the
text. Open the file again by running vim <filename> in the terminal,
replacing <filename> with the name of the file you created.
6. Once the file is open in Vim, press the Esc key to ensure you are in the
Normal mode.
7. Move the cursor to the part of the text where you want to perform the
search and substitution.
8. Press the : key to enter Command-line mode.
9. To search for a specific pattern, type / followed by the pattern you want
to search for. For example, if you want to search for the word "example",
you would type /example.
10.Press Enter to perform the search. Vim will highlight the first occurrence
of the pattern in the text.
11.To substitute the searched pattern with a different text, type
:s/old_text/new_text/, replacing old_text with the pattern you searched
for and new_text with the replacement text. For example, if you want to
replace "example" with "replacement", you would type
:s/example/replacement/.
12.To perform the substitution on the current line, press Enter. If you want to
perform the substitution globally (on all occurrences of the pattern in the
file), add the g flag at the end of the command. For example,
:s/example/replacement/g.
13.Vim will perform the substitution and provide feedback on the number of
substitutions made.
14.You can use the n key to move to the next occurrence of the pattern and
perform the substitution again if needed.
15.Once you are done with the search and substitution, you can save the
changes and quit Vim by pressing the Esc key, then typing :wq and
pressing Enter.
In Vi editor, there are several commands that allow you to move the cursor
around the file while you're in command mode. Here are some of the most
common cursor movements:
- `h`: Move the cursor one character to the left.
- `0` (zero): Move the cursor to the beginning of the current line.
H, M, L - These keys are used to move the cursor to the top, middle, and
bottom of the screen, respectively. The H key moves the cursor to the top of the
screen, the M key moves the cursor to the middle of the screen, and the L key
moves the cursor to the bottom of the screen.
Ctrl+f, Ctrl+b - These keys are used to move the cursor forward and backward
by a full screen, respectively. The Ctrl+f key moves the cursor forward by a full
screen, while the Ctrl+b key moves the cursor backward by a full screen.
In Vi editor, you can delete and change text using a variety of commands. Here
are some of the most common ones:
Deletion Commands:
- `x`: Deletes the character under the cursor.
- `dw`: Deletes from the cursor to the end of the current word.
In Vim, buffers are an essential concept for managing multiple files or text
sources within the editor. A buffer represents the content of a file or a text
source that is currently open in Vim. Understanding buffers allows you to work
with multiple files simultaneously and switch between them efficiently. Here
are the key concepts related to buffers in Vim: