vi Editor | vi Editor with its options | how to use vi Editor | Step by Step Learning of vi Editor | ftp Commands

vi Editor :

In previous articles we have checked the different file commands in unix with real examples,directory commands,grep command with examples.In this article we focus on the vi editor with real examples and its options.Vi editor is almost used in all unix operating systems.We can be able to edit the text of the file,change the text,delete or format the text.It is used to create files or to modify existing files.

It is classified into 3 types:

  1. Command mode
  2. Input or Insert mode
  3. Ex command mode

The default mode is Command mode:

Vi is command to open vi editor.

Back to UNIX Ctrl+Z

The following are the commands to shift from Command Mode to Insert Mode.

A :

It places cursor at end of the current line

a :

It places cursor at right side of the cursor line

I :

It places cursor at beginning of the current line

i :

It places cursor at left side of the cursor line

O :

It Insert new line of the cursor

o :

It Insert new line below of the cursor

(Shift+:) “ESC” is the key to shift from Insert mode to command mode.

“:” is the command to shift to Ex command mode from command mode.

 Command mode commands :

k (nk)(Upper Arrow)

 

 

h (nh)(Left Arrow)                             l (nl)(Right Arrow)

 

j (nj)(Lower Arrow)

 

(n) means any number

 

1) w (nw)        Next Word Starting

e(ne)                Word Ending

b(ne)                Previous Word Beginning

 

2) $                                  End of the current line (End Key)

^                                   Beginning of the current line (HomeKey)

 

3) H                                 Beginning of the Current Page

M                                 Middle of the Current Page

L                                  End of the Current Page

 

4) Ctrl+f                       Forward on Page (Page Down)

Ctrl+b                       End of the Page (Page Up)

 

5) x(nx)                         Delete Current Character (Del Key)

 

6) X                                Delete Previous Character(Backspace Key)

 

7) dw(ndw)                  Delete Current Word

 

8) dd(ndd)                    Delete Current Line

 

9) d$                             Delete Current Position to End of the line.

 

10) d^                           Delete Current Position to Beginning of the line.

 

11) yw(nyw)                 To Copy a Word

 

12) yy(nyy)                  To Copy a Line

 

13) y$                          It Copies Current Position to End of the line

 

14) y^                          It Copies Current Position to Beginning of the line

 

15) p                            Paste Below the Cursor

 

16) P                            Paste Above the Cursor

 

17) J                             To Join a line

 

18) cc                           To Clear a line

 

19) u                             undo

 

20) c^                          Cut Current Position to Beginning of the line

 

21) c$                           Cut Current Position to End of the line

 

EX Command Mode Commands:

 

:wfile name                            Save with Given File Name

:q!                                            Quit Without Save

:wq                                          Save And Quit

:n                                             Places Cursor At Nth Line.

:$                          Places Cursor At Last Line In The File

: Set nu                                    Set Line Numbers

: Set nonu                                To Remove Line Numbers

:!<UNIX command>                 Execute UNIX Command

:/string/                                   Top To Bottom Search        [n à next occurrence]

: ?string?                                 Bottom to Top Search        [N à Previous occurrence]

: Starting Line No,

Ending Line No

s/old string/new string/gi        Search And Replace string

 

E.g. 1, $ s/Unix/Linux/gi

: 1,$ S/^/UNIX                 It adds UNIX at beginning of each line

: 1, $, S/$/i                         It adds I at end of each line

: nd                                       It deletes nth line

: 3d                                       It deletes 3rd line

: $d                                       It deletes last line

: 4,7d                                    It deletes 4th line to 7th line

 

ftp command :

 The FTP (File Transfer Protocol) utility program is commonly used for copying files to and from other computers. These computers may be at the same site or at different sites thousands of miles apart. FTP is a general protocol that works on UNIX systems as well as a variety of other (non-UNIX) systems.

To connect your local machine to the remote machine, type

$ ftp machine name

 

? to request help or information about the FTP commands

bye to exit the FTP environment (same as quit)

cd to change directory on the remote machine

close to terminate a connection with another computer

delete to delete (remove) a file in the current remote directory (same as rm in UNIX)

get to copy one file from the remote machine to the local machine

lcd to change directory on your local machine (same as UNIX cd)

ls to list the names of the files in the current remote directory

mkdir to make a new directory within the current remote directory

mget to copy multiple files from the remote machine to the local machine; you are prompted for a y/n answer before transferring each file

mget * copies all the files in the current remote directory to your current local directory, using the same filenames. Notice the use of the wild card character, *.

mput to copy multiple files from the local machine to the remote machine; you are prompted for a y/n answer before transferring each file

put to copy one file from the local machine to the remote machine

pwd to find out the pathname of the current directory on the remote machine

quit to exit the FTP environment (same as bye)

rmdir to remove (delete) a directory in the current remote directory

sftp is a program for transferring files to and from a remote computer. It is interactive, just like ftp used to be, but uses the secure encryption of ssh.

 

sftp connects and logs into the specified host then enters an interactive command mode

 

$ sftp 10.102.17.200

Leave a Reply