VIM Editor

VI             Visual display editor
VIM         Visual display editor improved

This is command mode editor for files. Other editors in Linux are emacs, gedit
vi editor is most popular

It has 3 modes:

  1. Command Mode
  2. Insert mode (edit mode)
  3. extended command mode

Note: When you open the vim editor, it will be in the command mode by default.

In the command mode the cursor’s can be used as
h/l/k/j to move cursor left/right/up/down
Insert Mode:

i

To begin insert mode at the cursor position

I

To insert at the beginning of line

a

To append to the next word’s letter

A

To Append at the end of the line

o

To insert a new line below the cursor position

O

To insert a new line above the cursor position

 

Command Mode:

gg

To go to the beginning of the page

G

To go to end of the page

w

To move the cursor forward, word by word

b

To move the cursor backward, word by word

nw

To move the cursor forward to n words (5W)

nb

To move the cursor backward to n words (5B)

u

To undo last change (word)

U

To undo the previous changes (entire line)

Ctrl+R

To redo the changes

yy

To copy a line

nyy

To copy n lines (5yy or 4yy)

p

To paste line below the cursor position

P

To paste line above the cursor position

dw

To delete the word letter by letter (like Backspace)

x

To delete the world letter by letter (like DEL Key)

dd

To delete entire line

ndd

To delete n no. of lines from cursor position(5dd)

/

To search a word in the file

 

Extended Mode: ( Colon Mode)
Extended Mode is used for save and quit or save without quit using “Esc” Key with “:”

Esc+:w

To Save the changes

Esc+:q

To quit (Without saving)

Esc+:wq

To save and quit

Esc+:w!

To save forcefully

Esc+wq!

To save and quit forcefully

Esc+:x

To save and quit

Esc+:X

To give password to the file and remove password

Esc+:20(n)

To go to line no 20 or n

Esc+: se nu

To set the line numbers to the file

Esc+:se nonu

To Remove the set line numbers

To open multiple files in vim editor
#vim –o file1 file2
To switch between files use Ctrl +w

Listing files and directories:

#ls                                       list the file names
#ls -l                                    long listing of the file
#ls –l filename                  to see the permissions of a particular file
#ls -al                                  shows the files in ascending order of modification.
#ls p*                                  All the files start with p.
#ls ?ample                         Files with any first character and has ample
#ls -ld l*                             Directory listing only
#ls –ld directory name    to see the permissions of a particular directory
#ls [ae]*                             First character of the filename must be a or e.
# ls [!ae]*                           ! Symbol complements the condition that follows.
                                            The characters must not be a or e.
#ls [a-m][c-z][4-9]            list all the files in specific range

Types of Files:

Symbol

Type of File

Normal file

d

Directory

l

Link file (shortcut)

b

Block file (Harddisk, Floppy disk)

c

Character file (Keyboard, Mouse)

Symbolic Link

There are two types of Links:-

 

Soft Link

Hard link

1

Size of link file is equal to no. of

characters in the name of original file

Size of both file is same

2

Can be created across the Partition

Can’t be created across the partition

3

Inode no. of source and link file is

different

Inode no. of both file is same

4

if original file is deleted, link is broken

and data is lost

If original file is deleted then also link

will contain data

5

SHORTCUT FILE

BACKUP FILE

 

Creating a soft link:
# ln –s <source file> <destination>

[root@localhost ~]# ln -s linuxfile linuxfile.slink
[root@localhost ~]# ls -li linuxfile linuxfile.slink
3076 -rw-r--r--. 1 root root 20 Mar 25 11:14 linuxfile
3522 lrwxrwxrwx. 1 root root 9 Mar 29 18:09 linuxfile.slink -> linuxfile
[root@localhost ~]#

Creating a Hard link:
#ln <source file> <Destination>

[root@localhost ~]# ln linuxfile linuxfile.hlink
[root@localhost ~]# ls -li linuxfile linuxfile.hlink
3076 -rw-r--r--. 2 root root 20 Mar 25 11:14 linuxfile
3076 -rw-r--r--. 2 root root 20 Mar 25 11:14 linuxfile.hlink
[root@localhost ~]#

Leave a Reply

Your email address will not be published. Required fields are marked *