Vim Editor PART-2..!


19) Deletion and Insertion Simultaneously :D
Place the cursor on the alphabet you want to be deleted,type ce and then write what you want to.(Insert mode is on) Now you might be confused in commands rx and ce.
Difference is that rx just replaces the alphabet. and ce deletes the alphabet and takes you to insert mode.
20) Text Entry Commands (Used to start text entry)
a Append text following current cursor position
A Append text to the end of current line
i Insert text before the current cursor position
I Insert text at the beginning of the cursor line
o Open up a new line following the current line and add text there
O Open up a new line in front of the current line and add text there

21)While editing a file, press ctrl + n or ctrl + p and get autocompletion list.

22) THE SUBSTITUTE COMMAND :
a)In command line mode, Move the cursor to the line below marked --->.
b) Type :s/old/new to substitute 'new' for 'old'.Press Enter now. This command only changes the first occurrence of "old" in the line.
c)If you want to substitute Old globally in the line then command is :
:s/old/new/g v d) If you want to change the word globally,
type :#,#s/old/new/g where #,# are the line numbers of the range
of lines where the substitution is to be done.
Type :%s/old/new/g to change every occurrence in the whole file.
Type :%s/old/new/gc to find every occurrence in the whole file,
with a prompt whether to substitute or not.

Summary of point 22 :
To substitute new for the first old in a line type :s/old/new
To substitute new for all 'old's on a line type :s/old/new/g
To substitute phrases between two line #'s type :#,#s/old/new/g
To substitute all occurrences in the file type :%s/old/new/g
To ask for confirmation each time add 'c' :%s/old/new/gc

23) If you want to execute an external command,then type
:!external_command
eg: :!ls , :!dir

24)You can also make and save a file while you are in another file.
eg : If I am in abc file,from there I can make a file cde and save it.
For eg,If you are in INSERT mode,press esc and Command mode will appear,from command mode type
:w cd (where cd is the name of file)

25)If you want to save some text of file in which you are working upon to other file, you can create and save by following method :
a) Move the cursor to this line.

b) Press v (you will go to visual mode) and move the cursor to the fifth item below. Notice that the text is highlighted.

c) Press the : character. At the bottom of the screen :'<,'> will appear.

d) Type w TEST , where TEST is a filename that does not exist yet. Verify that you see :'<,'>w TEST before you press .

e) Vim will write the selected lines to the file TEST. Use :!dir or :!ls
to see it. Do not remove it yet! We will use it in the next lesson.

26) If you want to merge something in file from other file,you will have to first retrieve it and then merge it.This is done by following :

1. Place the cursor just above this line.

2. Now retrieve your CD file using the command :r CD where CD is the name of the file you used.
The file you retrieve is placed below the cursor line.
27) You can also read the output of an external command. For example, :r !ls reads the output of the ls command and puts it below the cursor.
28) Type o(in command line mode) to open a line below the cursor and place you in Insert mode

No comments:

Post a Comment

SAY HELLO!!