Java Reference
In-Depth Information
Change does the delete, then puts you in input mode. (Notice the re-
minder on the status line.) Remember, to get out of input mode and back into
vi mode, press the Escape key.
Sometimes you've done too much, and you'd like to undo what you've
just done. Typing u will undo the last change that you made. But here's a dif-
ference between the classic vi and some of the new, improved versions. In classic
vi , if you type another u , then you are telling vi to undo what it just
did—which was an undo. So the undo of an undo remakes the change that you
had originally made. But in vim , “vi improved,” typing u again and again will
just keep undoing previous changes. If you want to undo the undo, in vim ,
you need to type :redo and then Enter.
The vi editor has shortcuts for helping you to change the indentation of
your code. Typing two less-than signs ( << ) will shift the line to the left; typing
two greater-than signs ( >> ) will shift the line to the right. Typing a number
first and then the less-than or greater-than signs will shift that many lines at
once. But how far will they shift? The default is usually set at eight, but you
can set it to any value you want. In ex mode you can set all sorts of values and
flags, customizing vi 's operation. The value we're interested in here is
shiftwidth which can be abbreviated sw . So the command would be :set
sw=4 if you want each shift to move by four characters. For more about this,
and how to make it your default, see Section 2.2.4.
Any command that you do may be worth repeating. Say, you just shifted
14 lines and you'd like to shift them further. Or you just deleted five lines, and
would like to delete five more. Well, you could just retype the command, but
an easier way is just to type the period ( . ) and let vi repeat it for you.
2.2.1
There are three ways of exiting vi ( ZZ , :q , :q! ) that you should know. The
correct one to use depends on whether or not you want to save the changes to
the file and on whether or not you have saved your changes.
Exiting
ZZ saves and quits in one step (three keystrokes).
:w writes what you've been editing but doesn't quit.
:w filename writes what you've been editing to a new file named
filename ; it will complain (and not write out anything) if the file
already exists.
Search WWH ::




Custom Search