Progress0 of 0 lessons

Block Commands

Block commands in ISPF allow you to manipulate blocks (ranges) of lines, similar to cut/paste and copy/paste operations in modern text editors. These commands are essential for efficiently reorganizing code, duplicating sections, and moving large blocks of text. This tutorial covers MOVE/POP (cut/paste) and COPY/PASTE equivalents, along with techniques for marking and manipulating blocks.

Understanding block commands is crucial for efficient editing, especially when working with large files or reorganizing code structure. Block operations let you work with multiple lines at once, saving time and reducing errors compared to moving or copying lines individually.

Understanding Block Operations

Block operations work on ranges of lines rather than individual lines.

What is a Block?

A block is:

  • A range of consecutive lines
  • Marked by placing commands on the first and last lines
  • Operated on as a single unit
  • Can contain any number of lines

Block Operations

Common block operations include:

  • MOVE: Cut a block (remove from original location)
  • POP: Paste a cut or copied block
  • COPY: Copy a block (keep original in place)
  • PASTE: Paste a copied block

MOVE and POP (Cut/Paste)

MOVE and POP are the ISPF equivalents of cut and paste operations.

Understanding MOVE

MOVE (cut) operation:

  • Removes the block from its original location
  • Stores it in a temporary buffer (clipboard)
  • The original lines are deleted
  • The block can then be pasted using POP

Understanding POP

POP (paste) operation:

  • Retrieves the last cut or copied block
  • Inserts it at the current or specified location
  • Can be used multiple times to paste the same block
  • Works with both MOVE and COPY operations

MOVE/POP Workflow

The typical workflow:

  • Mark the block you want to move
  • Cut the block (using MOVE or line commands)
  • Navigate to the target location
  • Use POP to paste the block

Marking Blocks with Line Commands

The most common way to mark blocks is using line commands.

Marking a Block for MOVE

To mark a block for moving:

  • Place "M" in the line number area on the first line of the block
  • Place "M" in the line number area on the last line of the block
  • All lines between (inclusive) are marked as the block
  • Press Enter to execute the move

Marking a Block for COPY

To mark a block for copying:

  • Place "C" in the line number area on the first line of the block
  • Place "C" in the line number area on the last line of the block
  • All lines between (inclusive) are marked as the block
  • Press Enter to execute the copy

Marking Example

Marking lines 5-10 for moving:

text
1
2
3
4
5
6
7
8
9
10
11
12
000001 This is line 1 000002 This is line 2 000003 This is line 3 000004 This is line 4 M 000005 This line will be moved (first line of block) 000006 This line will be moved 000007 This line will be moved 000008 This line will be moved 000009 This line will be moved M 000010 This line will be moved (last line of block) 000011 This is line 11 000012 This is line 12

Lines 5 through 10 are now marked as a block.

Moving Blocks with Line Commands

You can move blocks directly using line commands without separate cut/paste steps.

Move Block After a Line

To move a block after a specific line:

  • Mark the block with "M" on first and last lines
  • Place "A" (After) next to the target line
  • Press Enter to execute
  • The block is moved to after the target line

Move Block Before a Line

To move a block before a specific line:

  • Mark the block with "M" on first and last lines
  • Place "B" (Before) next to the target line
  • Press Enter to execute
  • The block is moved to before the target line

Move Block Example

Moving lines 5-10 to after line 15:

text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
000001 This is line 1 000002 This is line 2 000003 This is line 3 000004 This is line 4 M 000005 This line will be moved 000006 This line will be moved 000007 This line will be moved 000008 This line will be moved 000009 This line will be moved M 000010 This line will be moved 000011 This is line 11 000012 This is line 12 000013 This is line 13 000014 This is line 14 A 000015 This is line 15 (target line) 000016 This is line 16

After pressing Enter, lines 5-10 are moved to after line 15.

Copying Blocks with Line Commands

You can copy blocks directly using line commands.

Copy Block After a Line

