From Eclipse to Emacs



This is my OLD blog. I've copied this post over to my NEW blog at:

http://www.saltycrane.com/blog/2007/09/from-eclipse-to-emacs/

You should be redirected in 2 seconds.



I am trying to learn Emacs after about a year of using Eclipse 3.2/3.3. See this post for some reasons why. Below is a list of Eclipse keyboard shortcuts and their Emacs equivalents. I'm using Emacs 22.1 for Windows.
ECLIPSE COMMAND SIMILAR EMACS COMMAND
(Emacs manuals use C for the CTRL key and M for the Meta or Alt key. So, e.g. C-x means CTRL+X. For Emacs long commands, you can type TAB to complete the command name.)

Cancel a command
ESC
Cancel a command
C-g

Open resource
CTRL+SHIFT+R
Find file
Keybinding: C-x C-f
Command: M-x find-file
Notes: Type in the file to open. Hit TAB for filename completion. Hit up and down arrows for recently used files.

Save file
CTRL+S
Save buffer
Keybinding: C-x C-s
Command: M-x save-buffer

Close
CTRL+F4
Kill this buffer
Keybinding: none
Command: M-x kill-this-buffer

Undo/Redo
CTRL+Z / CTRL+Y

Undo/ Undo Undo
Keybinding: C-_, C-x u, C-/
Command: M-x undo

To redo, interrupt the undo sequence by entering any command (e.g. C-f), then undo again. This undoes what you just undid, which is like redo. See 21.1 Undo in the GNU Emacs Manual.

This behavior can be confusing so there is also a RedoMode which behaves more like Eclipse and other editors. See RedoMode on the Emacs Wiki.

Switch editors
Keybinding: CTRL+F6 or CTRL+SHIFT+F6
Command: CTRL+3 Next Editor or CTRL+3 Previous Editor

Switch buffers
Keybinding: C-x RIGHTARROW or C-x LEFTARROW
See also: 24 Using Multiple Buffers in the Emacs Manual

Switch views
Keybinding: CTRL+F7 or CTRL+SHIFT+F7
Command: CTRL+3 Next View or CTRL+3 Previous View

After splitting into 2 windows with C-x 2, use C-x o to switch between windows.

To scroll the other window, use C-M-v. This is useful to reference one window while editing in the other.

To close the other window, type C-x 1 in the window you want to keep.

Find and Replace
Keybinding: CTRL+F
Incremental Search
Keybinding: C-s

Unconditional Replace
Command: M-x replace-string RET string RET newstring RET

Regexp Replacement
Command: M-x replace-regexp RET regexp RET newstring RET

See also: 20.9 Replacement Commands

Show line numbers
Keybinding: none
Command: CTRL+3 Show Line Numbers

Look in your status bar for the line number or see http://www.emacswiki.org/cgi-bin/wiki/LineNumbers

Code Completion
Keybinding: CTRL+SPC

Dynamic Abbrev Expansion
Keybinding: M-/
Command: M-x dabbrev-expand

This command is much faster and simpler than Eclipse because it doesn't use the compiler/interpreter. However, I think it is less robust for the same reason. At this point, I think I like the Eclipse version better.

See also 34.6 Dynamic Abbrev Expansion in the manual.

Keys
Command: CTRL+3 Keys - General

Key Bindings
Keybinding: C-h b
Command: M-x describe-bindings

Comment
Keybinding: CTRL+/

Comment region
Keybinding: none
Command: M-x comment-region

Shift Right (or Left)
Keybinding: TAB (SHIFT+BACKSPACE)

Shift Region Right (or Left)
Keybinding: C-c > (C-c <)
Command: ???

Note: This doesn't work if you're in CUA mode (i.e. using C-x/C-c/C-v Cut and Paste)

Find text in Workspace
Keybinding: CTRL+ALT+G
Command: Find Text in Workspace

grep (and variants)
Command: M-x lgrep RET string RET filepattern RET directory RET.

See also 32.4 Searching with Grep under Emacs

I still miss this one in Eclipse. grep has more power than Eclipse, but the combination of pretty highlighting and searching across files is nice in Eclipse. I have created an Elisp function to at least grep for selected text with one key stroke. Put the following in your .emacs and you'll get something similar to CTRL+ALT+G in Eclipse.
;; my eclipse CTRL+ALT+G replacement
(defun grep-selected (start end)
  (interactive "r") 
  (grep (concat "grep -nH -e " 
                (buffer-substring start end)
                " * .*"))
(global-set-key "\C-\M-g" 'grep-selected)
I am just learning to customize emacs with Elisp so I'm sure there are improvements that can be made.

No comments:

About

This is my *OLD* blog. I've copied all of my posts and comments over to my NEW blog at:

http://www.saltycrane.com/blog/.

Please go there for my updated posts. I will leave this blog up for a short time, but eventually plan to delete it. Thanks for reading.