Linux Unix help !!

"Give respect to Time, One day at right Time, Time will respect You"

Sunday, August 29, 2010

Text Editors

Text editors

In this chapter, we will discuss the importance of mastering an editor. We will focus mainly on the Improved vi editor.
After finishing this chapter, you will be able to:
  • Open and close files in text mode
  • Edit files
  • Search text
  • Undo errors
  • Merge files
  • Recover lost files
  • Find a program or suite for office use

Vi(m)

Vim stands for "Vi IMproved". It used to be "Vi IMitation", but there are so many improvements that a name change was appropriate. Vim is a text editor which includes almost all the commands from the UNIX program vi and a lot of new ones.
Commands in the vi editor are entered using only the keyboard, which has the advantage that you can keep your fingers on the keyboard and your eyes on the screen, rather than moving your arm repeatedly to the mouse. For those who want it, mouse support and a GUI version with scrollbars and menus can be activated.
We will refer to vi or vim throughout this book for editing files, while you are of course free to use the editor of your choice. However, we recommend to at least get the vi basics in the fingers, because it is the standard text editor on almost all UNIX systems, while emacs can be an optional package. There may be small differences between different computers and terminals, but the main point is that if you can work with vi, you can survive on any UNIX system.
Apart from the vim command, the vIm packages may also provide gvim, the Gnome version of vim. Beginning users might find this easier to use, because the menus offer help when you forgot or don't know how to perform a particular editing task using the standard vim commands.

Using the Vim editor

Two modes

The vi editor is a very powerful tool and has a very extensive built-in manual, which you can activate using the :help command when the program is started (instead of using man or info, which don't contain nearly as much information). We will only discuss the very basics here to get you started.
What makes vi confusing to the beginner is that it can operate in two modes: command mode and insert mode. The editor always starts in command mode. Commands move you through the text, search, replace, mark blocks and perform other editing tasks, and some of them switch the editor to insert mode.
This means that each key has not one, but likely two meanings: it can either represent a command for the editor when in command mode, or a character that you want in a text when in insert mode.
Note Pronunciation
  It's pronounced "vee-eye".


Commands that switch the editor to insert mode:
  • a will append: it moves the cursor one position to the right before switching to insert mode
  • i will insert
  • o will insert a blank line under the current cursor position and move the cursor to that line.
Pressing the Esc key switches back to command mode. If you're not sure what mode you're in because you use a really old version of vi that doesn't display an "INSERT" message, type Esc and you'll be sure to return to command mode. It is possible that the system gives a little alert when you are already in command mode when hitting Esc, by beeping or giving a visual bell (a flash on the screen). This is normal behavior.

Basic commands

 Moving through the text is usually possible with the arrow keys. If not, try:
  • h to move the cursor to the left
  • l to move it to the right
  • k to move up
  • j to move down
SHIFT-G will put the prompt at the end of the document.
ctl+s -- stop   ctl+q --resume

Basic operations
These are some popular vi commands:
  • n dd will delete n lines starting from the current cursor position.
  • n dw will delete n words at the right side of the cursor.
  • x will delete the character on which the cursor is positioned
  • :n moves to line n of the file.
  • :w will save (write) the file
  • :q will exit the editor.
  • :q! forces the exit when you want to quit a file containing unsaved changes.
  • :wq will save and exit
  • :w newfile will save the text to newfile.
  • :wq! overrides read-only permission (if you have the permission to override permissions, for instance when you are using the root account.
  • /astring will search the string in the file and position the cursor on the first match below its position.
  • / will perform the same search again, moving the cursor to the next match.
  • :1, $s/word/anotherword/g will replace word with anotherword throughout the file.
  • yy will copy a block of text.
  • n p will paste it n times.
  • :recover will recover a file after an unexpected interruption.

Hope you Like it:        

  
                                                                                   29 aug 2010
                                                                              --Shirish Shukla

2 comments:

  1. Shirish please post some for vim & vi diff and abt mcedit

    - gyan

    ReplyDelete
  2. what are the other gui editors available

    ReplyDelete

Write Here .. your comments are always wellcome ..but no spam please !!

Followers

Pls LIKE my Story !!!