This section is designed to show some of the capabilities and
functionality of the X2 Editor. If you are already familiar with the editor
you may want to skip this section.
The following figure
shows a sample editor screen, when editing a small C source file.
This sample illustrates the main areas of the screen:
This section takes you through a sample edit session. It shows you how
you can use some of the default keys to speed up editing tasks, and how to
manipulate data with the default keys. Text that you should type is
highlighted in italics, while keys you should press are
highlighted in bold text.
If you have not already created a profile, do so now:
Load a new C source file into the editor: x newfile.c. The
message "New file" should be displayed on the help line.
Create a main function. Type main and press the space bar. A
skeleton main function should be entered for you.
Define some variables: int sq, sum=0;
Duplicate the current line: Ctrl-K
Overtype the variable names with another variable called ctr
Insert a new line: Ctrl-Enter
Insert the following text:
While adding the above text, you may need to move around the screen. The
following keys may be useful:
Comment your code. Move to the first brace after the if
statement, and position the cursor at the end of the line. Add the following
text:
When you move the cursor down past this line, you should see that the
comment has been converted from a quick comment to a regular C
language comment, and has been aligned to the right comment margin.
Save your file: F4. You should see the filename change from
red to magenta, to indicate that it has been saved successfully.
Now we want to move the calculation of the squares to a separate function.
We'll do that by adding a prototype before the definition of the main
function. Move the cursor just above the definition of the main
function, and insert the following line:
Mark the above line by pressing Alt-L with the cursor still on
the line. You should see just one line change to marked emphasis.
Move to the bottom of the file: Ctrl-End
Insert a few blank lines after the main function, and copy the marked
line: Alt-C
Remove the trailing semi-colon and insert beginning and ending braces to
define the function. Move back to the calculation of the square from the
previous exercise: sq = ctr * ctr;. Duplicate this line with
Ctrl-K, then overwrite the top copy to call the new CalcSquare
function: sq = CalcSquare(ctr);
Position the cursor over the next line and start another line mark with
Alt-L. You will notice that this extends the previous mark to the
current location. You may remove the mark with Alt-U, but an
easier way is just to press Alt-L once again.
Extend the line mark to include the next line (printf) by moving the
cursor down and pressing Alt-L again.
Move back down to the bottom of the file and move the marked text to its
new location. Position the cursor over the line containing the open brace
for the function definition, and press Alt-M.
If you want to align the text in the new function, press Alt-<
or Ctrl-F7 to move the text left, as many times as necessary.
Insert a line at the beginning of the function to define a variable:
int sq;
Insert a line at the end of the function to return the result:
return sq;
Press F4 to save the file again
You may have noticed that the variable name ctr in the
CalcSquare function does not match the supplied parameter name
num. This may be fixed with the Change command. Move the
cursor to the beginning of the CalcSquare function and press
Esc to display the command line. Enter: c /ctr/num/
and press the Enter key. Respond to the prompts by pressing
Y until you reach the end of file. If you are sure you want to
change all occurrences of a given string to the end of file, you can supply
the * option to the change command.
While still on the command line, type save and press
Enter to save the file to disk. The default F4 key is set to call the Save
command when pressed. Knowing the equivalent command for a key is useful
when writing macros or configuring the editor.
The command stack is displayed whenever the command line is active. This
is a list of the twenty most recently issued commands, sorted so the most
recent is displayed first. Although the command stack contains up to
twenty items, you will only see a maximum of ten lines when using the
default configuration. You may scroll through the list with the cursor up
and cursor down keys. When you do so, you will notice that the current stack
line is copied to the command line for modification and/or execution.
While editing a large file, it is sometimes useful to see only a few lines
and hide the rest. X2 provides this capability through keys and
commands. While editing NEWFILE.C, press Ctrl-X several times. You should
see the current line replaced by a line that says "1 line(s) not displayed".
The number of lines displayed will increase every time you press Ctrl-X. The
"line(s) not displayed" line is called a Shadow line, and may be turned on
and off with the Shadow command or by pressing Ctrl-S. Press
Ctrl-S twice to see the shadow line disappear and reappear.
Press Ctrl-U to make sure all lines are displayed. Now move to
the open brace in the for statement in your main function. Press
Ctrl-A (exclude area) to hide all the lines with the same or
greater indentation. Now move the cursor to the shadow line and press
Ctrl-X. This will show the five lines that were previously
hidden.
There are times when you want to see where you have used a certain
variable name, or perhaps you want to see every location where you have
called a given function. You can do this with X2's All command. Go to the
command line and enter all /printf/. You should see just two
remaining text lines and three shadow lines. Move to the first printf line
and press Alt-L to mark the line. Move to the second printf line
and press Alt-L again to mark all the lines between the two printf
lines. Now edit a new file: Press F6 to display the command line
with the command Edit already displayed. Now enter a new filename:
printfs.c. This will create a second file in the edit ring. You
can move back and forth between the two files with the F11 and F12 keys.
Press F12 to move back to newfile.c. Notice that the file is as
you left it, i.e. the hidden lines and mark are intact. Move back to
printfs.c by pressing F12 again. Press Alt-C to copy
the mark. You will see that only the two lines were copied, even though you
marked hidden lines between the two visible lines. This allows you to
easily copy just a few lines from a large file. Most other commands only
work on visible text, so if a line is hidden it can safely be ignored when
doing file operations that may destroy data.
Press F3 to quit printfs.c, and reply Y to the
prompt confirming that you don't want to save your changes. Press
F4 to save newfile.c and you will notice that all your hidden
lines are now visible again.
Screen Areas
Sample Edit Session
Basic Navigation
for (ctr = 0; ctr < 10; ++ctr)
{
sq = ctr * ctr;
printf("The square of %i is %i\n", ctr, sq);
sum += sq;
}
printf("The total of the squares is %i\n", sum);
// Loop through the integers
Marking
int CalcSquare (int num);
The Command Line
Hidden Lines