Notes For Vi Editor

0 comments

VI editor is the default file editor in most of the Linux/Nix machines. It is having great capabilities to edit a file with in few key strokes.

Lets start with some general information and then move on to some good things what vi editor can do for you while editing a file.
1. Vi stands for visual.
2. Vi have its variants like vim which stands for Vi IMproved, VimX11 for gui and winvi for MS windows.
3. Vi is the most popular editor and next most popular editor is gedit.
4. Do you know there is a book on VI editor from orally which is of 600+ pages.
5. Some other editors which will do the work of editing files are neno, pico, gedit, emacs, joe, nedit, ed etc.

Learning vi editor and remembering them is a very a easy task if you learn it in a systematic way.
a. Modes of VI
b. Navigational commands
c. Editing commands.
d. Search and Replace
e. Save and quiting a file.

a. Modes of VI :
Vi have two mode of operation.
1. Command mode
2. Inserting mode

Command mode :
Vi editor begins in command mode, where cursor movement(navigation in the file) and editing occur. To enter in to command mode from Inserting mode press esc button.

Inserting mode :
Used for entering text, this is similar to notepad in Windows. To enter in to inserting mode you can use any of the following.
i or I => present line
o => one line down the present line
O => one line above

Note : All comments will work in command mode only.

b. Navigational commands :
1. Character navigation k, h, l and j
h => To move one character left.
j => To move one line down.
k => To move one line up.
l => To move one character right.

How to use above commands in clever way?
Examples :
6j => to move 6 lines down from the present courser.
7k => to move 7 lines above from the present courser.

2. Word Navigation
w => word forward.
e =>word forward, but end of the word.
b => one word backward.

Examples :
32w => To move 32 words forward
6b => To move 6 words back.

3. Setting (nu) mbering to lines
:set nu
Removing of (nonu)mbering to lines
:set nonu

4. Moving paragraphs
move one paragraph up => {{
move one paragraph down => }}

5. Moving page up/down
For up => ctrl+b
For down => ctrl+f

6. Moving start/end of the file
Starting of the file(first line => [[
End of the file(last line) => ]]

7. Going to any line :
:lineno

Example :
If we want to go to 56 line then type
:56

c. Editing commands

8. Replace one letter
Replace one letter => r
Delete one letter => x

9. Editing one word
Edit one word => cw
Delete one word => dw

10. Editing one line
Editing a line from courser to the end of that line => d$

11. Cutting
deleting(cutting) one line => dd

Examples :
2dd(deleting/cutting two lines)

12. Pasting
Pasting a line below the courser => p
Pasting a line above the courser => P

13. Coping
Copying one line => yy
Copying n lines => nyy

14. Special commands
joining lines => J
undoing things => u
repeating previous command => .

d. Search and replace

15. Search for a term /term

Example : If you want to search for suresh then press /suresh enter
/suresh
Moving to next occurrence, press "n" with out quotes moving to previous occurrence, press "N" with out quotes.

16. Searching and replacing a term(here separator is / )
:%s/searchterm/replaceterm/g
change default separator
:%s_/home/surya/grade_/home/testing/dest_g

To search and replace particular term from given line to other given line.
:%s294,304/sahana/xyz/g

e)Save and quiting a file
:w => save the file
:q => quit the file
:wq => save and quit
:w! => force save the file
:q! => force quit with out save
:wq => save and quit forcefully


  • Like the post? Please Subscribe to free RSS feed to get updates
  • Red Hat Enterprise Linux 6 Beta Available Today For Public Download

    0 comments

    The long waited Redhat Enterprise Linux version 6 with beta tag is released to public. As of now there are so many downloads happening from FTP server of Redhat. Here is the link to download RHEL6 32 arch and 64 arch.

    Here is the improved features from Redhat in this release :

    Power Management : Tickless kernel and improvements through the application stack to reduce wakeups, power consumption measurement by Powertop, Power Management (ASPM, ALPM), and adaptive system tuning by Tuned, all enhance more efficient system power usage.

    Next Generation Networking : Comprehensive IPv6 support (NFS 4, CIFS, mobile support [RFC 3775], ISATAP support), FCoE, iSCSI, and a new and improved mac 802.11 wireless stack.

    Reliability, Availability, and Serviceability (RAS) : System-level enhancements from industry collaborations make the most of hardware RAS capabilities and NUMA architectures.

    Fine-Grained Control and Management : Improved scheduler and better resource management in the kernel via Completely Fair Scheduler (CFS) and Control Groups (CG).

    Scalable Filesystems : Ext4 file system provides support for larger file sizes and significantly reduces repair times over ext3. XFS® is a high-performance file system that supports extremely large files and is optimized for large data transfers.

    Virtualization : KVM includes performance improvements and new features, sVirt protects the guest and host from unauthorized access, SR-IOV and NPIV deliver high-performance virtual use of physical devices, and libvirt leverages kernel resource management functionality.

    Enterprise Security Enhancement : SELinux includes improved ease of use, application sandboxing, and significantly increased coverage of system services, while SSSD( System Security Services Daemon) provides unified access to identity and authentication services as well as caching for off-line use.

    Development and Runtime Support : SystemTap improvements, ABRT is a new framework for simple collection and reporting of bug information, and improvements are made to GCC (version 4.4.3), glibc (version 2.11.1), and GDB (version 7.0.1).

    And here the press release from Redhat.

  • Like the post? Please Subscribe to free RSS feed to get updates
  • All About info, man, whatis, whereis, --help Commands

    0 comments

    Do you know what dmidecode command will do?
    Ans :
    Are you going to search in google about dmidecode? No need to search boss. No need to go any where. Linux provied many help tools to know more about a command. This post is all about these commands they are as follows.

    1.info command
    2. man command
    3. --help option
    4. whatis command
    5. whereis command

    First command in this list is
    info
    1. info command(Information command) :
    info is a good command which will describe all about the command in detail. Its like lots and lots of pages of information will be there for a single command.

    Example :
    info ls
    The above command will show full help about ls command which is of 10 pages. This will give full information.

    2. man command(manual command)
    This will give little bit less descriptive but will provied information which you require, and most of the times each option of a command will be described in one sentence and some times in paragraphs.

    Example :
    man ls

    3. --help option
    This option is to give one line discription to each option of the command

    Example :
    ls --help
    Please remember --help may present or not present to a command.

    4. whatis command
    This will show one line description to a give command,
    whatis ls

    Last but not least
    5. whereis
    this is not a help command but i feel describing this here. This command will show the location of any command.
    whereis ls

  • Like the post? Please Subscribe to free RSS feed to get updates
  • Archive

    Translate this page

     

    The Linux Juggernaut | Copyright 2006-2009 Surendra Kumar Anne | Surendra's Home Page | Give us feedback how we are doing, Click here