[Chapter 30] 30.36 The ex Open Mode Can Be Handy
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:45:59Z

#

| Chapter 30 vi Tips and Tricks |

## 30.36 The ex Open Mode Can Be Handy

Most vi users hate it when they start the editor and get a message like one of these:

>     Visual needs addressable cursor or upline capability
>     [Using open mode]

Those folks usually say (or think) something choice like "how the #&@! do I get to fullscreen mode?" If you're one of those people, wait. You might get to like the ex open mode!

Before I show you an example of open mode, I'll mention another place where it's nice: on slow dialup lines or sluggish network connections, where your screen fills slowly and you're always waiting for it to redraw. It's also very useful if you're using a window system and vi doesn't seem to understand how many lines are in your window - for quick editing, it can be easier to switch to open mode for a minute than to try to fix the window.

The open mode is something like vi on a one-line screen. It's different from other UNIX line-mode editors like ed or the standard colon-prompt mode of ex, though. In open mode, you use the normal fullscreen vi commands - one line at a time. For example, to exit, type `ZZ` just like you do in fullscreen mode.

If you've got a fair amount of experience with vi, the easiest way to learn about open mode is to jump in and try it - after a little explanation, that is. There are three ways to get into open mode:

- If you're thrown into ex mode and given a colon (`:`) prompt, type this command and press RETURN:

  >     :open

- If you have a choice - on a slow network connection, for example - start open mode from the command line. Depending on your version of vi, use one of the following commands:

  >     % ex +open filename
  >     % ex -c open filename

- If you're already in vi's fullscreen mode, switch to open mode by typing `Q` to get an ex colon (`:`) prompt. Then type the command `open` and press RETURN.

When you start open mode, the editor will display the current line and put your cursor at the start of it.

Keystrokes

  Result

`ex +open afile`

>     [Using open mode]
>     "afile" 47 lines, 1943 characters
>     In the beginning, there was a cursor.

Open the file afile in open mode. Notice that the prompt line, which shows the filename and size at the bottom of the screen in vi, is printed first during open mode. That's because open mode always prints line by line. Next, the first line of the file is displayed. Your cursor is at the start of the line.

`2w`

>     [Using open mode]
>     "afile" 47 lines, 1943 characters
>     In the beginning, there was a cursor.

The vi command `2w` moves the cursor forward two words.

`j`

>     [Using open mode]
>     "afile" 47 lines, 1943 characters
>     In the beginning, there was a cursor.
>     The screen was blank and without characters.

The vi command `j` moves the cursor down one line. NOTE: On some versions, this command will print only the first few characters of the new line - up to the place where the cursor sits. So, instead of `j`, I usually use the RETURN command to paint a whole line and move the cursor to the front of it.

`k`

>     [Using open mode]
>     "afile" 47 lines, 1943 characters
>     In the beginning, there was a cursor.
>     The screen was blank and without characters.
>     In the beginning, there was a cursor.

The vi command `k` moves the cursor up one line - to the previous line. This is open mode, so the previous lines scroll away. To keep from getting confused, remember: the line with the cursor is the one you're editing now. NOTE: As in the previous step, the `k` command may not print all of the line. In that case, the minus (`-`) command is better.

`cwend`

>     [Using open mode]
>     "afile" 47 lines, 1943 characters
>     In the beginning, there was a cursor.
>     The screen was blank and without characters.
>     In the end, there was a cursor.

Typing `cw` puts you into vi's text-input mode to change the word beginning to end. Press ESC to go back to command mode.

This might take some getting used to. But once you learn the idea behind open mode, it can be handy to know.

- JP

30.35 Out of Temporary Space? Use Another Directory |  | 30.37 Neatening Lines