Tải bản đầy đủ - 0 (trang)
The Emacs Editor (Linux in a Nutshell, 3rd Edition)

The Emacs Editor (Linux in a Nutshell, 3rd Edition)

Tải bản đầy đủ - 0trang

The Emacs Editor (Linux in a Nutshell, 3rd Edition)



Copyright © 2001 O'Reilly & QKFIN. All rights reserved.



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch10_01.htm (2 of 2) [15/05/2002 18:10:27]



Typical Problems (Linux in a Nutshell, 3rd Edition)



Linux in a Nutshell, 3rd

Edition



10.2. Typical Problems

A very common problem is that the Del or Backspace key on the terminal does not delete the

character before the cursor, as it should. Instead, it invokes a help prompt. This problem is

caused by an incompatible terminal. A fairly robust fix is to create a file named .emacs in your

home directory (or edit one that's already there) and add the following lines:

(keyboard-translate ?\C-h ?\C-?)

(keyboard-translate ?\C-\\ ?\C-h)

Now the Del or Backspace kill should work, and you can invoke help by pressing C-\ (an

arbitrarily chosen key sequence).

Another potential problem is that on some systems, C-s causes the terminal to hang. This is

due to an old-fashioned handshake protocol between the terminal and the system. You can

restart the terminal by pressing C-q, but that doesn't help you enter commands that contain the

sequence C-s. The solution (aside from using a more modern dial-in protocol) is to create new

key bindings that replace C-s or to enter those commands as M-x command-name.



10.2.1. Notes on the Tables

Emacs commands use the Ctrl key and the Meta key. Most modern terminals provide a key

named Alt that functions as a Meta key. In this section, the notation C- indicates that you

should hold down the Ctrl key and press the character that follows, while M- indicates that the

Meta or Alt key is pressed in the same way, along with the character that follows. As an

alternative to Meta or Alt, you can press the Esc key, release it, and press the character. You

might want to do this if you have any problems with controlling windows capturing the Alt

key (which sometimes happens).

In the command tables that follow, the first column lists the keystroke and the last column

describes it. When there is a middle column, it lists the command name. The command can be

executed by typing M-x followed by the command name; you have to do this when the

binding is listed as "(none)." If you're unsure of the full command name, you can type a space

or a carriage return, and Emacs will list possible completions of what you've typed so far.



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch10_02.htm (1 of 3) [15/05/2002 18:10:30]



Typical Problems (Linux in a Nutshell, 3rd Edition)



Because Emacs is such a comprehensive editor, containing hundreds of commands, some

commands must be omitted for the sake of preserving a "quick" reference. You can browse

the command set by typing C-h (for help) and then b to get a list of the key bindings[6] or Mx followed by a space or Tab to get the command names.

[6]If you want to learn to create your own key bindings, see Learning GNU

Emacs (O'Reilly).



10.2.2. Modes

One of the features that makes Emacs popular is its editing modes. The modes set up an

environment designed for the type of editing you are doing, with features like having

appropriate key bindings available and automatically indenting according to standard

conventions for that type of document. There are modes for various programming languages

like C or Perl, for text processing (e.g., SGML or even straight text), and many more. One

particularly useful mode is Dired (Directory Editor), which has commands that let you

manage directories. For a full discussion of modes, see Learning GNU Emacs, mentioned at

the beginning of this chapter, or the Emacs Info documentation system (C-h i).



10.2.3. Absolutely Essential Commands

If you're just getting started with Emacs, here's a short list of the most important commands to

know:

Binding



Action



C-h



Enter the online help system.



C-x C-s



Save the file.



C-x C-c



Exit Emacs.



C-x u



Undo last edit (can be repeated).



C-g



Get out of current command operation.



C-p



Up by one line.



C-n



Down by one line.



C-f



Forward by one character.



C-b



Back by one character.



C-v



Forward by one screen.



M-v



Backward by one screen.



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch10_02.htm (2 of 3) [15/05/2002 18:10:30]



Typical Problems (Linux in a Nutshell, 3rd Edition)



C-s



Search forward for characters.



C-r



Search backward for characters.



C-d



Delete current character.



Del



Delete previous character.



Backspace Delete previous character.



10. The Emacs Editor



10.3. Summary of

Commands by Group



Copyright © 2001 O'Reilly & QKFIN. All rights reserved.



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch10_02.htm (3 of 3) [15/05/2002 18:10:30]



Summary of Commands by Group (Linux in a Nutshell, 3rd Edition)



Linux in a Nutshell, 3rd

Edition



10.3. Summary of Commands by Group

Reminder: Tables list keystrokes, command name, and description. C- indicates the Control

key; M- indicates the Meta key.



10.3.1. File-Handling Commands

Binding Command



Action



C-x C-f



find-file



Find file and read it.



C-x C-v



find-alternate-file



Read another file; replace the one read currently in the

buffer.



C-x i



insert-file



Insert file at cursor position.



C-x C-s



save-buffer



Save file. (If terminal hangs, C-q restarts.)



C-x C-w write-file



Write buffer contents to file.



C-x C-c



save-buffers-kill-emacs Exit Emacs.



C-z



suspend-emacs



Suspend Emacs (use exit or fg to restart).



10.3.2. Cursor Movement Commands

Some words are emphasized in the Action column to help you remember the binding for the

command.

Binding Command



Action



C-f



forward-char



Move forward one character (right).



C-b



backward-char



Move backward one character (left).



C-p



previous-line



Move to previous line (up).



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch10_03.htm (1 of 9) [15/05/2002 18:10:34]



Summary of Commands by Group (Linux in a Nutshell, 3rd Edition)



C-n



next-line



Move to next line (down).



M-f



forward-word



Move one word forward.



M-b



backward-word



Move one word backward.



C-a



beginning-of-line



Move to beginning of line.



C-e



end-of-line



Move to end of line.



M-a



backward-sentence



Move backward one sentence.



M-e



forward-sentence



Move forward one sentence.



M-{



backward-paragraph Move backward one paragraph.



M-}



forward-paragraph



Move forward one paragraph.



C-v



scroll-up



Move forward one screen.



M-v



scroll-down



Move backward one screen.



C-x [



backward-page



Move backward one page.



C-x ]



forward-page



Move forward one page.



M->



end-of-buffer



Move to end-of-file.



M-<



beginning-of-buffer



Move to beginning of file.



(none)



goto-line



Go to line n of file.



(none)



goto-char



Go to character n of file.



C-l



recenter



Redraw screen with current line in the center.



M-n



digit-argument



Repeat the next command n times.



C-u n



universal-argument



Repeat the next command n times.



10.3.3. Deletion Commands

Binding Command



Action



Del



backward-delete-char



Delete previous character.



C-d



delete-char



Delete character under cursor.



M-Del



backward-kill-word



Delete previous word.



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch10_03.htm (2 of 9) [15/05/2002 18:10:34]



Summary of Commands by Group (Linux in a Nutshell, 3rd Edition)



M-d



kill-word



Delete the word the cursor is on.



C-k



kill-line



Delete from cursor to end-of-line.



M-k



kill-sentence



Delete sentence the cursor is on.



C-x Del



backward-kill-sentence



Delete previous sentence.



C-y



yank



Restore what you've deleted.



C-w



kill-region



Delete a marked region (see Section 10.3.4,

"Paragraphs and Regions").



(none)



backward-kill-paragraph Delete previous paragraph.



(none)



kill-paragraph



Delete from the cursor to the end of the paragraph.



10.3.4. Paragraphs and Regions

Binding Command



Action



C-@



Mark the beginning (or end) of a region.



set-mark-command



C-Space (Same as preceding)



(Same as preceding)



C-x C-p mark-page



Mark page.



C-x C-x exchange-point-and-mark Exchange location of cursor and mark.

C-x h



mark-whole-buffer



Mark buffer.



M-q



fill-paragraph



Reformat paragraph.



(none)



fill-region



Reformat individual paragraphs within a region.



M-h



mark-paragraph



Mark paragraph.



M-{



backward-paragraph



Move backward one paragraph.



M-}



forward-paragraph



Move forward one paragraph.



(none)



backward-kill-paragraph



Delete previous paragraph.



(none)



kill-paragraph



Delete from the cursor to the end of the paragraph.



10.3.5. Stopping and Undoing Commands



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch10_03.htm (3 of 9) [15/05/2002 18:10:34]



Summary of Commands by Group (Linux in a Nutshell, 3rd Edition)



Binding Command



Action



C-g



keyboard-quit



Abort current command.



C-x u



advertised-undo Undo last edit (can be done repeatedly).



(none)



revert-buffer



Restore buffer to the state it was in when the file was last

saved (or auto-saved).



10.3.6. Transposition Commands

Binding Command



Action



C-t



transpose-chars



Transpose two letters.



M-t



transpose-words



Transpose two words.



C-x C-t



transpose-lines



Transpose two lines.



(none)



transpose-sentences



Transpose two sentences.



(none)



transpose-paragraphs Transpose two paragraphs.



10.3.7. Capitalization Commands

Binding



Command



Action



M-c



capitalize-word



Capitalize first letter of word.



M-u



upcase-word



Uppercase word.



M-l



downcase-word



Lowercase word.



M- - M-c negative-argument; capitalize-word Capitalize previous word.

M- - M-u negative-argument; upcase-word



Uppercase previous word.



M- - M-l



negative-argument; downcase-word Lowercase previous word.



(none)



capitalize-region



Capitalize initial letters in region.



C-x C-u



upcase-region



Uppercase region.



C-x C-l



downcase-region



Lowercase region.



10.3.8. Incremental Search Commands

file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch10_03.htm (4 of 9) [15/05/2002 18:10:34]



Summary of Commands by Group (Linux in a Nutshell, 3rd Edition)



Binding Command



Action



C-s



isearch-forward



Start or repeat incremental search forward.



C-r



isearch-backward



Start or repeat incremental search backward.



Return



(none)



Exit a successful search.



C-g



keyboard-quit



Cancel incremental search; return to starting point.



Del



(none)



Delete incorrect character of search string.



M-C-r



isearch-backward-regexp Incremental search backward for regular expression.



M-C-s



isearch-forward-regexp



Incremental search forward for regular expression.



10.3.9. Word Abbreviation Commands

Binding Command



Action



(none)



abbrev-mode



Enter (or exit) word abbreviation mode.



C-x a -



inverse-add- global-abbrev



Define previous word as global (modeindependent) abbreviation.



C-x a i l inverse-add- mode-abbrev



Define previous word as mode-specific

abbreviation.



(none)



unexpand-abbrev



Undo the last word abbreviation.



(none)



write-abbrev-file



Write the word abbreviation file.



(none)



edit-abbrevs



Edit the word abbreviations.



(none)



list-abbrevs



View the word abbreviations.



(none)



kill-all-abbrevs



Kill abbreviations for this session.



10.3.10. Buffer Manipulation Commands

Binding Command



Action



C-x b



Move to specified buffer.



switch-to-buffer



C-x C-b list-buffers



Display buffer list.



C-x k



Delete specified buffer.



kill-buffer



file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch10_03.htm (5 of 9) [15/05/2002 18:10:34]



Summary of Commands by Group (Linux in a Nutshell, 3rd Edition)



(none)



kill-some-buffers



Ask about deleting each buffer.



(none)



rename-buffer



Change buffer name to specified name.



C-x s



save-some-buffers Ask whether to save each modified buffer.



10.3.11. Window Commands

Binding Command



Action



C-x 2



split-window-vertically



Divide the current window in two vertically,

resulting in one window on top of the other.



C-x 3



split-window-horizontally



Divide the current window in two horizontally,

resulting in two side-by-side windows.



C-x >



scroll-right



Scroll the window right.



C-x <



scroll-left



Scroll the window left.



C-x o



other-window



Move to the other window.



C-x 0



delete-window



Delete current window.



C-x 1



delete-other-windows



Delete all windows but this one.



(none)



delete-windows-on



Delete all windows on a given buffer.



C-x ^



enlarge-window



Make window taller.



(none)



shrink-window



Make window shorter.



C-x }



enlarge-window- horizontally



Make window wider.



C-x {



shrink-window- horizontally



Make window narrower.



M-C-v



scroll-other-window



Scroll other window.



C-x 4 f



find-file-other-window



Find a file in the other window.



C-x 4 b



switch-to-buffer-other-window Select a buffer in the other window.



C-x 5 f



find-file-other-frame



Find a file in a new frame.



C-x 5 b



switch-to-buffer-other-frame



Select a buffer in another frame.



(none)



compare-windows



Compare two buffers; show first difference.



10.3.12. Special Shell Mode Characters

file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch10_03.htm (6 of 9) [15/05/2002 18:10:34]



Summary of Commands by Group (Linux in a Nutshell, 3rd Edition)



Binding Command



Action



C-c C-c



interrupt-shell-subjob Terminate the current job.



C-c C-d



shell-send-eof



End-of-file character.



C-c C-u



kill-shell-input



Erase current line.



C-c C-w backward-kill-word



Erase the previous word.



C-c C-z



Suspend the current job.



stop-shell-subjob



10.3.13. Indentation Commands

Binding Command



Action



C-x .



set-fill-prefix



Prepend each line in paragraph with characters from

beginning of line up to cursor column; cancel prefix

by typing this command in column 1.



(none)



indented-text-mode



Major mode: each tab defines a new indent for

subsequent lines.



(none)



text-mode



Exit indented text mode; return to text mode.



M-C-\



indent-region



Indent a region to match first line in region.



M-m



back-to-indentation



Move cursor to first character on line.



M-^



delete-indentation



Join this line to the previous line.



M-C-o



split-line



Split line at cursor; indent to column of cursor.



(none)



fill-individual- paragraphs Reformat indented paragraphs, keeping indentation.



10.3.14. Centering Commands

Binding Command



Action



(none)



center-line



Center line that cursor is on.



(none)



center-paragraph Center paragraph that cursor is on.



(none)



center-region



Center currently defined region.



10.3.15. Macro Commands

file:///E|/O'Reilly/O'Reilly%20-%20Linux%20in%20a%20Nutshell,%203rd%20Edition/Pages/ch10_03.htm (7 of 9) [15/05/2002 18:10:34]



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

The Emacs Editor (Linux in a Nutshell, 3rd Edition)

Tải bản đầy đủ ngay(0 tr)

×