Java Reference
In-Depth Information
Table 2.2 Some useful vi substitutions
Command
Explanation
:1,$s/ *$//
Removes all (any number of) trailing blanks—that is, looks for zero or
more blanks followed immediately by the end of line, and replaces
them with nothing (no characters between the last two slashes).
:1,$s/^.*$/""/
Puts quotes around the text of each and every line.
:1,$s/^"//
Removes the leading quote from any line that starts with one.
:1,$s/"$//
Removes the trailing quote from any line that ends with one.
There is so much more that could be said about regular expressions. They
are one of the most powerful features for making big changes with few
keystrokes. It's an integral part of sed , Perl, and other tools. It's in such demand
that it has been added to Java for better pattern matching. See Section 2.6 for
ways to learn more about regular expressions.
Starting Off Right: .exrc
2.2.4
You can preset certain behaviors in vi by putting ex commands in a file called
.exrc in your home directory. Those commands will be read whenever you
invoke vi and before you begin typing commands.
Here's a simple but useful .exrc example:
" set my favorite options:
set autoindent shiftwidth=4
set ignorecase
As you can see from the example, settings can be combined on one line.
Note also that these lines do not begin with a colon. A colon is needed if you
type these lines from within vi —because you need to get into ex mode; but
since these are assumed to be ex commands (hence the name .exrc ) they are
going straight to the ex side of vi and no colon is needed. Comment lines
begin with a double quote; the rest of the line is ignored, and doesn't need a
matching quote.
The ignorecase command tells vi to ignore any difference between
upper- and lowercase characters when searching for text with the / or ? com-
mands. The single character searches on the current line ( f and F ) are not
Search WWH ::




Custom Search