Showing posts with label Vi. Show all posts
Showing posts with label Vi. Show all posts

Saturday, February 11, 2012

Editor VI SET useful preferences


Their HOME directory. vimrc file, create the following additional information is.

set tabstop=2  
set color evening 
set shiftwidth=2 
set expandtab 
set softtabstop = 2 "when converted to a space character tab spacing in units of two spaces shall be deleted
set visualbell "user error warning will flash on the screen once Taishan beep.
set nobackup "does not create a backup file
set cindent "C language uses the indentation style.
set autoindent 
set smartindent "more intelligent use indentation.
set enc = euc-kr 
set incsearch "Enter keywords to search for, use the search progresses. (using Firefox seuseo)
syntax on "syntax highlighting is used
filetype on "file, depending on the type of syntax highlighted.
set background=dark
set backspace=eol,start,indent
set history = 1000 "VI until 1000 to save the edited record.
set hlsearch "search highlighting is used.
set ignorecase "search, edit, or substitution is not case-sensitive.
set showmatch "() {} and parentheses but you can enter a match in the parentheses shows

Tuesday, May 17, 2011

VI EDITOR notes


VI Commands:
i                   insert mode, (ESC to exit insert mode) allows text to be entered on the screen
a                  Append to right mode
/word       Move to the occurrence of “word”
n                 Locate the next occurance
w                Advance to the next word
e                Advance to the next end of a word
b                Move to the previous word
3b        Move backward 3 words
dd        delete line
3dd        delete 3 lines
D        Delete remainder of a line
dw        Delete word
x        Delete character
o        Open space for new line below the cursor line
O        Open a line above the cursor
CTRL-w        Move back a word in append mode
u        Undo last
U        Undo all changes to current line
.        In command mode, repeat the last text changing the command on the current line
:w newfilename        save the file to newfilename from the command mode
:wq        save and quit
:q!        quit without saving
r        replace then typa a character ot be replaced with r then return to break up a line
J        join 2 lines
s        substitute (sentence) typed text over a character, ESC when done
cw        change word
c        change part of a line from the cursor to the end of the line
cc        substitute new text for aline, ESC when done
h        move the cursor back one space
H        move the cursor to the highest line on the screen
L        move the cursor to the lowest line on the screen
M        position the cursor at the midpoint on the screen
G        last line in the file
0 (zero)        Move the cursor to the beginning of the line it is on
view filename        Open a file for viewing only
set number        Turn on line numbers
set nonumber        Turn off line numbers
Options:
number
autoindent (ai)        ctrl-d to move to the left
showmatch        match brackets and parenthesis
tabstop=4
wrapmargine(wm)         when line is wrapped (80-value)
:2 copy 4        Place a copy of line 2 after line 4.
:1,4         copy 7 (lines 1-4)
:n        Access the next file for editing

Wednesday, August 11, 2010

Notes For Vi Editor

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 VIMproved, 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
=> one line down the present line
=> 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.
=> To move one line down.
=> To move one line up.
=> 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
=> word forward.
=>word forward, but end of the word.
=> 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