Problem 6
———
How to copy range of lines from a file to another?
Solution 6
———-
Suppose i want to copy 50 lines from line number 15 to 64, then open file in vi editor in command mode then follow below command
:15,64w file2.txt
Additionally,
For single line –> :10w file2.txt
For current line where cursor is positioned –> : .w file2.txt
For last line –> :$w file2.txt
For current line to end –> : .,$w file2.txt
Problem 7
———-
What are repeat factor and how to use in navigation?
Solution 7
———
k — move cursor up
j — move cursor down
h — move cursor left
l — move cursor right
if want to move 5 lines up then use “5k” this is called repeat factor.
Problem 8
———
how to navigate among words in a line?
Solution 8
———-
Problem 9
———
How to do “copy and paste” in vi editor?
Solution 9
———-
Open a file in vi editor in command mode,
y — copy single character
yy — copy current line
15yy — copy current line and 14 lines below
p – paste text on right
P – paste text on left
NOTE: p and P paste text on right and left when delete single character of line. However, same keys paste “below” and “above” when delete complete line.
Problem 10
————
How to join lines?
Solution 10
————
Use “J” in command mode. Additionally, if want to join current line and 5 lines below current line then use “6J” (called repeat factor)
Problem 11
———–
How to discard all changes in a line before moving away from the line.
Solution 11
———–
Use “U” in command mode
Problem 12
———–
How to repeat last command?
Solution 12
———–
Use “.” in command mode. For e.g. if you have deleted 3 lines using “3dd” then you can delete 3 lines again and again by pressing “.”
Sybase Blog -Anything About Sybase ASE,REP,IQ.
Wednesday, December 29, 2010
Vi Editor – Part 1
Basic Vi Editor commands
————————
Problem 1
———
How to do the undo in Vi editor?
Solution 1
———-
Go to command mode and press “u” to undo the last action.
Problem 2
———
How to convert lines into comments?
Solution 2
———
Use “I” and “A”
“I” inserts at the beginning of line.
“A” appends at the end of line.
So press “I” and type /* then [Escape] and then press “A” and type */ then [Escape]. Due to this each line can be converted to comment.
Problem 3
———
How to insert lines above and below the current line without placing the cursor at the start and end of line?
Solution 3
———-
Use “o” and “O”
open a file in command mode and press “o” which inserts a new line below the current line.
Open a file in command mode and press “O” which inserts a new line above the current line.
Problem 4
———
What is the difference between s,S,r,R in command mode?
Solution 4
———
r –> Replaces a single character with one character.
R –> Replaces all text on the right of the cursor position.
s –> Replaces a single character with many.
S –> Replaces the entire line irrespective of cursor position.
Problem 5
———
How to save and quit in one character?
Solution 5
———
Use “:x” in command mode.
————————
Problem 1
———
How to do the undo in Vi editor?
Solution 1
———-
Go to command mode and press “u” to undo the last action.
Problem 2
———
How to convert lines into comments?
Solution 2
———
Use “I” and “A”
“I” inserts at the beginning of line.
“A” appends at the end of line.
So press “I” and type /* then [Escape] and then press “A” and type */ then [Escape]. Due to this each line can be converted to comment.
Problem 3
———
How to insert lines above and below the current line without placing the cursor at the start and end of line?
Solution 3
———-
Use “o” and “O”
open a file in command mode and press “o” which inserts a new line below the current line.
Open a file in command mode and press “O” which inserts a new line above the current line.
Problem 4
———
What is the difference between s,S,r,R in command mode?
Solution 4
———
r –> Replaces a single character with one character.
R –> Replaces all text on the right of the cursor position.
s –> Replaces a single character with many.
S –> Replaces the entire line irrespective of cursor position.
Problem 5
———
How to save and quit in one character?
Solution 5
———
Use “:x” in command mode.
Subscribe to:
Posts (Atom)