Sunday, November 27, 2011

Interface


In general, interface is the way just to say something to a media by using another media. Let's take the general life example. TV Remote is the interface because it is the medium to give the command to a TV in order to change the channels or to ON/OFF the TV. Electric switch is also the interface's example.

But in java programming language interface is nothing but the collection of methods with empty implementations and constants variables (variables with static and final declarations). All the methods in an interface are "public and abstract" by default. Since interfaces are abstract in nature so they can not be directly instantiated. To define the methods of an interface the keyword "implements" is used. 

Interfaces are similar to abstract classes but the major difference between these two is that interface have all the methods abstract while in case of abstract classes must have at least one abstract method. Interface combines the two functionality (template and multiple inheritance) of C++ language into one (in itself).  
 
Interface Definition
visibility mode interface InterfaceName {
        constant variable declarations
        
abstract method declarations
}

e.g.
public interface RacingCar {
  
public void startcar (int Obj); 
  
public void changegear (int Obj); 
  
public void incrrace (int Obj);
  
public void stopcar (int Obj);
}

Marker Interface
In java language programming, interfaces with no methods are known as marker interfaces. Marker interfaces are Serializable, Clonable, SingleThreadModel, Event listener. Marker Interfaces are implemented by the classes or their super classes in order to add some functionality.
e.g.  Suppose you want to persist (save) the state of an object then you have to implement the Serializable interface otherwise the compiler will throw an error. To make more clearly understand the concept of marker interface you should go through one more example.  
Suppose the interface Clonable is neither implemented by a class named Myclass nor it's any super class, then a call to the method clone() on Myclass's object will give an error. This means, to add this functionality one should implement the Clonable interface. While the Clonable is an empty interface but it provides an important functionality.

Difference between Interfaces and abstract classes
Some important difference between Interface and abstract classes are given here

    Features                             Interface                             Abstract Class
    Methods An interface contains all the methods with empty implementation.An abstract class must have at least one method with empty implementation.        
   VariablesThe variables in interfaces are final and static.Abstract classes may contain both instance as well as static variables.
    Multiple   Inheritance In java multiple inheritance is achieved by using the interface (by implementing more than one interface at a time)Abstract classes does not provide this functionality.
 Additional Functions  If we add a method to an interface then we will have to implement this interface by any class..In Abstract classes we can add a method with default implementation and then we can use it by extending the abstract class. 
Used WhenAll the features are implemented differently in different objects.When there are some common features shared by all the objects.
Diff
Can’t have ConstructorCan have Constructor

IMP TIP: 
Why u can’t create object for Abstract Class: Since abstract class contains incomplete methods, it is not possible to estimate the total memory required to create an object. So JVM can’t create objects to an abstract class.

Karatsuba algorithm


Key of the Process

The basic step of Karatsuba's algorithm is a formula that allows us to compute the product of two large numbers x and y using three multiplications of smaller numbers, each with about half as many digits as x or y, plus some additions and digit shifts.
Let x and y be represented as n-digit strings in some base B. For any positive integer m less than n, one can split the two given numbers as follows
x = x1Bm + x0
y = y1Bm + y0
where x0 and y0 are less than Bm. The product is then
xy = (x1Bm + x0)(y1Bm + y0)
z2 B2m + z1 Bm + z0
where
z2 = x1y1
z1 = x1y0 + x0y1
z0 = x0y0.

Example

To compute the product of 1234 and 5678, choose B = 10 and m = 2. Then
12 34 = 12 × 102 + 34
56 78 = 56 × 102 + 78
z2 = 12 × 56 = 672
z0 = 34 × 78 = 2652
z1 = (12 + 34)(56 + 78) - z2 - z0 = 46 × 134 - 672 - 2652 = 2840
result = z2 × 102×2 + z1 × 102 + z0 = 672 × 10000 + 2840 × 100 + 2652 = 7006652.

Sunday, November 20, 2011

Enabling JMX on Hibernate.

Here are some instructions for making the Hibernate Statistics JMX MBean available from JBoss.
The example below has been tested with JDK 1.6 and JBoss 4.x.

Then, if you are using Spring, add this to your applicationContext.xml file:



    <bean id="jmxExporter"
        class="org.springframework.jmx.export.MBeanExporter">
        <property name="beans">
            <map>
                <entry key="Hibernate:name=statistics">
                    <ref local="statisticsBean" />
                </entry>
            </map>
        </property>
    </bean> 

    <bean id="statisticsBean" class="org.hibernate.jmx.StatisticsService">
        <property name="statisticsEnabled">
            <value>true</value>
        </property>
        <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