To copy a block after a specific line:

  • Mark the block with "C" on first and last lines
  • Place "A" (After) next to the target line
  • Press Enter to execute
  • The block is copied to after the target line, original remains

Copy Block Before a Line

To copy a block before a specific line:

  • Mark the block with "C" on first and last lines
  • Place "B" (Before) next to the target line
  • Press Enter to execute
  • The block is copied to before the target line, original remains

Copy Block Example

Copying lines 5-10 to after line 15:

text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
000001 This is line 1 000002 This is line 2 000003 This is line 3 000004 This is line 4 C 000005 This line will be copied 000006 This line will be copied 000007 This line will be copied 000008 This line will be copied 000009 This line will be copied C 000010 This line will be copied 000011 This is line 11 000012 This is line 12 000013 This is line 13 000014 This is line 14 A 000015 This is line 15 (target line) 000016 This is line 16

After pressing Enter, lines 5-10 are copied to after line 15, and the originals remain in place.

Using Primary Commands for Blocks

You can also use primary commands for block operations.

MOVE Primary Command

To move a block using primary commands:

text
1
Command ===> MOVE 5 10 15

This moves lines 5 through 10 to after line 15.

COPY Primary Command

To copy a block using primary commands:

text
1
Command ===> COPY 5 10 15

This copies lines 5 through 10 to after line 15.

Primary Command Syntax

The syntax is:

text
1
2
MOVE startline endline targetline COPY startline endline targetline

Where startline and endline define the block, and targetline is where it should be placed.

POP and PASTE Operations

POP and PASTE are used to insert previously cut or copied blocks.

Using POP

After cutting or copying a block:

  • Navigate to the target location
  • Use POP to paste the block
  • POP can be used multiple times to paste the same block
  • The block is inserted at the current cursor position or specified location

POP Primary Command

To paste using POP:

text
1
Command ===> POP

Or to paste at a specific line:

text
1
Command ===> POP 20

This pastes the block at line 20.

PASTE Command

Some ISPF versions use PASTE instead of or in addition to POP:

text
1
Command ===> PASTE

PASTE works similarly to POP, inserting the last cut or copied block.

Block Operations Workflow

Here's a complete workflow for block operations.

Cut and Paste Workflow

