Monday, September 27, 2010

How to edit text with VI/VIM text editor in Linux.

On windows system you can use Notepad to edit the text with format .txt. While in Linux, to edit the text using the application VI/VIM Builder. But not everyone knows how to use VI. For that, this time i wrote down how your program how to use the VI text editor in Linux. Let's look at together.


Vi editor has many facilities that are helping programmers, but novice users because they avoid Vi editor considers it very difficult and confusing. This chapter intended to introduce the novice user to the editor Vi. Why Using Vi Here are some reasons 



why you use Vi

  • Vi generally available on every UNIX system, so if you Vi mastered, it will be easy to do task editing on every UNIX system.
  • Vi is free, you are free to use and view the source code. 
  • Vi can be customized to your needs, because the available files configuration. If you are still not satisfied, maybe you can change the source code according to your needs.
  • Vi-sized much smaller than the Emacs editor.
Vi Version The following is a
list of some of the available versions of Vi: 
Unix MSDOS Windows 3.x Windows 95/98/NT Vim
vim5.6src.tar.gz vim56d16.zip Use gvim56.zip MSDOS Elvis elvis2.1_4.tar.gz elvis2.1_4msdos.tar.gz
Not Available elvis2.1_4win32.tar.gz Vile vile9.1.tgz vil91w32.zip vil91dos.zip Not Available Lemmy Not Available Not Available Not Available lemmy40.exe Nvi nvi1.79.tar.gz
Not Available Not Available Not Available Stevie stevie69x.zip3 
Not Available Not Available Not Available WinVi Not Available Not Available WinVi16e.zip WinVi32.zip xvi Not Available Not Available xvi.zip xviexe.zip Pvic pvic_dos.zip Not Available Not Available Not Available Calvin calvin23.zip Not Available Not
Available Not Available.


Before Starting Vi
Vi Editor utilize the whole screen, so he needs to know the type terminal you have. So that when a when you do not Vi can start because of the type terminals that do not match, then you need to change your terminal type. For example if you have a terminal type vt100, for change your terminal set in the
UNIX shell is as follows:
For the C Shell (/ bin / csh), the command is as follows: set term = vt100 

For Bourne Shell (/ bin / sh or / bin / bash) or Korn Shell (/ Bin / ksh), the command are as follows:
TERM= vt100 export TERM 


Starting and Ending a Vi.
Vi Editor lets users create a new file or edit existingfile. 
To start vi from the shell enter the command tedi: tedi $ vi 
If successful, it then will appear:




~~
~VIM Vi Improved~ 
~
version 5.4
~~

~by Bram Moolenaar et al. Vim is Freely distributable
~type: help uganda if you like Vim    ~type: q to exit

~type: help or for online help
~type: help version5 for version info






 The screen indicates that Vi is ready for use. You can start vi editor without entering a file name, but if you want to save your work, you need to tell Vi your file name to save it. To edit an existing file, the command given is "Vi filename". On the left side of the screen will appear tilde (). In the bottom of the screen, you will see the name of the file you are editing, as well as file size, as shown in the followingexcerpts: 
"Filename" 21 lines, 385 characters Vi To end, press and then type: q If successful then you will go back to the shell. Navigation Direction in Vi To move the cursor in the vi editor, you can use buttons buttons as follows: k h l j


Instructions:
H button on the left, to move to the left. L button on the right and to move to the right. J keys like the down arrow In Vi the new version, these functions can also be done by using the directional keys found on keyboards. In addition there are also several commands for cursor movement the others are:


g: to switch to a particular row. 
^ F: move down one full screen.
^ B: move one screen full up.
^ D: move half a screen down.
^ U: move half a screen to the top.
^ W: move one word forward.
^ B: to move one word backward. 
^ Sign is a sign of the Ctrl key, ^F means you have to press the Ctrl key simultaneously with key button F.


Editing Text Entering Text To enter text enter the command i (insert) with the first first switching to command mode (press ESC). At the bottom of the screen will message appears as follows: INSERT


This indicates that Vi is ready to receive the text to your enter. You then can enter the text you want.
With command i then added the text to be inserted before the position cursor today. Additionally there is also a command that will add text after the current cursor position. Two commands The next that can also be used to enter text is o and O commands odigunakan command to open a newline after current
line and add text, while the O will open the newline before the current line and add text.


Deleting Text
There are times in editing, we want to remove a text. In Vi text deletion can be done in several ways among others are:
Delete characters one by one
Deleting a single row To be able to delete characters one by one to be conducted in command mode by pressing the button and then pressing the x at the time cursor on the character you want to delete. To be more clear note the following excerpts, here you
want to delete the character "a" the word "regular." 
Initial state: 
I do not usual
~


--INSERT--
 The situation at the time of switch to command mode and give the command xpada time cursor is in the second letter from the end of the line and delete one character "a": 
I do not usual 
~


The situation after one character is deleted: 
I can not 
~


In addition, the elimination of a character can also be
done on the mode insert by pressing a button. Note the following excerpts: 
Initial state: 
I do not usual
~


--INSERT-- 
Then move the cursor until the character you want erased. Then press the button once. 
The result is: 
I can not 
~


Sometimes required the elimination of a whole row, then deletion one line by deleting a single character one by one, of course, very unpleasant and inefficient, for this requirement
Vi provides the dd command. To be able to run it we first need to go into command mode and then pressing the dd. To be more jelanya note The following excerpts: 
Here is deleted the line containing the phrase "me too". 


I do not usual 
I also



--INSERT--
The first step to do is go to command mode by pressing button. If successful then at the bottom of the screen is no longer there writing "- INSERT -". 
I do not usual 
I also 
~


The next step is to put the cursor on the row you want deleted and press the button dd. If successful, then the line desired
has been deleted. 
I do not usual 
~