and then set the hibernate.generate_statistics property in your applicationContext-hibernate.xml file:
 <prop key="hibernate.generate_statistics">true</prop>
 

When you browse the MBeans (using JConsole.exe - which lives in the bin dir of your JDK 1.5 
distribution), you should see Hibernate, if you double click on that node, you should see
the Statistics Bean.


Below are a couple of screenshots.


If you are not using Spring, inside StartupListener.java (inside contextInitialized method) add:


import org.hibernate.jmx.*; 
import javax.management.*;
import java.lang.management.ManagementFactory;

try {
    SessionFactory sessionFactory = (SessionFactory)applicationContext.getBean("sessionFactory");
    MBeanServer mbeanServer =
        ManagementFactory.getPlatformMBeanServer();
    ObjectName on =
        new ObjectName("Hibernate:type=statistics,application=appfuse");
    StatisticsService mBean = new StatisticsService()
    mBean.setStatisticsEnabled(true);
    mBean.setSessionFactory(sessionFactory);
    mbeanServer.registerMBean(mBean, on);
}
catch (Exception e) {
    log.error("Error registering Hibernate StatisticsService [" + e.getMessage() "]", e);
}
 

After starting up JBoss, you should be able to attach to the server using JConsole (port 9002, as in the config above). From there, you should see the Hibernate MBean where you can view the statistics that have been collected.

Monday, November 14, 2011

Advanced Commands in Vi





Click here for the Basic VI Commands

General Notes:

1. Before doing anything to a document, type the following command followed by a carriage return: :set showmode

2. VI is CaSe SEnsItiVe!!! So make sure Caps Lock is OFF.


Starting and Ending VI


Starting VI
vi filenameEdits filename
vi -r filenameEdits last save version of filename after a crash
vi + n filenameEdits filename and places curser at line n
vi + filenameEdits filename and places curser on last line
vi +/string filenameEdits filename and places curser on first occurance of string
vi filename file2 ...Edits filename, then edits file2 ... After the save, use :n


Ending VI
ZZ or :wq or :xSaves and exits VI
:wSaves current file but doesn't exit
:w!Saves current file overriding normal checks but doesn't exit
:w fileSaves current as file but doesn't exit
:w! fileSaves to file overriding normal checks but doesn't exit
:n,mw fileSaves lines n through m to file
:n,mw >>fileSaves lines n through m to the end of file
:qQuits VI and may prompt if you need to save
:q!Quits VI and without saving
:e!Edits file discarding any unsaved changes (starts over)
:we!Saves and continues to edit current file



Status


:.=Shows current line number
:=Shows number of lines in file
Control-GShows filename, current line number, total lines in file, and % of file location
lDisplays tab (^l) backslash (\) backspace (^H) newline ($) bell (^G) formfeed (^L^) of current line



Modes


Vi has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for "colon" commands which execute when you press the ruturn key.



Inserting Text


iInsert before cursor
IInsert before line
aAppend after cursor
AAppend after line
oOpen a new line after current line
OOpen a new line before current line
rReplace one character
RReplace many characters
CTRL-v charWhile inserting, ignores special meaning of char (e.g., for inserting characters like ESC and CTRL) until ESC is used
:r fileReads file and inserts it after current line
:nr fileReads file and inserts it after line n
CTRL-i or TABWhile inserting, inserts one shift width

Things to do while in Insert Mode:
CTRL-h or BackspaceWhile inserting, deletes previous character
CTRL-wWhile inserting, deletes previous word
CTRL-xWhile inserting, deletes to start of inserted text
CTRL-vTake the next character literally. (i.e. To insert a Control-H, type Control-v Control-h)



Motion


