http://goo.gl/EmKxy0

Home > UNIX > Vi Editor – Part 2

Vi Editor – Part 2

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 “.”

Check the Sybase Wiki @ sybasewiki.com
Categories: UNIX Tags:
  1. No comments yet.
  1. No trackbacks yet.