Friday, 6 January 2012

Linux Vim Editor, Vim editor commands

1. Vim 

· How can you cause vim to enter Input mode? How can you make vim revert to Command mode? 
Using “i” for input mode and “esc” for revert to command mode. 

1. To get into the input mode you press either ‘a’ or ‘i’ key. And to revert back to the command mode you press the ‘escape’ key

· What is the Work buffer? Name two ways of writing the contents of the Work buffer to the disk. 
The Work buffer is the area of memory where vim stores the text you are 

editing. A”:w” command writes the contents of the work buffer to disk but 
does not end your editing session. A ZZ command writes the contents of 
The work buffer to disk and ends your editing session. 

2. Vim stores the text being edited in the work buffer. 

:w command writes the contents of the work buffer to disk but does not end the editing. 

ZZ command writes the contents of the work buffer to disk and ends the editing. 

· While working in vim, with the cursor positioned on the first letter of a word, you give the command x followed by p. Explain what happens. 
The commands exchange the first two letters of the word. First the x 
command copies the character the cursor is on to the General-Purpose 
buffer and deletes the character, leaving the cursor on the character to the 
right of where the deleted character was. Then the p command inserts the 
contents of the General-Purpose buffer after the character the cursor is on. 

3. The position of the first two characters are swapped. X command deletes the first letter and places it on the buffer. The cursor is then moved to a new position and when the p command is given the letter from the buffer is removed and placed to a new position i.e after the first letter. 

· What are the differences between the following commands? 

a. i and I 
i=Insert before cursor. 

I=Insert to the start of the current line. 

i : insert cursor at the current position. 

I :insert cursor at the beginning of the line. 

b. a and A 

a=Append after cursor. 

A=Append to the end of the current line. 

a : append after cursor. 

A :append at the end of line. 

c. o and O 

o=Open a new line below and insert. 

O=Open a new line above and insert. 

o : Open a new line below and insert. 

O : Open a new line above and insert. 

d. r and R 
r=Overwrite one character. After overwriting the single character, go back to command mode. 

R=Enter insert mode but replace characters rather than inserting. 

r : Replace character 

R : Overwrite characters from cursor onward 

e. u and U 

u=Undo the last action. 

U=Undo all the latest changes that were made to the current line. 

u : Undo last change 

U : Undo all changes to entire line 

· Which command would you use to search backward through the Work buffer for lines that start with the word it? 
Give the command ?^itRETURN to search backward (?) for a line beginning 
with (^) it. 
5. ?^it 
· Which command substitutes all occurrences of the phrase this week with the phrase next week? 
:s/this week/next week/g 
6. :s/this week/next week 

· Consider the following scenario: You start vim to edit an existing file. You make many changes to the file and then realize that you deleted a critical section of the file early in your editing session. You want to get that section back but do not want to lose all the other changes you made. What would you do? 

This problem assumes that you have not written out the Work buffer since 
you deleted the critical section. There are a few ways to approach this 
problem. To be safe, make copies of the Work buffer and the original file 
under names other than the name of the original file. That way, if you 
make a mistake, you can easily start over. For example, give the command 
:wq changedfile to save the work buffer as changedfile, and exit from vim. 
Then use cp to copy the original file to, for example, file.orig and 
changedfile to changedfile.orig. Start vim with the following command, 
which instructs it to edit the original file first and the modified file second: 
$ vim originalfile changedfile 
Once you are editing the original file, search for and copy the part of the 
file you want to save into a Named buffer. For example, to save five lines, 
starting with the line the cursor is on, into the Named buffer a, give the 
command "a5yy. Then edit the modified file by giving the command 
:n!RETURN (edit the next file without writing out the Work buffer). Position 
the cursor where you want to insert the text, and give the command "ap or 
"aP, depending on where you want to place the copied text. 

How can you move the current line to the beginning of the file? 
We can move to the beginning of the file using “H” command. 
8. “H” command.


Ajay Jain said...

:m 0 try this one for move the current line to the beginning of the file

Natasha Nazeer said...

Shuaa Digest November 2018 Free Download
Shuaa Digest Download

Read Online Books And Online Results

Read Online Books Online Library for Urdu Novels Famous Urdu Novels Download PDF Urdu Novels.Board of Intermediate & Secondary Education Results from all Pakistani boards prize bond draw list Prize Bond results.

Read Online Books
Read Online Digest
Read Online Novels
Read Online Magazine

Post a Comment

Free Host | lasik surgery new york