hMove left
jMove down
kMove up
lMove right
Arrow KeysThese do work, but they may be too slow on big files. Also may have unpredictable results when arrow keys are not mapped correctly in client.
wMove to next word
WMove to next blank delimited word
bMove to the beginning of the word
BMove to the beginning of blank delimted word
^Moves to the first non-blank character in the current line
+ or Moves to the first character in the next line
-Moves to the first non-blank character in the previous line
eMove to the end of the word
EMove to the end of Blank delimited word
(Move a sentence back
)Move a sentence forward
{Move a paragraph back
}Move a paragraph forward
[[Move a section back
]]Move a section forward
0 or |Move to the begining of the line
n|Moves to the column n in the current line
$Move to the end of the line
1GMove to the first line of the file
GMove to the last line of the file
nGMove to nth line of the file
:nMove to nth line of the file
fcMove forward to c
FcMove back to c
HMove to top of screen
nHMoves to nth line from the top of the screen
MMove to middle of screen
LMove to botton of screen
nLMoves to nth line from the bottom of the screen
Control-dMove forward ½ screen
Control-fMove forward one full screen
Control-uMove backward ½ screen
Control-bMove backward one full screen
CTRL-eMoves screen up one line
CTRL-yMoves screen down one line
CTRL-uMoves screen up ½ page
CTRL-dMoves screen down ½ page
CTRL-bMoves screen up one page
CTRL-fMoves screen down one page
CTRL-IRedraws screen
z z-carriage return makes the current line the top line on the page
nz Makes the line n the top line on the page
z.Makes the current line the middle line on the page
nz.Makes the line n the middle line on the page
z-Makes the current line the bottom line on the page
nz-Makes the line n the bottom line on the page
%Move to associated ( ), { }, [ ]



Deleting Text


Almost all deletion commands are performed by typing d followed by a motion. For example, dw deletes a word. A few other deletes are:
xDelete character to the right of cursor
nxDeletes n characters starting with current; omitting n deletes current character only
XDelete character to the left of cursor
nXDeletes previous n characters; omitting n deletes previous character only
DDelete to the end of the line
d$Deletes from the cursor to the end of the line
dd or :dDelete current line
ndwDeletes the next n words starting with current
ndbDeletes the previous n words starting with current
nddDeletes n lines beginning with the current line
:n,mdDeletes lines n through m
dMotion_cmdDeletes everything included in the Motion Command (e.g., dG would delete from current position to the end of the file, and d4 would delete to the end of the fourth sentence).
"npRetrieves the last nth delete (last 9 deletes are kept in a buffer)
"1pu.u.Scrolls through the delete buffer until the desired delete is retrieved (repeat u.)



Yanking Text


Like deletion, almost all yank commands are performed by typing y followed by a motion. For example, y$ yanks to the end of the line. Two other yank commands are:
yyYank the current line
:yYank the current line
nyy or nYPlaces n lines in the buffer-copies
yMotion_cmdCopies everything from the curser to the Motion Command (e.g., yG would copy from current position to the end of the file, and y4 would copy to the end of the fourth sentence)
"(a-z)nyy or "(a-z)nddCopies or cuts (deletes) n lines into a named buffer a through z; omitting n works on current line




Changing text


The change command is a deletion command that leaves the editor in insert mode. It is performed by typing c followed by a motion. For example cw changes a word. A few other change commands are:
CChange to the end of the line
cc or SChange the whole line until ESC is pressed
xpSwitches character at cursor with following character
stextSubstitutes text for the current character until ESC is used
cwtextChanges current word to text until ESC is used
CtextChanges rest of the current line to text until ESC is used
cMotion_cmdChanges to text from current position to Motion Command until ESC is used
<< or >>Shifts the line left or right (respectively) by one shift width (a tab)
n<< or n>>Shifts n lines left or right (respectively) by one shift width (a tab)
<Motion_cmd or >Motion_cmdUse with Motion Command to shift multiple lines left or right



Putting text


pPut after the position or after the line
PPut before the poition or before the line
"(a-z)p or "(a-z)PPastes text from a named buffer a through z after or before the current line



Buffers


Named buffers may be specified before any deletion, change, yank or put command. The general prefix has the form "c where c is any lowercase character. for example, "adw deletes a word into buffer a. It may thereafter be put back into text with an appropriate "ap.



Markers


