Vim crib sheet for an ISPF user

If you have any suggestions for this post – please let me know.

If you use z/OS Unix from ISPF, you can use the ISPF editor. If you use z/OS Unix through an SSH session, you do not have access to ISPF, and need to use native Unix facilities.

From an SSH session, to display files you can use cat, head, tail or the less commands. To change text the most common editor is Vim.

Vim is an enhanced vi; neovim is an enhanced vim – for example good for people who want to write vim plugins.

If you are starting out, use the vim editor. Initially use it to browse files instead of tools like less, head or tail. Then graduate to making change.

There are some good tutorials around for how to use vim.

I’ve tried to give the bits which are not covered and get you started. This is a good crib sheet of all of the commands

Getting started

There are different modes (normal, insert, replace, visual, select). Sometimes you can enter text into the main window, sometimes you cannot. See the bottom line to the left.

  • — INSERT you can insert text in the main window. Press the Insert key to get into this mode. Press clear key to return to normal mode.
  • blank – this is normal/command mode. If you position the cursor on a word in the file and type dw it will delete the word. As you type commands, the text will be displayed on the bottom line.
  • — VISUAL you can use the mouse (or keys) to select text
    • v allows you to select text
    • V allows you to select lines
    • Ctrl-V allows you to rectangles of data. Use Ctrl-V then move the cursor

If the screen is mostly read only, as you type commands they appear in the middle of the bottom line

  • Edit a file using vim file_name
  • Quit
    • :q (you may have to press escape then type :q)
    • if you’ve changed the file :q!
  • Save changes :w
  • Save changes and quit :wq
  • Page down and page up work like PF7 and PF8 (on my 3270 emulator I have <keyPress>Next mapping to PF(“8”)
  • The up and down cursor keys move the cursor, and data.
  • You can use the :help command to display comprehensive information.
  • Use Escape :set wrap or Escape :set nowrap to wrap the text or not
  • Use Escape :set nu or Escape :set nonu to display line numbers
  • Move the data (in normal mode – press Escape on ore more times)
    • one char to the left under the window zl
    • one char to the right under the window zh
    • 20 char to the left under the window z20l
    • 20 char to the right under the window z20h
    • half a window to the left under the window zL
    • half a window to the right under the window zH
  • Top of the file gg
  • Bottom of the file G
  • Search
    • Find next /value (enter)
    • Use * to find the next word under the cursor
    • Use # to find previous word under the cursor
    • Find backwards ?value (enter)
    • Find word /\<theword\>
    • / followed by up or down arrow shows history of search
    • Highlight all values found :set hlsearch
    • To ignore case for one search, append \c after the search pattern. /ISPF/\c
    • To force case sensitivity, append uppercase \C after the pattern. /ISPF/\C
    • To set ignore case for the session :set ic
    • To reset case :set noic
  • Find and replace
    • Change one instance on the current line :s/{pattern}/{replacement}/
    • Change all instances on the current line :s/{pattern}/{replacement}/g
    • Change all instances in the file :%s/{pattern}/{replacement}/g
    • Change instances in a range :%3,6s/{pattern}/{replacement}/g
    • Change instances in a range from current line to line 6 %.,6s/{pattern}/{replacement}/g
    • Change instances in a range from current line to the end :%.,$s/{pattern}/{replacement}/g
    • Change instances in a range from current line in the next 3 lines :%.,+3s/{pattern}/{replacement}/g
    • Change instances in a range from current line to the top :%.,1s/{pattern}/{replacement}/g
    • Show history :s
  • What were the last commands I entered? : followed by Ctrl-P (same as ISPF retrieve key)
  • Undo: in command mode (escape)
    • u undo last change
    • 3u undo last 3 changes
    • U undo change to the line
    • Ctrl-R redo
  • Label lines. In ISPF you can label lines, such as .a in the prefix command.
    • Mark the current line as the single letter a ma
    • Display all of the marked lines :marks
    • Jump to mark a `a

Profile

You can store profile commands in $HOME/.vimrc

Mapping keys

You can map keys to commands. See here