A little of the magical stuff that makes vi such a useful tool for editing text files and such.

By now everyone knows / starts up the search function, but did you know it can also do a search and replace? (more on that in a moment)

A quick review of some advanced search functions;

/s
would move the cursor to the first instance of ’s’ in the text, hit n to repeat the last command (in this case search for s)… not very efficient in most cases so read on.

/[a-z]s
is a little more specific, the search will look for any instance of s but preceded by a litter a - z. Try different combinations and you will find the pattern matching can be very precise with only a few keystrokes. This is not pico or nano, so case is sensitve.

/[^c]tem
will search for any tem preceded by any character other than a c.

/^[A-Z].*\. *$

will search for any line that begins with a capital letter and ends with a period and any number of blanks

All of the above patterns can be used to as part of search and replace (or find and replace for this coming from windoze) pattern matching.

:s/search_string/replacement_string/g

This command replaces every search_string on the current line with replacement_string. Omitting the g (global) flag at the end of the command will cause only the first occurrence of search_string to be altered. Often you may wish to confirm each replacement. This can be done with the confirm flag c. The confirm flag should be placed after or in place of the g flag. Suppose I had the following line:

Give a young man a hammer… and he’ll find something to bash

and typed

:s/find something to bash/bash something to bits/

I would be left with

Give a young man a hammer… and he’ll bash something to bits

Any command that begins with a “:” is called a line mode command and performs its duty on the line the cursor is currently on. However, you can override vi’s default of operating only on the current line by preceding them with a range of line numbers. For example, if I wanted to replace guy with gal on lines 32 through 56 I would type

:32,56s/guy/gal/g

Omitting the g would cause only the first occurrence of guy in each line to be replaced. The “.” and “$” play a special role in this sort of designation. “.” indicates the current line, and “$” indicates the last line of the file. Therefore, if I wanted to delete1 from the current line to the end of the file I would enter:2

:.,$d

I could even do something like:

:.,/Fred/d

which would delete from the current line to the next line that contained Fred.

One other shortcut that might be worth mentioning is that 1,$ and % both indicate all the lines in the file. Therefore,

:1,$s/search_string/replacement_string/g

and

:%s/search_string/replacement_string/g

do exactly the same thing.

—————————–
The marketing companies working for different businesses are also sponsoring affiliate program marketing to promote their products and services. The computers software are used to build effective websites and now with a lot of companies are offering free web hosting services to the customers to promote online trading. The internet phone is used to by the buyers and the sellers to talk at cheap rates. The online backup uses a script to follow step by step procedures to streamline the processes.