以下是Emacs的一些基礎命令, 最近正在練級,這些基礎命令可幫上大忙了。
C代表control鍵,
M代表command鍵, 一般是alt鍵
C = ControlM = Meta = Alt|Esc
C-x C-f 在emacs 裏面打開文件
C-x C-s 保存當前文件
C-x C-w 保存爲一個不同名稱的文件
C-x C-v
find alternate fileC-x i
insert file at cursor positionC-x b
create/switch buffersC-x C-b
show buffer listC-x k
kill bufferC-z
suspend emacs C-X C-c
close down emacsBasic movement
C-f 向前移動一個字符
C-b 向後移動一個字符
C-p 向上移動一行
C-n 向下移動一行
M-f 向前移動一個單詞
M-b 向後移動一個單詞
C-a 移動到行首
C-e 移動到行尾
C-v 向上翻一頁, 有點類似pageup
M-v 向下翻一頁
M-< 跳到文件的第一行 --gg
M-> 跳到文件的末尾 ----G
C-/ undo , 取消操作
C-g C-/ redo 重新操作
Editing
M-n 重複剛纔的命令N次
C-u 重複剛纔的命令4次
C-u n 重複N次
C-d 刪除一個字符
M-d 刪除一個單詞
M-Del 向後刪除一個單詞
C-k 刪除一行
C-Space 設置起點標識
C-W 刪除選定區域
M-W 複製所選區域
C-y 黏貼選中的內容
M-y
yank earlier text (cycle through kill buffer)C-x C-x
exchange cursor and markC-t
transpose two charsM-t
transpose two wordsC-x C-t
transpose linesM-u
make letters uppercase in word from cursor position to endM-c
simply make first letter in word uppercaseM-l
opposite to M-uImportant
C-g
quit the running/entered commandC-x u
undo previous actionM-x revert-buffer RETURN
(insert like this) undo all changes since last saveM-x recover-file RETURN
Recover text from an autosave-fileM-x recover-session RETURN
if you edited several filesOnline-Help
C-h c
which command does this keystroke invokeC-h k
which command does this keystroke invoke and what does it do?C-h l
what were my last 100 typed keysC-h w
what key-combo does this command have?C-h f
what does this function doC-h v
what's this variable and what is it's valueC-h b
show all keycommands for this bufferC-h t
start the emacs tutorialC-h i
start the info readerC-h C-k
start up info reader and go to a certain key-combo pointC-h F
show the emacs FAQC-h p
show infos about the Elisp package on this machineSearch/Replace
C-s
Search forwardC-r
search backwardC-g
return to where search started (if you are still in search mode)M-%
query replace
Space or y
replace this occurenceDel or n
don't replace.
only replace this and exit (replace),
replace and pause (resume with Space or y)!
replace all following occurences^
back to previous matchRETURN or q
quit replace
Search/Replace with regular expressions
Characters to use in regular expressions:
^
beginning of line$
end of line.
single char.*
group or null of chars\<
beginning of a word\>
end of a word[]
every char inside the backets (for example [a-z] means every small letter)M C-s RETURN
search for regular expression forwardM C-r RETURN
search for regular expression backwardM C-s
incremental searchC-s
repeat incremental searchM C-r
incremental search backwardsC-r
repeat backwardsM-x query-replace-regexp
search and replaceWindow-Commands
C-x 2
split window verticallyC-x o
change to other windowC-x 0
delete windowC-x 1
close all windows except the one the cursors inC-x ^
enlarge windowM-x shrink-window
command says it ;-)M C-v
scroll other windowC-x 4 f
find file in other windowC-x 4 o
change to other windowC-x 4 0
kill buffer and windowC-x 5 2
make new frameC-x 5 f
find file in other frameC-x 5 o
change to other frameC-x 5 0
close this frameBookmark commands
C-x r m
set a bookmark at current cursor posC-x r b
jump to bookmarkM-x bookmark-rename
says itM-x bookmark-delete
"M-x bookmark-save
"C-x r l
list bookmarks
d
mark bookmark for deletionr
rename bookmarks
save all listed bookmarksf
show bookmark the cursor is overm
mark bookmarks to be shown in multiple windowv
show marked bookmarks (or the one the cursor is over)t
toggle listing of the corresponding pathsw
" path to this filex
delete marked bookmarksDel
?q
quit bookmark list
M-x bookmark-write
write all bookmarks in given fileM-x bookmark-load
load bookmark from given fileShell
M-x shell
starts shell modusC-c C-c
same as C-c under unix (stop running job)C-d
delete char forwardC-c C-d
Send EOFC-c C-z
suspend job (C-z under unix)M-p
show previous commandsDIRectory EDitor (dired)
C-x d
start up diredC
(large C) copy d
mark for eraseD
delete right awaye or f
open file or directoryg
reread directory structure from fileG
change group permissions (chgrp)k
delete line from listing on screen (don't actually delete)m
mark with *n
move to next lineo
open file in other window and go thereC-o
open file in other window but don't change thereP
print fileq
quit diredQ
do query-replace in marked filesR
rename fileu
remove markv
view file contentx
delete files marked with Dz
compress fileM-Del
remove all marks (whatever kind)~
mark backup files (name~ files) for deletion#
mark auto-save files (#name#) for deletion*/
mark directory with * (C-u * removes that mark again)=
compare this file with marked fileM-=
compare this file with it's backup file!
apply shell command to this fileM-}
change to the next file marked with * od DM-{
" previous "% d
mark files described through regular expression for deletion% m
" (with *)+
create directory>
changed to next dir<
change to previous dirs
toggle between sorting by name or dateMaybe into this category also fits this command:
M-x speedbar
starts up a separate window with a directory viewTelnet
M-x telnet
starts up telnet-modusC-d
either delete char or send EOFC-c C-c
stop running job (similar to C-c under unix)C-c C-d
send EOFC-c C-o
clear output of last commandC-c C-z
suspend execution of commandC-c C-u
kill line backwardsM-p
recall previous commandText
Works only in text mode
M-s
center lineM-S
center paragraphM-x center-region
name says Macro-commands
C-x (
start macro definitionC-x )
end of macro definitionC-x e
execute last definied macroM-n C-x e
execute last defined macro n timesM-x name-last-kbd-macro
give name to macro (for saving)M-x insert-keyboard-macro
save named macro into fileM-x load-file
load macroM-x macroname
execute macronameProgramming
M C-\
indent region between cursor and markM-m
move to first (non-space) char in this lineM-^
attach this line to previousM-;
formatize and indent commentC, C++ and Java Modes
M-a
beginning of statementM-e
end of statementM C-a
beginning of functionM C-e
end of functionC-c RETURN
Set cursor to beginning of function and mark at the endC-c C-q
indent the whole function according to indention styleC-c C-a
toggle modus in which after electric signs (like {}:';./*) emacs does the indentionC-c C-d
toggle auto hungry mode in which emacs deletes groups of spaces with one del-pressC-c C-u
go to beginning of this preprocessor statementC-c C-c
comment out marked areaMore general (I guess)
M-x outline-minor-mode
collapses function definitions in a file to a mere {...} M-x show-subtree
If you are in one of the collapsed functions, this un-collapses it In order to achive some of the feats coming up now you have to run etags *.c *.h *.cpp (or what ever ending you source files have) in the source directory
M-.
(Thats Meta dot) If you are in a function call, this will take you to it's definition M-x tags-search ENTER
Searches through all you etaged M-,
(Meta comma) jumps to the next occurence for tags-search M-x tags-query-replace
yum. This lets you replace some text in all the tagged files
GDB (Debugger)
M-x gdb
starts up gdm in an extra windowVersion Control
C-x v d
show all registered files in this dirC-x v =
show diff between versionsC-x v u
remove all changes since last checkinC-x v ~
show certain version in different windowC-x v l
print logC-x v i
mark file for version control addC-x v h
insert version control header into fileC-x v r
check out named snapshotC-x v s
create named snapshotC-x v a
create changelog file in gnu-style