To cut and paste a block:

  • Step 1: Mark the block using "M" on first and last lines
  • Step 2: Use MOVE or cut the block (it's removed from original location)
  • Step 3: Navigate to the target location
  • Step 4: Use POP to paste the block
  • Step 5: The block appears at the new location

Copy and Paste Workflow

To copy and paste a block:

  • Step 1: Mark the block using "C" on first and last lines
  • Step 2: Use COPY or copy the block (original remains in place)
  • Step 3: Navigate to the target location
  • Step 4: Use POP to paste the block
  • Step 5: The block appears at the new location, original still in place

Multiple Paste Operations

You can paste the same block multiple times.

Pasting Multiple Times

After cutting or copying a block:

  • Use POP at the first target location
  • Navigate to a second target location
  • Use POP again to paste another copy
  • Repeat as needed
  • The same block can be pasted multiple times

Multiple Paste Example

After copying a block, you can paste it at multiple locations:

  • Copy lines 5-10
  • Use POP at line 20 (first copy)
  • Use POP at line 30 (second copy)
  • Use POP at line 40 (third copy)
  • All three copies are created from the same original block

Block Operations Best Practices

Following best practices helps you use block operations effectively:

  • Verify Block Range: Double-check that you've marked the correct first and last lines
  • Save Before Large Operations: Save your work before performing large block moves or copies
  • Use COPY for Safety: When unsure, use COPY instead of MOVE to keep originals
  • Check Target Location: Verify the target location before pasting
  • Understand Line Numbering: Be aware that line numbers change after block operations
  • Use Primary Commands for Precision: Use primary commands when you know exact line numbers
  • Test on Small Blocks First: Practice with small blocks before working with large sections
  • Undo When Available: Use undo if you make mistakes (if supported by your ISPF version)

Common Block Operation Scenarios

Here are common scenarios where block operations are useful.

Reorganizing Code Sections

When reorganizing code:

  • Mark the section you want to move
  • Move it to the new location
  • Use MOVE to relocate entire functions or procedures
  • Maintain code structure while reorganizing

Duplicating Code Patterns

When duplicating similar code:

  • Mark the pattern you want to duplicate
  • Use COPY to create a copy
  • Paste it at the new location
  • Modify the copy as needed

Moving Comment Blocks

When moving documentation:

  • Mark the comment block
  • Move or copy it to the appropriate location
  • Keep documentation with relevant code

Block Operations vs. Line Commands

Understanding when to use block operations vs. individual line commands.

Use Block Operations When

Block operations are best for:

  • Moving or copying multiple lines (3+ lines)
  • Reorganizing large sections
  • Duplicating code patterns
  • Working with entire functions or procedures

Use Line Commands When

Individual line commands are best for:

  • Working with single lines or small ranges (1-2 lines)
  • Quick insertions or deletions
  • Simple operations on individual lines

Explain Like I'm 5: Block Commands

Think of block commands like moving or copying whole paragraphs in a story:

  • MOVE (Cut) is like cutting out a whole paragraph from your story. You mark the paragraph (the block), cut it out, and then you can paste it somewhere else. The original paragraph disappears from where it was, and you can put it in a new place!
  • POP (Paste) is like pasting that paragraph you cut. After you cut a paragraph, you go to a new place in your story and paste it there. You can even paste the same paragraph in multiple places if you want!
  • COPY is like making a photocopy of a paragraph. You mark the paragraph, copy it, and then you can paste copies of it in new places. But the original paragraph stays right where it was—you didn't cut it out, you just made copies!
  • Marking a Block is like highlighting a whole paragraph. You put a special mark at the beginning and end of the paragraph to say "this whole section is what I want to work with!"

So block commands are like special tools for moving or copying whole sections of your file at once, instead of doing it line by line!

Practice Exercises

Complete these exercises to reinforce your understanding of block commands:

Exercise 1: Marking Blocks

Practice marking blocks: create a test file, practice marking different ranges of lines using "M" and "C" commands, and verify that you're marking the correct ranges. Build familiarity with block marking.

Exercise 2: Moving Blocks

Practice moving blocks: mark blocks and move them to different locations using line commands (M with A or B) and primary commands. Observe how blocks are relocated and how line numbers change.

Exercise 3: Copying Blocks

Practice copying blocks: mark blocks and copy them to different locations. Verify that originals remain in place while copies are created. Practice copying the same block to multiple locations.

Exercise 4: Cut and Paste Workflow

Practice the complete cut and paste workflow: mark a block, cut it, navigate to a target location, and paste it using POP. Practice pasting the same block multiple times at different locations.

Exercise 5: Real-World Scenarios

Practice real-world scenarios: reorganize code sections, duplicate code patterns, and move comment blocks. Apply block operations to practical editing tasks.

Test Your Knowledge

1. What is the ISPF equivalent of cut/paste?

  • COPY and POP
  • MOVE and POP
  • CUT and PASTE
  • DELETE and INSERT

2. What is the difference between MOVE and COPY in block operations?

  • MOVE duplicates, COPY relocates
  • MOVE relocates, COPY duplicates
  • They are identical
  • MOVE is faster

3. How do you mark a block of lines in ISPF?

  • Use function keys only
  • Place M or C on first and last lines of the block
  • Use primary commands only
  • Drag with mouse

4. What does POP do in ISPF?

  • Cuts a block
  • Copies a block
  • Pastes a previously cut or copied block
  • Deletes a block

5. Can you paste a copied block multiple times?

  • No, only once
  • Yes, using POP at different locations
  • Only with special commands
  • Only in some ISPF versions

Related Concepts