How To Create And Edit Text File In Linux Using Vim

Introduction:

Vim stands for Visual Interface IMprove is an improved version of VI (Visual interface), a famous text-editor in Linux. VIM is display-oriented: the screen of terminal acts as a window into the file you are editing. Changes you make to the file are reflected in what you see. Vim is backward-compatible with vi. Vim editor provides syntax highlighting, completion modes, spell-checking, scripting in multiple languages, file-type plug-ins, and many other options. VIM editor is a full screen editor and has three modes of operations”

Command Mode:

Command which cause action to be taken on the file. This mode is used for the file navigation, cut and paste, and simple commands such as undo and redo.

Insert Mode:

This mode is used for normal text editing means entered text is inserted into the file. Accessed by typing the letter “i” or “I”, we simple enter text. Most keystrokes result in text appearing on the screen. To get out of insert mode, hit the “esc” Escape key. Once you press “Esc” Escape key it will turns off the insert mode.

Last-Line Mode:

This mode is used to save, quit and open files, as well as search & replace and other operation. Press “:” and vi will switch to Last-Line Mode. Enter a command like “:w” to write the file or “:q” to exit the editor.

h or left Arrow Go one character to the left
j or Down Arrow Go down one line
12j Move the cursor 12 lines down
k or Up Arrow Go up one line
l or Right Arrow Go one character to the right
$ Go to the end of the current line
G Move to the last line of the document
gg Move to the first line of the document
W Forward one word
5w Forward five words
B Backward one word
( Move cursor to beginning of current or previous sentence
) Move cursor to beginning of next sentence
{ Move to beginning of current/previous paragraph
} Move cursor to beginning of next paragraph
H Go to the top of the screen
L Go to the bottom of the screen
0 (Zero) Go to the beginning of the current line
Ctrl – B Go back one screen
Ctrl – F Go forward one screen
R Replace the character as the current cursor position
R Overwrite at the current cursor position
X Delete the character at the current cursor position
x Delete the character immediately before (to the left)
Dd Cut the entire line
D Cut from the current cursor position to the end of the line
YY or Y Yank (copy) the entire current line
P Paste
.(period) Repeat the last command
u Undo the last command
U Undo the last command in the last line.
n Fine the next match in a search
N Fine the previous match in a search
cw Change current word to a new word
:/ To search forward
: ? To search backward
:set number Enables line numbers
:set nu Enables line numbers
:set nonu Turn line numbers off
:set nonumber Turn line numbers off

Leave a Reply

Your email address will not be published.