.emacs
file:(global-set-key "C-Z" nil)
Copy into register 1:
Paste from register 1:
View the contents of a register
Register names can be single letters, numbers, characters. Upper and lower case are distinct.
#define DONT_REOPEN_PTY
(setq c-default-style "bsd" c-basic-offset 4)
deletechar
into backward-delete-char-untabify
causes backspace in incremental search to cancel the search, which is annoying.
One option is to set the TERM env var to rxvt:
% setenv TERM rxvtBefore cranking up screen.
C-x (
: start recording keyboard macroC-x )
: stop recording keyboard macroC-x e
: replay current keyboard macro.emacs
file. This will make spaces the indent character, and use 4 spaces per indent level, for C, C++, and Objective C:
(setq c-mode-hook (function (lambda () (setq indent-tabs-mode nil) (setq c-indent-level 4)))) (setq objc-mode-hook (function (lambda () (setq indent-tabs-mode nil) (setq c-indent-level 4)))) (setq c++-mode-hook (function (lambda () (setq indent-tabs-mode nil) (setq c-indent-level 4))))
.emacs(add-to-list 'auto-mode-alist '("\\.h$" . objc-mode))- Rectangular cut and paste
[permalink]
- Move to top-left of source rectangle.
C-SPC
to set the mark
- Move to bottom-right of source rectangle
-
M-x kill-rectangle
- Move to paste destination
-
M-x yank-rectangle
- Resetting shell mode's idea of the current working directory
[permalink]
Sometimes the shell mode will get confused as to what the current working directory is (like if you use aliases to move to a new directory, or if you
use the conveniences like !$
). M-x dirs
will tell the shell buffer to figure out what the current working directory is. - Restrict editing to the region
[permalink]
M-x narrow-to-region
Hides everything not in the current region.
- Revisiting / reloading a file in emacs
[permalink]
The $Id: $
tags for CVS are nice, but it can be a pain when you're doing lots of checkins and have to re-load the file each time. You can either execute M-x revert-bufer
or bind that to a key, or else use a trick by doing C-x C-v
which invokes find-alternate-file
, but just so happens to have the current buffer name, so you just have to do C-x C-v RET
- Running shell command pasting result back into the buffer
[permalink]
So to run uuidgen
, for instance:
C-U M-!
ret uuidgen
ret
- Scroll line with cursor to the top of the window
[permalink]
C-U 0 C-L
(you can put in another number besides zero to scroll the line with the cursor to that particular line in the buffer)
- Setting variables when loading a file
[permalink]
So say you're working on a project with two-space indents, but most of your other work happens with four-space indents. If the two-space crowd is amenable, add this to the bottom of the file:
/* For the emacs weenies in the crowd.
Local Variables:
c-basic-offset: 2
End:
*/
- Showing current column position
[permalink]
M-x column-number-mode
- Sort case-insensitive
[permalink]
M-x sort-lines
uses a case-sensitive search. When that sucks, you can tell emacs to be case insensitive (globally) by doing M-x set-variable RET sort-fold-case RET t
- Toggling read-only mode in a buffer
[permalink]
C-X C-Q
- Turning off command highlighting in shell mode
[permalink]
Emacs 21, which comes with Mac OS X 10.2, "helpfully" puts into bold the commands you execute in the shell. This drives me nuts, so I figured out how to turn it off. Add this to your .emacs file:
(setq comint-highlight-input nil)
- Turning off font-lock mode everywhere
[permalink]
(global-font-lock-mode -1)
- Turning off incremental-search highlighting
[permalink]
Emacs 21, which comes with Mac OS X 10.2, has highlighting enabled when doing incremental search (which drives me nuts). You can turn that off by setting this in your .emacs file:
(setq search-highlight nil)
You may also need to
(setq isearch-lazy-highlight nil)
To turn off underlining of matching results. Only some OS X installs need this setting.
- Turning off scroll-to-end in shell-mode
[permalink]
(setq comint-scroll-show-maximum-output nil)
- Undo within a given region
[permalink]
C-U C-_
- Unnarrowing the region
[permalink]
M-x widen
- Use only spaces when indenting code
[permalink]
(setq indent-tabs-mode nil) - Using carriage returns in query-replace / replace-string
[permalink]
Use C-Q C-J
(control-Q control-J) each time you want to include a carriage return. e.g. to double-space everything
M-x replace-string RET C-Q C-J RET C-Q C-J C-Q C-J RET
Or to put "bloogie " at the beginning of every line
M-x replace-string RET C-Q C-J RET C-Q C-J b l o o g i e SPACE RET
- compiling emacs .el files
[permalink]
Big emacs .el
files take a long time to load.
You can compile them into .elc
files by using:
% emacs -batch -f batch-byte-compile filename.el
- emacs registers
[permalink]
Stick something into a register:
(select stuff)
C-x r x 1
where "1" is the register identifier.
Getting stuff out of a register:
C-x r g 1
(global-set-key (kbd "C-x p") 'move-to-previous-window) (defun move-to-previous-window () "Move to the previous window." (interactive) (other-window -1))
C-/