Dec 18, 2007

EMCAS Command

SourceForge Logo
Emacs Commands List

C = Control
M = Meta = Alt|Esc

C-x C-f "find" file i.e. open/create a file in buffer
C-x C-s save the file
C-x C-w write the text to an alternate name
C-x C-v find alternate file
C-x i insert file at cursor position
C-x b create/switch buffers
C-x C-b show buffer list
C-x k kill buffer
C-z suspend emacs
C-X C-c close down emacs

Basic movement
C-f forward char
C-b backward char
C-p previous line
C-n next line
M-f forward one word
M-b backward one word
C-a beginning of line
C-e end of line
C-v one page up
M-v scroll down one page
M-< beginning of text
M-> end of text

M-n repeat the following command n times
C-u repeat the following command 4 times
C-u n repeat n times
C-d delete a char
M-d delete word
M-Del delete word backwards
C-k kill line

C-Space Set beginning mark (for region marking for example)
C-W "kill" (delete) the marked region region
M-W copy the marked region
C-y "yank" (paste) the copied/killed region/line
M-y yank earlier text (cycle through kill buffer)
C-x C-x exchange cursor and mark

C-t transpose two chars
M-t transpose two words
C-x C-t transpose lines
M-u make letters uppercase in word from cursor position to end
M-c simply make first letter in word uppercase
M-l opposite to M-u

C-g quit the running/entered command
C-x u undo previous action
M-x revert-buffer RETURN (insert like this) undo all changes since last save
M-x recover-file RETURN Recover text from an autosave-file
M-x recover-session RETURN if you edited several files

C-h c which command does this keystroke invoke
C-h k which command does this keystroke invoke and what does it do?
C-h l what were my last 100 typed keys
C-h w what key-combo does this command have?
C-h f what does this function do
C-h v what's this variable and what is it's value
C-h b show all keycommands for this buffer
C-h t start the emacs tutorial
C-h i start the info reader
C-h C-k start up info reader and go to a certain key-combo point
C-h F show the emacs FAQ
C-h p show infos about the Elisp package on this machine

C-s Search forward
C-r search backward
C-g return to where search started (if you are still in search mode)
M-% query replace

Space or y replace this occurence
Del 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 match
RETURN 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 forward
M C-r RETURN search for regular expression backward
M C-s incremental search
C-s repeat incremental search
M C-r incremental search backwards
C-r repeat backwards
M-x query-replace-regexp search and replace

C-x 2 split window vertically
C-x o change to other window
C-x 0 delete window
C-x 1 close all windows except the one the cursors in
C-x ^ enlarge window
M-x shrink-window command says it ;-)
M C-v scroll other window
C-x 4 f find file in other window
C-x 4 o change to other window
C-x 4 0 kill buffer and window
C-x 5 2 make new frame
C-x 5 f find file in other frame
C-x 5 o change to other frame
C-x 5 0 close this frame

Bookmark commands
C-x r m set a bookmark at current cursor pos
C-x r b jump to bookmark
M-x bookmark-rename says it
M-x bookmark-delete "
M-x bookmark-save "
C-x r l list bookmarks

d mark bookmark for deletion
r rename bookmark
s save all listed bookmarks
f show bookmark the cursor is over
m mark bookmarks to be shown in multiple window
v show marked bookmarks (or the one the cursor is over)
t toggle listing of the corresponding paths
w " path to this file
x delete marked bookmarks
Del ?
q quit bookmark list

M-x bookmark-write write all bookmarks in given file
M-x bookmark-load load bookmark from given file

M-x shell starts shell modus
C-c C-c same as C-c under unix (stop running job)
C-d delete char forward
C-c C-d Send EOF
C-c C-z suspend job (C-z under unix)
M-p show previous commands

