 ctrl-r for re-do.
Often one wants to delete an entire set of lines or other region. Though one could do this character-by-character or line-by-line, it is faster and less distracting to apply a single delete operation to an entire region..
Moreover, by using a delete operation on an entire region, this sets up ways to copy or move the region.
Suppose for instance that we wish to move the function PrintResults() to a position just before the function Insert(). In vim we could first enter visual mode.
In gvim, one simply creates the block by dragging the mouse from the first to the last character of the region, upon which the region becomes highlighted.
In vim, we move the cursor to the first character of the region, then hit v, then move the cursor to the last character of the region. For our example here:
This will define a region, which will now be highlighted:
Now hit d to delete the region. Note that vim (or gvim) has not discarded this region, but instead has placed it in a buffer.
Move to the desired transfer point, just before Insert() (black cursor, 3rd line in the screen):
Now hit p ("paste"), and the buffer contents will be placed at the cursor, thus transfering those lines of code.
If we wanted to merely copy those lines of code, not move them, we could have deleted the block and then used p twice: First at the point of deletion, to restore the block, and then at the place at which we want to copy the block.
In gvim, the GUI version of vim, it is even easier to define the region, simply by dragging the mouse.
The v operation is oriented to sets of lines. By contrast, ctrl-v , which invokes visual-block mode, allows you to define rectangular blocks of characters.
Say for instance that we wish to de-indent the body of the function ProcessData() by 3 spaces. First, position the cursor at the beginning of the body:
Now hit ctrl-v, and then move the cursor 3 spaces to the right, and down 3 lines. This defines a highlighted region:
Now hit d to delete the region, and voila! -- the lines have been de-indented 3 spaces:
Another application of ctrl-v is the commenting out/in of lines of code. During the debugging of a program, a programmer will often temporarily "comment out" some lines of code. We can expedite this using ctrl-v, say to comment-out the innermost if-then-else within the while loop in Insert(). First, define region consisting of the first character in each line:
(Don't hit the Esc key yet.)
Now hit I. This puts you into vim's Insert mode, at the top of the highlighted region. Now enter // to comment-out the first line:
Now hit Esc to end Insert mode as usual -- and look, all the lines are commented out!
Later, we will want to re-enable those lines. Again, set up a region using ctrl-v, this time 2 columns wide:
Now hit d, to delete the comment symbols:
First, there is auto-indent mode, which you can set using the vim command
In this mode, whenever you hit Enter to start typing on the next line, vim automatically will indent to the same amount as the previous line.
For example, note the position of the black cursor at the end of the 7th line of code in this screen:
After hitting Enter, the screen now looks like this:
This saved us the trouble of holding down the Space bar for 12 spaces. We can start typing the new line right away, already properly indented.
If we want to ignore this indenting on this line, we just hit the Esc key. If we want to leave auto-indent mode entirely, we type:set noai.
Another powerful auto-indenting comment in vim is the = command. We will not discuss it here, though.
In vim, type
The makefile will be executed, and if there are any errors in syntax, etc. reported by the compiler, vim will relay them to you in the same window as the source code.
For instance, suppose we had forgotten to end the line
X[I] = atoi(AV[I+1])
in GetArgs() with a semicolon. After typing :make we would see the following screen:
When we then do hit the Enter key as requested, vim will move the cursor right to the location of the first error (black cursor on the 6th line of the screen):
Suppose you are typi