Named markers may be set on any line in a file. Any lower case letter may be a marker name. Markers may also be used as limits for ranges.
mcSet marker c on this line
`cGo to beginning of marker c line.
'cGo to first non-blank character of marker c line.



Search for strings


/stringSearch forward for string
?stringSearch back for string
nSearch for next instance of string
NSearch for previous instance of string
%Searches to beginning of balancing ( ) [ ] or { }
fcSearches forward in current line to char
FcSearches backward in current line to char
tcSearches forward in current line to character before char
TcharSearches backward in current line to character before char
?strFinds in reverse for str
:set icIgnores case when searching
:set noicPays attention to case when searching
:n,ms/str1/str2/optSearches from n to m for str1; replaces str1 to str2; using opt-opt can be g for global change, c to confirm change (y to acknowledge, to suppress), and p to print changed lines
&Repeats last :s command
:g/str/cmdRuns cmd on all lines that contain str
:g/str1/s/str2/str3/Finds the line containing str1, replaces str2 with str3
:v/str/cmdExecutes cmd on all lines that do not match str
,Repeats, in reverse direction, last / or ? search command



Replace


The search and replace function is accomplished with the :s command. It is commonly used in combination with ranges or the :g command (below).
:s/pattern/string/flagsReplace pattern with string according to flags.
gFlag - Replace all occurences of pattern
cFlag - Confirm replaces.
&Repeat last :s command



Regular Expressions


. (dot)Any single character except newline
*zero or more occurances of any character
[...]Any single character specified in the set
[^...]Any single character not specified in the set
\<Matches beginning of word
\>Matches end of word
^Anchor - beginning of the line
$Anchor - end of line
\<Anchor - begining of word
\>Anchor - end of word
\(...\)Grouping - usually used to group conditions
\nContents of nth grouping
\Escapes the meaning of the next character (e.g., \$ allows you to search for $)
\\Escapes the \ character

[...] - Set Examples
[A-Z]The SET from Capital A to Capital Z
[a-z]The SET from lowercase a to lowercase z
[0-9]The SET from 0 to 9 (All numerals)
[./=+]The SET containing . (dot), / (slash), =, and +
[-A-F]The SET from Capital A to Capital F and the dash (dashes must be specified first)
[0-9 A-Z]The SET containing all capital letters and digits and a space
[A-Z][a-zA-Z]In the first position, the SET from Capital A to Capital Z
In the second character position, the SET containing all letters
[a-z]{m}Look for m occurances of the SET from lowercase a to lowercase z
[a-z]{m,n}Look for at least m occurances, but no more than n occurances of the SET from lowercase a to lowercase z

Regular Expression Examples
/Hello/Matches if the line contains the value Hello
/^TEST$/Matches if the line contains TEST by itself
/^[a-zA-Z]/Matches if the line starts with any letter
/^[a-z].*/Matches if the first character of the line is a-z and there is at least one more of any character following it
/2134$/Matches if line ends with 2134
/\(21|35\)/Matches is the line contains 21 or 35
Note the use of ( ) with the pipe symbol to specify the 'or' condition
/[0-9]*/Matches if there are zero or more numbers in the line
/^[^#]/Matches if the first character is not a # in the line
Notes:
1. Regular expressions are case sensitive
2. Regular expressions are to be used where pattern is specified


Counts


Nearly every command may be preceded by a number that specifies how many times it is to be performed. For example, 5dw will delete 5 words and 3fe will move the cursor forward to the 3rd occurence of the letter e. Even insertions may be repeated conveniently with this method, say to insert the same line 100 times.



Ranges


Ranges may precede most "colon" commands and cause them to be executed on a line or lines. For example :3,7d would delete lines 3-7. Ranges are commonly combined with the :s command to perform a replacement on several lines, as with :.,$s/pattern/string/g to make a replacement from the current line to the end of the file.
:n,mRange - Lines n-m
:.Range - Current line
:$Range - Last line
:'cRange - Marker c
:%Range - All lines in file
:g/pattern/Range - All lines that contain pattern



Shell Functions


:! cmdExecutes shell command cmd; you can add these special characters to indicate:% name of current file# name of last file edited
!! cmdExecutes shell command cmd, places output in file starting at current line
:!!Executes last shell command
:r! cmdReads and inserts output from cmd
:f fileRenames current file to file
:w !cmdSends currently edited file to cmd as standard input and execute cmd
:cd dirChanges current working directory to dir
:shStarts a sub-shell (CTRL-d returns to editor)
:so fileReads and executes commands in file (file is a shell script)
!Motion_cmdSends text from current position to Motion Command to shell command cmd
!}sortSorts from current position to end of paragraph and replaces text with sorted text



Files


:w fileWrite to file
:r fileRead file in after line
:nGo to next file
:pGo to previous file
:e fileEdit file
!!programReplace line with output from program



VI Settings


--noto
Note: Options given are default. To change them, enter type :set option to turn them on or :set nooptioni to turn them off.To make them execute every time you open VI, create a file in your HOME directory called .exrc and type the options without the colon (:) preceding the option
SetDefaultDescription
:set ainoaiTurns on auto indentation
:set all--Prints all options to the screen
:set apawPrints line after d c J m :s t u commands
:set awnoawAutomatic write on :n ! e# ^^ :rew ^} :tag
:set bfnobfDiscards control characters from input
:set dir=tmpdir = /tmpSets tmp to directory or buffer file
:set ebnoedPrecedes error messages with a bell
:set ednoedPrecedes error messages with a bell
:set ht=ht = 8Sets terminal hardware tabs
:set icnoicIgnores case when searching
:set lispnolispModifies brackets for Lisp compatibility.
:set listnolistShows tabs (^l) and end of line ($)
:set magicmagicAllows pattern matching with special characters
:set mesg mesgAllows others to send messages
:set nooption
Turns off option
:set nunonuShows line numbers
:set optoptSpeeds output; eliminates automatic RETURN
:set para=para = LIlPLPPPQPbpPmacro names that start paragraphs for { and } operators
:set promptpromptPrompts for command input with :
:set renoreSimulates smart terminal on dumb terminal
:set remapremapAccept macros within macros
:set reportnoreportIndicates largest size of changes reported on status line
:set ronoroChanges file type to "read only"
:set scroll=nscroll = 11set n lines for CTRL-d and z
:set sh=shell_pathsh = /bin/shset shell escape (default is /bin/sh) to shell_path
:set showmodenosmIndicates input or replace mode at bottom
:set slowslowPospone display updates during inserts
:set smnosmShow matching { or ( as ) or } is typed
:set sw=nsw = 8Sets shift width to n characters
:set tags=xtags = /usr/lib/tagsPath for files checked for tags (current directory included in default)
:set term$TERMPrints terminal type
:set tersenoterseShorten messages with terse
:set timeout
Eliminates one-second time limit for macros
:set tl=ntl = 0Sets significance of tags beyond n characters (0 means all)
:set ts=nts = 8Sets tab stops to n for text input
:set wanowaInhibits normal checks before write commands
:set warnwarn
Warns "no write since last change"
:set window=nwindow = nSets number of lines in a text window to n
:set wm=nwm = 0Sets automatic wraparound n spaces from right margin.
:set wswsSets automatic wraparound n spaces from right margin.



Key Mapping


NOTE: Map allows you to define strings of VI commands. If you create a file called ".exrc" in your home directory, any map or set command you place inside this file will be executed every time you run VI. To imbed control characters like ESC in the macro, you need to precede them with CTRL-v. If you need to include quotes ("), precede them with a \ (backslash). Unused keys in vi are: K V g q v * = and the function keys. Example (The actual VI commands are in blue): :map v /I CTRL-v ESC dwiYou CTRL-v ESC ESC Description: When v is pressed, search for "I" (/I ESC), delete word (dw), and insert "You" (iYou ESC). CTRL-v allows ESC to be inserted
:map key cmd_seqDefines key to run cmd_seq when pressed
:mapDisplays all created macros on status line
:unmap keyRemoves macro definition for key
:ab str stringWhen str is input, replaces it with string
:abDisplays all abbreviations
:una strUnabbreviates str



Other


~Toggle upper and lower case
JJoin lines
nJJoins the next n lines together; omitting n joins the beginning of the next line to the end of the current line
.Repeat last text-changing command
uUndo last change (Note: u in combination with . can allow multiple levels of undo in some versions)
UUndo all changes to line
;Repeats last f F t or T search command
:N or :EYou can open up a new split-screen window in (n)vi and then use ^w to switch between the two.



Return to the top

Basic Commands in VI





Click here for the Advanced VI commands

Modes


Vi has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for "colon" commands which execute when you press the ruturn key.



Quitting


:xExit, saving changes
:qExit as long as there have been no changes
ZZExit and save changes if any have been made
:q!Exit and ignore any changes



Inserting Text


iInsert before cursor
IInsert before line
aAppend after cursor
AAppend after line
oOpen a new line after current line
OOpen a new line before current line
rReplace one character
RReplace many characters



Motion


hMove left
jMove down
kMove up
lMove right
wMove to next word
WMove to next blank delimited word
bMove to the beginning of the word
BMove to the beginning of blank delimted word
eMove to the end of the word
EMove to the end of Blank delimited word
(Move a sentence back
)Move a sentence forward
{Move a paragraph back
}Move a paragraph forward
0Move to the begining of the line
$Move to the end of the line
1GMove to the first line of the file
GMove to the last line of the file
nGMove to nth line of the file
:nMove to nth line of the file
fcMove forward to c
FcMove back to c
HMove to top of screen
MMove to middle of screen
LMove to botton of screen
%Move to associated ( ), { }, [ ]



Deleting Text


Almost all deletion commands are performed by typing d followed by a motion. For example, dw deletes a word. A few other deletes are:
xDelete character to the right of cursor
XDelete character to the left of cursor
DDelete to the end of the line
ddDelete current line
:dDelete current line



Yanking Text


Like deletion, almost all yank commands are performed by typing y followed by a motion. For example, y$ yanks to the end of the line. Two other yank commands are:
yyYank the current line
:yYank the current line



Changing text


The change command is a deletion command that leaves the editor in insert mode. It is performed by typing c followed by a motion. For wxample cw changes a word. A few other change commands are:
CChange to the end of the line
ccChange the whole line



Putting text


pPut after the position or after the line
PPut before the poition or before the line



Buffers


Named buffers may be specified before any deletion, change, yank or put command. The general prefix has the form "c where c is any lowercase character. for example, "adw deletes a word into buffer a. It may thereafter be put back into text with an appropriate "ap.



Markers


Named markers may be set on any line in a file. Any lower case letter may be a marker name. Markers may also be used as limits for ranges.
mcSet marker c on this line
`cGo to beginning of marker c line.
'cGo to first non-blank character of marker c line.



