Skip to main content

Unix Vi Editor commands

To Start vi
1. vi filename Create or Edit filename starting at line 1
2. vi -r filename Recover filename that was being edited
when system crashed

To Exit vi
1. :x<return> Quit vi, writing out modified file to file
named in original invocation
2. :wq<return> Quit vi, writing out modified file to file
named in original invocation
3. :q<return> Quit or exit vi
4. :q!<return> Quit vi even though latest changes have not
been saved for this vi call

 cursor Movment
1. j or <return>
[or down-arrow]
Move cursor down one line
2. k[or up-arrow] Move cursor up one line
3. h or<backspace>
[or left-arrow]
Move cursor left one line
l or<space>[or right-arrow] Move cursor right one line
4. 0(zero) Move cursor to start of current line(the one
with the arrow)
5. $ Move cursor to end of the current line
6. w Move cursor to beginning of next word
Basic vi commands7. b Move cursor back to beginning of preceding
8. :0<return> or 1G Move cursor to first line in file
9. :n<return>or nG Move cursor to line n in file
10. :$<return>or G Move cursor to last line in file

Screen movement
1. ^f Move forward one screen
2. ^b Move backward one screen
3. ^d Move down(forward) one half screen
4. ^u Move up(back)one half sreen
5. ^l Redraws the screen
6. ^r Redraws the screen,removing the deleted

Text Editing
1. u Undo whatever you just did(a simple toggle)
Inserting or Adding text
1. i Insert text before cursor,until<esc>hit
2. I Insert text at beginning of current
3. a Append text after cursor,until<esc>hit
4. A Append text to end of current
5. o Open and put text in a new line below
current line,until<esc>hit
6. O Open and put text in a new line above
current line,until<esc>hit

Basic vi commandsChanging the text
1. r Replace single character under cursor(no
2. R Replace characters,starting with current
cursor position,until<esc>hit

3. cw Change the current word with new
text,starting with the character under

4. cNw Change N words beginning with the
character under cursor,until<esc>hit

5. c change(replace)the characters in the current line,until<esc>hit

6. cc change(replace)the characters in the current line,stopping when <esc>hit

7. Ncc or cNc change(replace)the next N lines,starting
with the current line,stopping when

Deleting the text
1. x Delete single character under cursor
2. Nx Delete N characters, starting with character
under cursor
3. dw Delete the single word beginning with
character under cursor
4. dNw Delete N words beginning with character
under cursor
5. D Delete the remainder of the line,starting
with current cursor position
6. dd Delete entire current line
7. Ndd or dNd Delete N lines beginning with the current
Basic vi commandsCutting and pasting the text
1. yy Copy (yank,cut) the current line into buffer
2. Nyy or yNy copy(yank,cut) the next N lines,including
the current line, into the buffer
3. p put(paste) the lines in the buffer into the
text after the current line

Searching the text
1. /string Search forward for occurence of string in text
2. ?string Search backward for occurence of string in text
3. n Move to next occurence of search string
4. N Move to next occurence of search string in opposite direction

Determining line numbers
1. :.= Returns line number of current line at bottom of screen
2. := Returns the total number of lines at bottom of the screen
3. ^g Provides the current line number, along with the total number of lines,in the file at the bottom of the screen

Saving and reading files
1. :r filename<return> Read file named filename and insert after
current line(the line with arrow)

Basic vi commands

2. :w<return> Write current contents to a file named in
original vi call

3. :w newfile<return> Write current contents to a new file named

4. :12,35w smallfile<return> Write the contents of the line numbered 12
through 35 to a new file named smallfile
5. :w! prevfile<return> Write current contents over a pre-existing
file named prevfile


Popular posts from this blog

Conversion from Clob To String in java and Vice versa

/***reading Clob data from oracle table and setting to Pojo**/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import oracle.sql.CLOB;


public class MessageDao {
private static String url = "jdbc:oracle:thin:@";
private static String username = "ABC123";
private static String password = "ABC123";

public  List readClobToBO() throws Exception {

Connection conn = DriverManager.getConnection(url, username, password);
PreparedStatement stmt = conn
ResultSet resultSet = stmt.executeQuery();
List msgList= new ArrayList();

while ( {

StagedMessage message = new StagedMessage();


Portable Java 8/ JDK8 setup without admin rights

Some time we got machine to work where we don't have access rights to install anything or if you do not want to install. You can get latest jdk running by this trick. Just follow step step & do comment if you like it.

Step by Step details to get running java from .exe setup without any admin rights. Get portable 7 zip from portableapps.comdownload java 8 from oracle 7 zip & extract jdk-8u102-windows-x64.exeyou will see below folders                .data                .pdata                .rdata                .reloc                .rsrc                .text                CERTIFICATE

          5.Go inside E:\jdk-8u102-windows-x64\.rsrc\1033\JAVA_CAB10you will find 111 file.

         6.extract it it some folder where you can find again extract that to some folder say Java & copy it to very first folder of setup along with .data,.rsrc etc.
         7.Go to folder where you have co…

GOF Design pattern with Java & Real World Examples

What are design patterns? 

So basically these are just collection of best practices to solve recurring problem by different kind of class arrangement. These arrangement could be based on creation of object or structural basis or on basis of required behavior.

Creational Design Pattern
Prototype Designpattern we will like to use this designpattern whenever creation of initial object & setting required default values is costly. So we just create 1 object & later on whenever more objects required we can provide initial object by just cloning of given object.Java Example is java.lang.Object#clone()
Builder DesignPattern When we jave object structure are complex and complicated we would go for this. we will be separating object creation from internal representation. With help of some simple interface we would create complicated Object.
Singleton When we need one instance per JVM. Example : Java Run time environment Java.lang.System.  java.lang.StringBuilder, Spring Beans are singleton …