DIRectory EDitor (dired)
C-x d start up dired
C (large C) copy
d mark for erase
D delete right away
e or f open file or directory
g reread directory structure from file
G change group permissions (chgrp)
k delete line from listing on screen (don't actually delete)
m mark with *
n move to next line
o open file in other window and go there
C-o open file in other window but don't change there
P print file
q quit dired
Q do query-replace in marked files
R rename file
u remove mark
v view file content
x delete files marked with D
z compress file
M-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 file
M-= compare this file with it's backup file
! apply shell command to this file
M-} change to the next file marked with * od D
M-{ " previous "
% d mark files described through regular expression for deletion
% m " (with *)
+ create directory
> changed to next dir
< change to previous dir
s toggle between sorting by name or date

Maybe into this category also fits this command:
M-x speedbar starts up a separate window with a directory view

M-x telnet starts up telnet-modus
C-d either delete char or send EOF
C-c C-c stop running job (similar to C-c under unix)
C-c C-d send EOF
C-c C-o clear output of last command
C-c C-z suspend execution of command
C-c C-u kill line backwards
M-p recall previous command

Works only in text mode
M-s center line
M-S center paragraph
M-x center-region name says

C-x ( start macro definition
C-x ) end of macro definition
C-x e execute last definied macro
M-n C-x e execute last defined macro n times
M-x name-last-kbd-macro give name to macro (for saving)
M-x insert-keyboard-macro save named macro into file
M-x load-file load macro
M-x macroname execute macroname

M C-\ indent region between cursor and mark
M-m move to first (non-space) char in this line
M-^ attach this line to previous
M-; formatize and indent comment
C, C++ and Java Modes
M-a beginning of statement
M-e end of statement
M C-a beginning of function
M C-e end of function
C-c RETURN Set cursor to beginning of function and mark at the end
C-c C-q indent the whole function according to indention style
C-c C-a toggle modus in which after electric signs (like {}:';./*) emacs does the indention
C-c C-d toggle auto hungry mode in which emacs deletes groups of spaces with one del-press
C-c C-u go to beginning of this preprocessor statement
C-c C-c comment out marked area
More 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 window

Version Control
C-x v d show all registered files in this dir
C-x v = show diff between versions
C-x v u remove all changes since last checkin
C-x v ~ show certain version in different window
C-x v l print log
C-x v i mark file for version control add
C-x v h insert version control header into file
C-x v r check out named snapshot
C-x v s create named snapshot
C-x v a create changelog file in gnu-style


8.1.2002: The first part comes here

Last update: 8.1.2002

Nov 18, 2007


Basic Emacs Editor Commands

Colorado State University

Basic Emacs Editor Commands

What is Emacs?

Emacs is another editor available in UNIX. Like vi, emacs is a screen editor. Unlike vi, emacs is not an insertion mode editor, meaning that any character typed in emacs is automatically inserted into the file, unless it includes a command prefix.

Commands in emacs are either control characters (hold down the <Ctrl> key while typing another character) or are prefixed by one of a set of reserved characters: <Esc> or <Ctrl>-X. The <Esc> key can be typed by itself (because it really is a character) and then followed by another character; the <Ctrl> key must be held down while the next character is being typed. The conventions for describing these characters (since it takes too long to type out the whole thing) are ESC means <Esc> and C- means <Ctrl>.

One other distinction between emacs and vi is that emacs allows you to edit several files at once. The window for emacs can be divided into several windows, each of which contains a view into a buffer. Each buffer typically corresponds to a different file. Many of the commands listed below are for reading files into new buffers and moving between buffers.

To use emacs on a file, type
        emacs filename
If the file named filename exists, then the first screen's worth of the file is displayed; if it doesn't exist, a help message is displayed.

The easiest way to learn emacs is to start it up and go through the on-line tutorial. To access the on-line tutorial, type
        ESC help-with-tutorial
immediately after you have started emacs. The tutorial directs you further in learning the basic commands. One notational point you should know is that the tutorial uses M- to mean ESC.

To give you a head start, the following table lists the basic commands you need to know to use emacs to edit a file. An asterisk (* or star) to the left of a command indicate it is one to learn immediately.

Help Commands

* C-h help-command: first character in lots of useful help commands
* C-h t help-with-tutorial: command to run the tutorial
C-h i information: describes most of the emacs commands in man style pages
C-h k describe-key: tells you what a particular key stroke does
* C-h a command-apropos: prompts for a string and
then searches for all emacs commands that contains that string
ESC ? also does command-apropos
* C-h ? help-for-help: describes how to use the help facilities

File Reading and Writing Commands

* C-x C-f find-file: first prompts for a filename and
then loads that file into a editor buffer of the same name
* C-x C-s save-buffer: saves the buffer into the associated filename
C-x C-w write-named-file: prompts for a new filename and writes the buffer into it

Cursor/Screen Movement Commands

Depending on the terminal, some of the cursor movement can be handled by the arrow keys.

* C-a move cursor to (at) beginning-of-line
C-e move cursor to end-of-line
* C-f move cursor forward one character
* C-b move cursor backward one character
* C-n move cursor to next line
* C-p move cursor to previous line
C-v scroll file forward by one screenful
ESC v scroll file backward by one screenful
* ESC < go to beginning-of-buffer
* ESC > go to end-of-buffer
ESC f move cursor forward one word
ESC b move cursor backward one word

Copy and Delete Commands

C-d delete-char: delete character under cursor
ESC d delete-word: delete from cursor to end of word immediately ahead of the cursor
* C-k kill-line: delete the rest of the current line
* C-@ set-mark-command: mark is used to indicate the beginning of an area of text to be yanked
* C-w kill-region: delete the area of text between the mark and the current cursor position
* C-y yank: insert at current cursor location whatever was most recently deleted
ESC w copy-region-as-kill: copy area between mark and cursor into kill-buffer
so that it can be yanked into someplace else

Search Commands

* C-s isearch-forward: prompts for text string and
then searches from the current cursor position forwards in the buffer
C-r isearch-backward: like isearch-forward,
but searches from the current cursor position to end of buffer for text string
ESC % query-replace: prompts for a search string and
a string with which to replace the search string

Window and Buffer Commands

C-x 0 zero-window: deletes current window
C-x 2 double-window: splits current window into two parts,
allowing you to edit at two different locations in the same file
or permitting you to view two different files at the same time
C-x b switch-to-buffer: display a different buffer on the screen
C-x o other-window: move the cursor to the other window
(assuming that you have two windows/buffers open at once
* C-x C-b list-buffers: lists those buffers currently loaded into emacs

Exiting Emacs, Fixing Mistakes and Other Important Stuff

* C-x C-c save-buffers-kill-emacs: when you are finished editing,
to save the edited but unsaved buffers
and to return you to the UNIX prompt
* C-g keyboard-quit: if while typing a command you make a mistake and want to stop,
this aborts a command in progress
C-u universal-argument: if you want to do a command several times,
type this command
followed by a number (for the number of times)
followed by the command you wish repeated
* C-x u undo: undoes the last command typed, in case you made a mistake
* ESC x execute-extended-command: prompts for the name of an emacs command;
allows you to execute a command
if you know roughly what it is called
but cannot remember the key strokes for it

Other Emacs Bindings

Emacs has many other useful commands. As you get more proficient at it, try listing the key bindings (ESC-x for describe-bindings) to find other commands. Also note that emacs has what is called escape-completion: as you type in commands or filenames, you can type a space at any time and emacs will either fill out the rest (if there is only one possible completion) or it will list the possible completions in a new window.

A Web page with a complete list of emacs bindings is also available.

Copyright &#169 1998: Colorado State University, CS Department. All rights reserved.

Emacs Command Summary

Emacs command summary, Thu Jul 25.

C-SP set-mark-command C-q quoted-insert
C-a beginning-of-line C-r isearch-backward
C-b backward-char C-s isearch-forward
C-c exit-recursive-edit C-t transpose-chars
C-d delete-char C-u universal-argument
C-e end-of-line C-v scroll-up
C-f forward-char C-w kill-region
C-h help-command C-x Control-X-prefix
TAB indent-for-tab-command C-y yank
LFD newline-and-indent C-z suspend-emacs
C-k kill-line ESC ESC-prefix
C-l recenter C-] abort-recursive-edit
RET newline C-_ undo
C-n next-line SPC .. ~ self-insert-command
C-o open-line DEL delete-backward-char
C-p previous-line

C-h v describe-variable C-h d describe-function
C-h w where-is C-h k describe-key
C-h t help-with-tutorial C-h c describe-key-briefly
C-h s describe-syntax C-h b describe-bindings
C-h n view-emacs-news C-h a command-apropos
C-h C-n view-emacs-news C-h C-d describe-distribution
C-h m describe-mode C-h C-c describe-copying
C-h l view-lossage C-h ? help-for-help
C-h i info C-h C-h help-for-help
C-h f describe-function

C-x C-a add-mode-abbrev C-x 5 split-window-horizontally
C-x C-b list-buffers C-x ; set-comment-column
C-x C-c save-buffers-kill-emacs C-x < scroll-left
C-x C-d list-directory C-x = what-cursor-position
C-x C-e eval-last-sexp C-x > scroll-right
C-x C-f find-file C-x [ backward-page
C-x C-h inverse-add-mode-abbrev C-x ] forward-page
C-x TAB indent-rigidly C-x ^ enlarge-window
C-x C-l downcase-region C-x ` next-error
C-x C-n set-goal-column C-x a append-to-buffer
C-x C-o delete-blank-lines C-x b switch-to-buffer
C-x C-p mark-page C-x d dired
C-x C-q toggle-read-only C-x e call-last-kbd-macro
C-x C-r find-file-read-only C-x f set-fill-column
C-x C-s save-buffer C-x g insert-register
C-x C-t transpose-lines C-x h mark-whole-buffer
C-x C-u upcase-region C-x i insert-file
C-x C-v find-alternate-file C-x j register-to-dot
C-x C-w write-file C-x k kill-buffer
C-x C-x exchange-dot-and-mark C-x l count-lines-page
C-x C-z suspend-emacs C-x m mail
C-x ESC repeat-complex-command C-x n narrow-to-region
C-x $ set-selective-display C-x o other-window
C-x ( start-kbd-macro C-x p narrow-to-page
C-x ) end-kbd-macro C-x q kbd-macro-query
C-x + add-global-abbrev C-x r copy-rectangle-to-register
C-x - inverse-add-global-abbrev C-x s save-some-buffers
C-x . set-fill-prefix C-x u advertised-undo
C-x / dot-to-register C-x w widen
C-x 0 delete-window C-x x copy-to-register
C-x 1 delete-other-windows C-x { shrink-window-horizontally
C-x 2 split-window-vertically C-x } enlarge-window-horizontally
C-x 4 ctl-x-4-prefix C-x DEL backward-kill-sentence

ESC C-SP mark-sexp ESC = count-lines-region
ESC C-a beginning-of-defun ESC > end-of-buffer
ESC C-b backward-sexp ESC @ mark-word
ESC C-c exit-recursive-edit ESC O ??
ESC C-d down-list ESC [ backward-paragraph
ESC C-e end-of-defun ESC delete-horizontal-space
ESC C-f forward-sexp ESC ] forward-paragraph
ESC C-h mark-defun ESC ^ delete-indentation
ESC LFD indent-new-comment-line ESC a backward-sentence
ESC C-k kill-sexp ESC b backward-word
ESC C-n forward-list ESC c capitalize-word
ESC C-o split-line ESC d kill-word
ESC C-p backward-list ESC e forward-sentence
ESC C-s isearch-forward-regexp ESC f forward-word
ESC C-t transpose-sexps ESC g fill-region
ESC C-u backward-up-list ESC h mark-paragraph
ESC C-v scroll-other-window ESC i tab-to-tab-stop
ESC C-w append-next-kill ESC j indent-new-comment-line
ESC ESC ?? ESC k kill-sentence
ESC C- indent-region ESC l downcase-word
ESC SPC just-one-space ESC m back-to-indentation
ESC ! shell-command ESC q fill-paragraph
ESC $ spell-word ESC r move-to-window-line
ESC % query-replace ESC t transpose-words
ESC ' abbrev-prefix-mark ESC u upcase-word
ESC ( insert-parentheses ESC v scroll-down
ESC ) move-past-close-and-reindent ESC w copy-region-as-kill
ESC , tags-loop-continue ESC x execute-extended-command
ESC - negative-argument ESC y yank-pop
ESC . find-tag ESC z zap-to-char
ESC 0 .. ESC 9 digit-argument ESC | shell-command-on-region
ESC ; indent-for-comment ESC ~ not-modified
ESC < beginning-of-buffer ESC DEL backward-kill-word

C-x 4 C-f find-file-other-window C-x 4 d dired-other-window
C-x 4 . find-tag-other-window C-x 4 f find-file-other-window
C-x 4 b pop-to-buffer C-x 4 m mail-other-window

Nov 17, 2007

linux command

常用命令动词 简要说明
cd directory 进入指定的目录
cd .. 进入上一级目录
cd /directory 进入目录
cd 进入用户自己的目录
cp file_from file_to 拷贝文件
ln [-s] source linkname 为一个文件建立连结
ls [directory] 查看指定目录下的文件
ls -l [directory] 查看指定目录下文件的详细
ls -a [directory] 查看指定目录下的所有文件
mkdir new_directory 建一个新目录
more file 查看一个文本文件的内容
rm file 删除一个文件
rm -r directory 删除一个目录
rmdir directory 删除一个目录
find . -name "file" 从当前目录开始查找指定的文件
adduser 创建新用户
alias 设置别名或替代名
bg fg 使挂起的进程继续运行
ps ax 查询当前进程
mount 连接文件系统
more less 浏览文件内容
chown chgrp 改变文件的拥有者
chmod 改变文件属性
halt 关闭系统
man 显示手册页
passwd 改变用户口令
grep 查找字符串
find 查找文件
dd 复制磁盘或文件系统
kill 杀掉一个进程
killall 杀掉进程

Linux BASH: vi Editor Commands

Linux BASH syntax : vi Editor Commands

Switch to Text or Insert mode:

Open line above cursor
Insert text at beginning of line
Insert text at cursor
Insert text after cursor
Append text at line end
Open line below cursor

Switch to Command mode:

Switch to command mode

Cursor Movement (command mode):

Scroll Backward 1 screen
Scroll Up 1/2 screen
Go to beginning of line
Go to line n
Go to end of line
Scroll Down 1/2 screen
Go to line number ##
Scroll Forward 1 screen
Go to last line
Scroll by sentence f/b ( )
Scroll by word f/b w b Move left, down, up, right h j k l
Left 6 chars
Directional Movement Arrow Keys
Go to line #6

Deleting text (command mode):

Change word
Replace one character
Delete word
Delete text at cursor
Delete entire line (to buffer)
Delete current to end of line
Delete 5 lines (to buffer)
Delete lines 5-10

Editing (command mode):

Copy line
Copy n lines
Copy lines 1-2/paste after 3
:1,2t 3
Paste above current line

Paste below current line
Move lines 4-5/paste after 6
:4,5m 6
Join previous line
Search backward for string
Search forward for string
/string Find next string occurrence n
% (entire file) s (search and replace) /old text with new/ c (confirm) g (global - all)
Ignore case during search
:set ic
Repeat last command
Undo previous command
Undo all changes to line

Save and Quit (command mode):

Save changes to buffer
Save changes and quit vi
Save file to new file
:w file
Quit without saving
Save lines to new file
:10,15w file

Related commands:

Book - Learning the vi Editor (6th Edition)
Full list of VI commands
vi Tutorial - simple text editor
Pico - short for Pine Composer

Back to the Top

Simon Sheppard

vi command summary

The following tables contain all the basic vi commands.

Starting vi

Command Description
vi file start at line 1 of file
vi +n file start at line n of file
vi + file start at last line of file
vi +/pattern file start at pattern in file
vi -r file recover file after a system crash

Saving files and quitting vi

Command Description
:e file edit file (save current file with :w first)
:w save (write out) the file being edited
:w file save as file
:w! file save as an existing file
:q quit vi
:wq save the file and quit vi
:x save the file if it has changed and quit vi
:q! quit vi without saving changes

Moving the cursor

Keys pressed Effect
h left one character
l or <Space> right one character
k up one line
j or <Enter> down one line
b left one word
w right one word
( start of sentence
) end of sentence
{ start of paragraph
} end of paragraph
1G top of file
nG line n
G end of file
<Ctrl>W first character of insertion
<Ctrl>U up ½ screen
<Ctrl>D down ½ screen
<Ctrl>B up one screen
<Ctrl>F down one screen

Inserting text

Keys pressed Text inserted
a after the cursor
A after last character on the line
i before the cursor
I before first character on the line
o open line below current line
O open line above current line

Changing and replacing text

Keys pressed Text changed or replaced
cw word
3cw three words
cc current line
5cc five lines
r current character only
R current character and those to its right
s current character
S current line
~ switch between lowercase and uppercase

Deleting text

Keys pressed Text deleted
x character under cursor
12x 12 characters
X character to left of cursor
dw word
3dw three words
d0 to beginning of line
d$ to end of line
dd current line
5dd five lines
d{ to beginning of paragraph
d} to end of paragraph
:1,. d to beginning of file
:.,$ d to end of file
:1,$ d whole file

Using markers and buffers

Command Description
mf set marker named ``f''
`f go to marker ``f''
´f go to start of line containing marker ``f''
"s12yy copy 12 lines into buffer ``s''
"ty} copy text from cursor to end of paragraph into buffer ``t''
"ly1G copy text from cursor to top of file into buffer ``l''
"kd`f cut text from cursor up to marker ``f'' into buffer ``k''
"kp paste buffer ``k'' into text

Searching for text

Search Finds
/and next occurrence of ``and'', for example, ``and'', ``stand'', ``grand''
?and previous occurrence of ``and''
/^The next line that starts with ``The'', for example, ``The'', ``Then'', ``There''
/^The> next line that starts with the word ``The''
/end$ next line that ends with ``end''
/[bB]ox next occurrence of ``box'' or ``Box''
n repeat the most recent search, in the same direction
N repeat the most recent search, in the opposite direction

Searching for and replacing text

Command Description
:s/pear/peach/g replace all occurrences of ``pear'' with ``peach'' on current line
:/orange/s//lemon/g change all occurrences of ``orange'' into ``lemon'' on next line containing ``orange''
:.,$/<file/directory/g replace all words starting with ``file'' by ``directory'' on every line from current line onward, for example, ``filename'' becomes ``directoryname''
:g/one/s//1/g replace every occurrence of ``one'' with 1, for example, ``oneself'' becomes ``1self'', ``someone'' becomes ``some1''

Matching patterns of text

Expression Matches
. any single character
* zero or more of the previous expression
.* zero or more arbitrary characters
< beginning of a word
> end of a word
quote a special character
* the character ``*''
^ beginning of a line
$ end of a line
[set] one character from a set of characters
[XYZ] one of the characters ``X'', ``Y'', or ``Z''
[[:upper:]][[:lower:]]* one uppercase character followed by any number of lowercase characters
[^set] one character not from a set of characters
[^XYZ[:digit:]] any character except ``X'', ``Y'', ``Z'', or a numeric digit

Options to the :set command

Option Effect
all list settings of all options
ignorecase ignore case in searches
list display <Tab> and end-of-line characters
mesg display messages sent to your terminal
nowrapscan prevent searches from wrapping round the end or beginning of a file
number display line numbers
report=5 warn if five or more lines are changed by command
term=ansi set terminal type to ``ansi''
terse shorten error messages
warn display ``[No write since last change]'' on shell escape if file has not been saved

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005