Tuesday, 10 July 2012

Finally autocomplete in Emacs

CREDITS TO:

http://www.quora.com/What-are-the-most-useful-shortcuts-in-Emacs

Most useful shortcuts:

C-_ undo (to redo after undoing, I press space and then C-_ again)
C-g cancel, essential if you make a mistake entering another shortcut
C-s search (incremental), great for navigating around a buffer
M-%  replace, see Jeff Hammerbacher's answer to How can you perform search and replace in Emacs?
M-g g  go-to line
M-; comment, see Adam Hupp's answer to How can I comment out an entire block of text in Emacs?
M-/ autocompletion, from Edmond Lau

You type a prefix, invoke the function, and it'll auto-complete with the strings that are found in other open buffers in your emacs process.  It's not exactly auto-completing from the entire codebase but is fast and works well.  Invoking the function multiple times cycles through possible completions.

Useful Basic Commands:

C-x C-s save file
C-x C-c  exit
C-x C-f open file
C-k kill (cut) from current position to end of line (use this to cut & paste lines)
C-<spacebar> set mark, select region
C-a / C-e beginning/end of line
M-< / M->  beginning/end of buffer
C-x C-x  move back to mark
C-w / M-w wipe (cut/copy)
C-y yank (paste)
C-x b switch buffer (C-x C-b lists buffers)
M-<right/left arrows>  move cursor from one word to the previous/next

Useful Advanced Commands:

M-x lets you type in a command (e.g. M-x revert-buffer reloads the buffer from disk). Some examples:

M-x shell: opens a shell in emacs (but auto-complete doesn't seem to work)
M-x grep: runs grep within emacs
(M-x compile and M-x gdb are nice, too)

Typing C-u before another command lets you supply an argument

M-: lets you evaluate lisp expressions (e.g. rebind a key on the fly)

You can also define new shortcuts by binding keys to commands.  For example:

1
2
3
4
5
6
(defun prev-window ()
  (interactive)
  (other-window -1))

(global-set-key "\033[5D" 'prev-window)
(global-set-key "\033[5C" 'other-window)


makes ctrl-<left arrow> and ctrl-<right arrow> move between windows.

0 comments:

Post a Comment