Canceling commands (Undo command)
 To undo the last command can be done by pressing u. Meanwhile button to cancel the entire order press the button U. Consider the following example: I do not usual Then the letter "a" last we delete by pressing the x in command mode. The result is as follows: I'm not used 
However, we still need the text in circumstances that have not been repaired. To restore the text or in other words to undelete a fruit characters, can be done by pressing the u (undo) in command mode. The result after the cancellation command is:
I do not usual


Putting Text (Put)
 If you want to put the text can be done by first used to remove the text, then put it back with the command put, that is by pressing the button p. Consider the following text snippet:

  • 2 of this two 
  • 1 this one 
  • These four 
  • 3 is three 
The text is in a state that is not sequential, we want sort text, langkahlangkahnya are as follows: 


• Switch to the command mode by pressing the button 
• Delete the line containing the text 2 with dd command 
• Place the cursor in the row containing the text 1 
• Press the p (put). 


The result is as follows: 
1 this one 
2 of this two 
4 These four 
3 is three 


• Place the cursor in the row containing the text 4 
• Remove these lines using dd 
• Place the cursor in the row containing the text 3 
• Press the p 
• Text has been sorted. 


The result after sorted are: 
1 this one 
2 of this two 
3 is three 
4 These four 


Operations on Files 
Saving Files 
To save the text that you've had your fill or edit, can be done with
a switch to command mode and give command: w (colon w), after which the text will be saved and you able to continue your work. This command can be accompanied also by other commands, especially command "quit", thus to save the file and then exit from vi editor can be done by giving the command :wq
If you have not named your file, it can be done by give orders: :W filename


Opening Files To open
an existing file can be done by giving command: e (point two e). Files are opened and then will appear in screen. Insert a File To insert a file into your current file edit, it can be done by giving the command:r FILENAME. After giving This command then the file FILENAME will be inserted in the file are you edit by following the location of the cursor. Finding Words / Sentences Vi editor has two kinds of searches: searches the character and search word. To search for words used commands / and?. When
you give this command, at the bottom of the screen you can enter the word you want to search. 


The second difference is the command is that the command / forward while looking in? search is backward. That is the command / search from the current cursor until the end of the document, while the command? search from current cursor until the beginning of the document. command n and N are used to repeat search before in the same or opposite direction. Some characters have special meaning to the Vi editor, so they need preceded by the sign "(backslash) if you want to be included in the search. Special Character ^ Beginning of line. (At the beginning of the search expression.) Search the characters looking characters entered after the command. F and F commands search for the characters only on the current line. F looking for a forward while
looking in a backwards F and cursor will move to the character found. t and T commands search characters only on the current line, but to command cursor t move into position before the character,while the T looking for backward to the position after the character. Both sets of commands can be repeated by using the command; or,. Command; repeat the last character search command in the direction Similarly, while, repeat the search command in the opposite direction. 


Vi Editor Configuration 
You can configure your Vi editor at the time he started. There are several options can be set using the command: set the mode edit. Here These are some of the fruits of options available (can
you get by typing : Set all and press Enter key in command mode): noautoindent magic noshowmatch AutoPrint mesg noshowmode noautowrite nomodelines noslowopen nobeautify nonumber tabstop = 8 directory = / tmp nonovice taglength = 0 nodoubleescape nooptimize tags = tags / usr / lib / tags noedcompatible paragraphs term = xterm prompt noerrorbells noterse noexrc noreadonly timeout flash redraw timeoutlen = 500 hardtabs = 8 remap ttytype = xterm noignorecase report = 5 keyboardedit
warn scroll = 11 window = 23 keyboardedit! sections wrapscan nolisp shell = / bin / csh wrapmargin =0 nolist shiftwidth = 8 nowriteany Some of these options have a value that can be set with the sign "=" in it, while others will be set or not set (this option is an option called Boolean and has a "no" in front
of it to indicate that they are not set). Explanation of some of the commands above will be given below,with a abbreviations. For example, the command set autoindent, you can wrote:: set autoindent or: set ai. To mengunsetnya, you can typing: set noautoindent or: set noai. autoindent (ai) option is used to set
the editor so that lines that follow the lines will have the indentation terindent same as the previous line. 


indentation width can be determined with shiftwidth. Recovering Your Work When There was a thing that is not desired with your Terminal. Vi editor to edit a temporary copy of your file, and after the process editing is complete, or when you save it, he put a copy of while those to the original file. If there is something problem when you are editing, editor Vi will try to save jobs that exist, and trying to return it to the rescue in time come. 


Note: If Vi stops when you're working on any files, it will email you how restore it. Commands -r stands for recovery. If you're editing the file daftarnilai and suddenly you come out, then -r command will be very helpful. The syntax is as follows vi -r daftarnilai. After using -r once, you should save what you earn. -r command only works once for each session that failed.

2 comments:

  1. A Plain Text Editor
    Plain Text files
    That's right, if you're writer on a budget, you don't need to spend any money buying expensive writing software or apps. Instead, you can use the text editor that comes free with your operating system.
    Just open up Notepad on Windows or TextEdit on a Mac. I like plain text editors for writing something short quickly and easily, without thinking much about it. I wrote a blog post about the benefits of using plain text editors as writing software.
    Use for: writing whatever, wherever

    ReplyDelete
  2. A Plain Text Editor
    Plain Text files
    That's right, if you're writer on a budget, you don't need to spend any money buying expensive writing software or apps. Instead, you can use the text editor that comes free with your operating system.
    Just open up Notepad on Windows or TextEdit on a Mac. I like plain text editors for writing something short quickly and easily, without thinking much about it. I wrote a blog post about the benefits of using plain text editors as writing software.
    Use for: writing whatever, wherever

    ReplyDelete