Книга: Learning GNU Emacs, 3rd Edition

13.3.4 Making Emacs Act like Windows: CUA Mode

13.3.4 Making Emacs Act like Windows: CUA Mode

CUA stands for common user access, a standard originally developed by IBM. CUA mandates that certain keys should always perform certain functions. In Windows, for example, C-c copies and C-v pastes from one application to another. As you know, Emacs uses these key bindings for its own purposes.

That's where Kim Storm's CUA mode comes in. This mode was so popular that it is now part of Emacs.[95] It allows standard Windows key bindings, like C-x for cut and C-v for paste, to work properly within Emacs. It's quite clever—these keys cut and paste only when an active selection exists. That leaves the normal functionality of multistroke commands like C-c C-f in fine shape.

To turn on CUA mode, select C-x/C-c/C-v cut-and-paste (CUA) from the Options menu. If you decide you want to use CUA mode for multiple sessions, select Save Options to have Custom (discussed in Chapter 10) automatically add it to your .emacs file.

As you can see from the option name, in this mode, C-x is used for cutting text, C-c is used for copying text, and C-v is used for pasting text. What is not so apparent is that C-z runs undo rather than minimizing the window (in CUA mode, you can minimize using C-x C-z).

What if you're used to confirming a region before you cut it using C-x C-x? You can type C-c C-x C-x in this case. This works in part because C-c cancels the active region. Remember that C-x would normally cut.

Strictly speaking, C-x C-x doesn't immediately cut text, if you type it fast enough. Cut is really bound to C-x <timeout>. In other words, Emacs is watching to see if you type something else really quickly. If you have a region highlighted and type C-x C-s to save the buffer, Emacs does the right thing. But if you pause after C-x, you'll cut text. This is true of C-c as well. If you immediately type another sequence after C-c, Emacs uses C-c as a prefix. If you pause, it copies the highlighted text.

CUA mode has a few other interesting behaviors. It has highly advanced rectangle support. (Rectangle editing is described in Chapter 7.) It also has the common behavior of replacing highlighted text. If you select a region and start typing, the highlighted text is replaced. Taking this one step further, you can do a quick and dirty search and replace in this way. Let's say that the text you typed over is just the first of several identical instances where you want to replace text. Typing M-v (for cua-repeat-replace-region) replaces the next instance. Repeat this command to continue making replacements. If there is no string to replace, M-v does nothing.

For example, let's take our classic Dickens passage and replace the word times with rhymes:

Highlight the word times.


The word times is highlighted.

Type: rhymes


Emacs replaces times with rhymes.

Type: M-v


Emacs replaces the next instance of times with rhymes.

You may love CUA mode or you may hate it; the only way to see if your fingers are ready for this option is to try it out. If you've used Emacs for years, you may find CUA mode keeps doing unexpected things. Your finger habits are set to Emacs's ways. On the other hand, it's hard to move back and forth between applications and change your finger habits all the time. If you have not yet gotten used to the Emacs key bindings, you may well love CUA mode, as many people do.

Table 13-1 lists CUA mode commands.

Table 13-1. CUA mode commands

Keystrokes Command name Action
C-c C-x C-x cua-exchange-point-and-mark Exchange location of cursor and mark.
C-c copy-region-as-kill Copy the region.
C-x orC-w orS-Delete kill-region Delete the region.
C-v orC-y orS-Insert cua-paste Paste most recently killed or copied text.
M-v cua-repeat-replace-region After highlighting and replacing a string, find the next string and replace it the same way.
PgUp cua-scroll-up Scroll up one page (or to the beginning of the buffer).
PgDown cua-scroll-down Scroll down one page (or to the end of the buffer).
M-y cua-paste-pop After C-v, pastes earlier deletion.
C-z orC-x u cua-undo Undoes the last change.
C-x C-z iconify-frame Minimize the current frame (what C-z does outside CUA mode).

Оглавление книги


Генерация: 0.146. Запросов К БД/Cache: 0 / 0
поделиться
Вверх Вниз