Linux Vim Commands And Modes

VIM - Linux Vim Commands And Modes


vim in Unix
image source:-https://bogdanvlviv.github.io

Vim is an editor that allows editing the text of the particular file. Unix operating system allows us a powerful editor to edit the contents of the file. This editor constructed by Bram Moolenar in 1991 for Amiga computer. We use the command to create the file on command prompt but we cannot edit the context of the file on the command prompt. It supports the regular expressions, visual mode, file transmission, spell checking etc. This editor supports multilanguage and manages the history of contents etc. It provides different modes to manage the text like command mode, insert mode, visual mode. It provides keys to manage the text for editing, deleting, searching etc.

Vim Mode:

This editor opens the contents into window format and provides different mode.

1. Command mode:

It is a mode of vim that executes the task on the base of the particular key. Vim editor manages the text manipulation, editing the text etc. By default, vim editor opens the text etc. By default vim editor open in command mode.

2. Insert mode:

It is a mode that inserts the text into the file as content. We press the key I, a,o, A to insert the information into the file. We use escape key to switch from insert mode to command mode.

3. Visual mode:

In this mode, the text can process in a visual format. We use u,v and ctrl v for visual mode. This command can be considered as sub-mode of command.

Vim Basic:

Vim editor allows opening the file into editing mode.

1. Vim command:

It is a command that allows opening the file into editing mode. By default, the file contents are open in command mode.

vim∅<file name>

vim anna↵

 Saving Files And Exit:

Vim editor allows us to save the content after editing into the existing file in command mode. We can also exit from the Vim editor using the particular key.

A) :w:

It is a command that saves the contents into the existing file in command mode.

B) :q:

This command is used to quit from the existing file.

C) :wq:

This command saves the content and exit also.

D) :q:

It is a command that forcing the exit from the current file.

Modifying a file:

It is a technique to modify the contents of the file and save also, In this, ≡ symbol identifies the blank line. The blank file contains ≡ symbol at beginning of the line.

Vim x↵

Vim Command:

1. Moving command:

Vim editor allows us an area to edit the text and provide different commands to control the contents of the particular file. We use arrow keys to move the cursor left-right, up-down direction. A key h is used to move the cursor in the left direction, i in right, k for up and j for down. These characters are executed in command mode of Vim editor.

2. Multi text processing:

A command cu is used to move the cursor at a particular line. In this, we use line number and G. We press ‘O’ character to insert the new line at the end of content. A character ‘i’ is used to inserting the text in the middle of the particular line before the current cursor position and ‘a’ is used to insert the contents after the current position. ‘A’ is used to append the contents at end of the line.

3. Replacing Text:

Vim editor allows us an area to edit the text we can replace the text with a new character with the particular key. We use r character to replace the text with the new character. ‘R’ is used to replace more than one character and is used to shift the text after inserting the contents and S is used for replacing current line at a time with the new character.

4. Deleting text :

Vim editor provides a character to delete the contents from the current file. We use X to delete single character as delete X.

We can also remove more than one lines at a time so, we need to use the number of characters with X. A character dd is used to delete the current line at a time. We can also use numeric with dd to remove more than one lines at a time.

5. Undoing change:

The character U is used to recover from the most recently committed mistake. It is similar to the undo process of application. We also use ctrl+r for undo process.

6. Search and replace:

Vim editor allows us to search the contents and replace with new text. We use: s to search the text and replacing with new data. The searching text and replacing text are separated with /.

:s|<searching text>|<replacing text>↵


7. Operators for vim:

Vim editor provides an operator to manipulate the text we use d to delete the whole part of the sentence from the beginning of a cursor. We used { to remove the section before the cursor and d ‘d}’ to remove section after the cursor. We use d[[ to delete a complete paragraph and d]] to delete paragraph after the cursor. We press y to pass the deleted text at the particular location. YY also used to pass the content before the cursor.

Text Processing:

Vim editor allows us to manage the text and editing also. It provides to transfer the concepts of a file to another file. A command: r is used to transfer the contents of the file into existing file.


r<file name>


r anna

Visual Mode:

Vim editor provides visual mode to manage the text processing into a visual format. We can transfer the Vim editor into visual mode using control +v, V. This mode displays the contents processing as GUI format. The user uses particular keys in the vim editor to move the cursor, inserting, deleting etc processing. It displays the selecting text and other processing details also. We use ctrl+v+$ to select the particular line in visual mode.

Vim editor also opens more than one window at a time into the Vim editor. A command buffer displays the list of windows. The :b is used to switch a particular window. In this, we pass window number. A command: q is used for closing the current window. And open the new window.

Customizing Features:

Vim editor allows changing the default feature of  Vim command. It means we can define the new definition of particular characters.

1. Abbreviation:

It is the customization feature of vim editor that allows defining a sentence on the particular word. It means we can display the text with the help of particular word.

A) :abb:

It is a command that creates the abbreviation of the particular sentence and assigns on a particular word. It is basically used to display particular sentence without re-typing.

:abb<abbreviation word>

<nw sentence: abb gth go to hell.

2. Key mapping:

There are different keys are used into the Vim editor for executing the commands like dd to delete a line, i to insert the text etc. Vim editor helps us to create a key with the particular command. It means we can assign the particular task on a particular task on the particular key.

A) :map:

It is a command that allows mapping the character to a new feature. We use particular task using control key and define the particular key for mapping.

:map<ctrl+command key>

<new char>

:map ctrl+delete X

3. Setting Vim parameter:

Vim provides a window for editing the text with a particular setting like margins, wrap margins, etc. A command :set is used to set the default parameters of Vim editor.

:set wm=4

Advanced Command:

Vim editor allows us advanced feature to manage the text for editing. Vim is an advanced text editor that provide built-in commands and options to control the text.

1. Macros:

The Vim editor provides a method to record the contents and display on the text editor. A character q and another key used to record the contents and again press q to stop the recording.

2. Completing words:

Vim editor helps us to complete the word without typing. It means we can display the complete word after typing particular character. We press ctrl+l to complete the line after typing some character it used a dictionary to search the content and display on Vim editor.

3. Spell checking:

It is a method to check the correct spelling of a particular word. We can display the set of words related to existing text for replacing with a mis-spell word. We use :sp to check the spell of given word.

4. Mark:

We can set marks with the document to jump quickly between different positions into the Vim editor. A command: mark is used to highlight the given character from the Vim editor. A command: delmark to delete the particular character from the document.

: mark a b↵

:delmark a b c↵

5. Running external Linux command:

Vim editor allows us to execute Linux command in command mode and execute output. We use :r and ! to execute the external command and append into the existing file.




About the author


Add Comment

Click here to post a comment