Search for strings


/stringSearch forward for string
?stringSearch back for string
nSearch for next instance of string
NSearch for previous instance of string



Replace


The search and replace function is accomplished with the :s command. It is commonly used in combination with ranges or the :g command (below).
:s/pattern/string/flagsReplace pattern with string according to flags.
gFlag - Replace all occurences of pattern
cFlag - Confirm replaces.
&Repeat last :s command



Regular Expressions


. (dot)Any single character except newline
*zero or more occurances of any character
[...]Any single character specified in the set
[^...]Any single character not specified in the set
^Anchor - beginning of the line
$Anchor - end of line
\<Anchor - begining of word
\>Anchor - end of word
\(...\)Grouping - usually used to group conditions
\nContents of nth grouping

[...] - Set Examples
[A-Z]The SET from Capital A to Capital Z
[a-z]The SET from lowercase a to lowercase z
[0-9]The SET from 0 to 9 (All numerals)
[./=+]The SET containing . (dot), / (slash), =, and +
[-A-F]The SET from Capital A to Capital F and the dash (dashes must be specified first)
[0-9 A-Z]The SET containing all capital letters and digits and a space
[A-Z][a-zA-Z]In the first position, the SET from Capital A to Capital Z
In the second character position, the SET containing all letters

Regular Expression Examples
/Hello/Matches if the line contains the value Hello
/^TEST$/Matches if the line contains TEST by itself
/^[a-zA-Z]/Matches if the line starts with any letter
/^[a-z].*/Matches if the first character of the line is a-z and there is at least one more of any character following it
/2134$/Matches if line ends with 2134
/\(21|35\)/Matches is the line contains 21 or 35
Note the use of ( ) with the pipe symbol to specify the 'or' condition
/[0-9]*/Matches if there are zero or more numbers in the line
/^[^#]/Matches if the first character is not a # in the line
Notes:
1. Regular expressions are case sensitive
2. Regular expressions are to be used where pattern is specified


Counts


Nearly every command may be preceded by a number that specifies how many times it is to be performed. For example, 5dw will delete 5 words and 3fe will move the cursor forward to the 3rd occurence of the letter e. Even insertions may be repeated conveniently with thismethod, say to insert the same line 100 times.



Ranges


Ranges may precede most "colon" commands and cause them to be executed on a line or lines. For example :3,7d would delete lines 3-7. Ranges are commonly combined with the :s command to perform a replacement on several lines, as with :.,$s/pattern/string/g to make a replacement from the current line to the end of the file.
:n,mRange - Lines n-m
:.Range - Current line
:$Range - Last line
:'cRange - Marker c
:%Range - All lines in file
:g/pattern/Range - All lines that contain pattern



Files


:w fileWrite to file
:r fileRead file in after line
:nGo to next file
:pGo to previos file
:e fileEdit file
!!programReplace line with output from program



Other


~Toggle upp and lower case
JJoin lines
.Repeat last text-changing command
uUndo last change
UUndo all changes to line



Return to the top