Thursday, July 19, 2007

Emacs Notes

This is my general emacs knowledge base. Some of these keys/features I use everyday others I always forget about, hence the existence of these notes.

//           When opening (visiting) a file (C-x C-f), disregards everything before //
M-\          Kills whitespace pointed to by point
M-^          Merge the current line with previous line (taking away whitespace)
C-x C-x      swap mark and point
C-space      set new mark
C-u C-space  goto next mark in ring
C-M-space    mark to end of paren
C-t          transpose two chars
M-t          transpose two words
C-M-t        transpose two balanced expressions
C-M-f        move forward one balanced expression
C-M-b        move backward one balanced expression
C-M-k        kill balanced expression forward
C-M-<del>    kill balanced expression backward
C-x C-t      transpose two lines
M-m          move to first non-whitespace on line
C-c C-e      in C-mode expands macros into new buffer
C-M-q        toggle-read-only
C-x w h      highlight a regexp
C-x w r      unhighlight a regexp
M-x find-file-at-point Opens file at point
M-x apropos  Find an emacs command based on regexp
M-x woman    Advanced manual page browser
C-x >        scroll right
C-x <        scroll left
C-x C-+      Increase font size
C-X C--      Decrease font size

Narrowing
C-x n d      Narrow to defun  (one C-function)
C-x n n      Narrow to region
C-x n w      widen

Minibuffer
M-s          Search minibuffer history forward
M-r          Search minibuffer history backward

Kill Ring
C-h v kill-ring    View contents of kill ring
C-u C-y            Yank, but leave point at beginning of yanked text

TAGS (old tags)
M-. TAG            Find a TAG
C-u M-.            Find next TAG
C-M-. PATTERN      Find a TAG using regexp PATTERN
C-x 4 . TAG        Find a tag but put in another window
M-*                Pop back to where you invoked a TAG search
M-x tags-search    Search multiple files for regexp
M-,                Continue tags search
M-x list-tags FILE Lists all tags in a file
M-x tags-apropos   Lists all tags matching a regexp

GTAGS
M-. TAG                find TAG
M-? TAG                find all references to TAG
[f3] TAG               create TAG completion list "global -c TAG"
M-x gtags-symbol-find  find a symbol (similar to [f6])

M-x ps-spool-region-with-faces
M-x desktop-read
M-x desktop-save

"C-mode"
M-a  backward statement
M-e  forward statement
C-M-u  up conditional (block)
C-M-d  down conditional (block)
C-M-n  next conditional (block)
C-M-p  prev conditional (block)
C-c C-a  Toggle Autonewline minor mode
C-c C-d  Toggle Hungry Delete minor mode
C-c C-t  Toggle both Autnewline and Hungry Delete minor modes
C-c C-\  Add \'s to a region for multi-lined macros
C-u C-c C-\  Remove \'s from multi-line macros
M-q  In a C comment, wrap text appropriately.
M-j  Add a line break in a comment.
C-x `  go to next compilation error

DIRED
(to enter)
C-x d                Enter dired mode
C-x f [tab] [enter]  Enter dired mode while visiting file
(once in)
i                    Show contents of directory at point
g                    Update buffer (reread directory from disk)
d                    Mark file at point for deletion ('D' not '*')
u                    Ummark file at point
x                    Delete (expunge) files marked for deletion
% d <regexp>         Mark files for deletion matching regexp
% m <regexp>         Mark files matching regexp
% g <regexp>         Mark all files which contain regexp (like grep)
[del]                Unmark move point up one line
[enter]              Visit file at point
f                    Visit file at point (Same as [enter])
e                    Visit file at point (Same as [enter])
o                    Visit file at point in other window
C-o                  Visit file at point in other window, but stay in dired window
v                    View file at point (read only, q to quit)
^                    Move up to parent directory (..)
m                    Mark a file (with '*' not 'D')
* s                  Mark all files in current dired window
* t                  Toggle marked files (unmark all marked, mark all unmarked)
* %                  Same as  % m <regexp>  above
* !                  Unmark all marked
* /                  Mark all directories except . and ..
C <name>             Copy current file, see manual for multiple files (marked files)
R <name>             Rename current file, see manual for multiple files
M <mode>             Change mode of file(s) (uses chmod modes)
G <newgroup>         Like chgrp
O <newowner>         Like chown
S <name>             Make symbolic link
Z                    Compress marked files (or uncompress if compressed)
! <cmd>              Run shell command <cmd> on all marked files.  If <cmd> contains '*', '*' expands to all marked files
X <cmd>              Same as ! <cmd>
% R <from> <to>      Use regular expression to rename file ^.*$ to x-^.*$ adds "x-" to all marked files
% C <from> <to>      Use regular expression to copy file ^.*$ to x-^.*$ makes new files with "x-"
% S <from> <to>      Use regular expression to symlinks files ^.*$ to x-^.*$ adds "x-" to all symlinks
q                    Quit (kill dired buffer)
=                    diff files at point and mark (uses dired-diff as command)
M-=                  diff file at point with it latest backup (.*~)
C-x u                (undo, unmark all marked, restore names of renamed files)
M-x find-dired       Use the 'find' command to fill dired buffer
M-x find-name-dired  Use the 'find' command employing -name to fill dired buffer
M-x find-grep-dired  Use the 'find' command with grep to fill dired buffer
M-x locate           Similar to 'locate' command

VC (clearcase.el)
C-x C-q              Toggle read-only on non-version controlled element
                   Checkout or checkin (whatever makes sense) version controlled element
C-x v v              Checkout or checkin (whatever makes sense) version controlled element
C-x v ~ <version>    View a specific version of a file (dired mode kicks in on tab)
C-x v i              Runs mkelem on current buffer (NOT TESTED!)
C-x v l              Display history on current buffer
C-x v u              Revert element (uncheckout current buffer)
C-x v e              Edit config spec
C-c C-c              Finishes a comment session (on checkin or checkout)
v v                  (In dired mode) Checkout or checkin all marked files (whatever makes sense for each file)

Emacs server/client
(server-start)       Starts emacs server. Clients connect with emacsclient command.
C-x #                Unblock emacsclient and kill emacsclient buffer
EDITOR               (Environment variable, set this to emacsclient)
ALTERNATE_EDITOR     (Environment variable, set to a different editor if emacs server not running)

International input mode
C-\                  Enter\Get out of international input mode.
_a                   1ª (feminine ordinal)
_o                   1º (masculine oridinal)
~c                   ç (ce com cedilha)
~a                   ã,õ - nasals
^a                   â,ô,ê - circumflex (hat)
'a                   á,é,í,ó,ú, - accent (acento agudo)
`a                   à - grave accent (acento grave)

Environment Variables
M-x getenv
M-x setenv

GDB mode
C-x space            Set breakpoint at point
M-s                  step
M-n                  next
M-i                  stepi
M-c                  continue

Filtering/Searching
M-x occur <RET> REGEXP <RET>        Lists in a buffer all lines matching REGEXP
M-x how-many <RET> REGEXP <RET>     Shows how many lines match REGEXP
M-x flush-lines <RET> REGEXP <RET>  Filter out lines matching REGEXP
M-x keep-line <RET> REGEXP <RET>    Filter out all lines not matching REGEXP 

Rectangles
C-x r k              Kill a rectangle
C-x r y              Yank a rectangle
C-x r d              Delete contents of a rectangle
C-x r o              "open" a rectangle, inserts spaces the same size as the rectangle
C-x r t string       Replace contents of a rectangle with string
C-x r c              Clears a rectangle (replaces with spaces)

No comments: