Recently I've decided to try the dark side of the force - emacs.
I'm Vim user for a long time. Several times I wanted to try emacs but didn't have a good chance.
Now I'm working on project with huge amount of sources and I decided to try emacs for it.
It works! ;)
Playing with emacs I've found out that it's not so complex as some people say.
The thing to which I couldn't get used to for some time is that I don't have to press ESC to switch to the command mode, press i(INS) to switch to editor mode and so on.
I haven't found some Vim features(as visual mode) but I believe that just don't know how to make them work.
The main difference is that there is no distinct differences between editor mode and command mode. You are allowed to run commands while you are editing the text.
All commands(or better to say most of them) begin with control- or meta- character. control is usually Ctrl on your keyboard and meta is Alt.
For guys who want to try emacs here is the migration guide on vim-to-emacs commands.
The table of equivalence of vim and emacs commands.
VIM | EMACS | Description |
:qa/:wqa/:xa/:qa! | C-x C-c | exit(emacs prompts whether to save buffers or not) |
h | C-b | left |
l | C-f | right |
b/B | M-b | word backward |
w/W | M-f | word forward |
j | C-n | down |
k | C-p | up |
0 | C-a | beginning of the line |
$ | C-e | end of the line |
gg/1G | C-< | beginning of the buffer |
G | C-> | end of the buffer |
x | C-d | delete under cursor |
D | C-k | delete from cursor to EOL |
dd | C-k C-k | delete line |
dw/dW | M-d | delete word |
db/dB | M-{BACKSPACE} | delete word backwards |
:set ignorecase {ENTER} / | C-s {needle in lower case} | icase search forward |
:set ignorecase {ENTER} ? | C-r {needle in lower case} | icase search backward |
/ | C-s | search forward |
? | C-r | search backward |
:set ignorecase {ENTER} / | M-C-s {regexp in lower case} | icase regexp search forward |
:set ignorecase {ENTER} ? | M-C-r {regexp in lower case} | icase regexp search backward |
:%s/{needle}/{replacement}/gc | M-% {needle} {ENTER} {replacement} {ENTER} | query replace |
/ | M-C-s | regexp search forward |
? | M-C-r | regexp search backward |
u | C-_/C-x u | undo |
C-R | C-_/C-x u | redo(it's tricky for emacs*) |
ESC | C-g | quit the running/entered command(switch to command mode in Vim) |
:e file | C-x C-f | open file |
:set ro | C-x C-q | set file as read-only |
:w | C-x C-s | save buffer |
:w file | C-x C-w file | save buffer as ... |
:wa | C-x s | save all buffers |
:buffers | C-x C-b | show buffers |
:b [name] | C-x b [name] | switch to another buffer |
:q/:q!/:wq/:x | C-x k | close buffer |
C-w n/:split | C-x 2 | split horizontal|
C-w v/:vsplit | C-x 3 | split vertical|
C-w C-w | C-x o | switch to another window |
:q | C-x 0 | close window |
C-w o | C-x 1 | close other windows |
:! {cmd} | M-! | run shell command |
m{a-zA-Z} | C-@/C-space | set mark |
C-x C-x | exchange mark and position | |
{visual}y | M-w | copy region** |
{visual}d | C-w | delete region** |
p | C-y | paste |
C-V {key} | C-q {key} | insert special char, e.g. ^M: |
{visual}SHIFT-> | C-x TAB | indent region |
C-] | M-. | find tag |
C-t | M-* | return to previous location |
:e! | M-x revert-buffer | reload buffer from disk |
*To redo changes you have undone, type `C-f' or any other command that will harmlessly break the
sequence of undoing, then type more undo commands
**region is from current position to the mark
Other useful emacs commands:
M-g | go to line |
C-x i | insert file |
C-x h | mark whole buffer |
C-x C-t | switch two lines |
M-C-a | beginning of the function |
M-C-e | end of the function |
M-a | beginning of the statement |
M-e | end of the statement |
M-C-h | mark the function |
M-/ | autocompletion |
M-C-\ | indent region |
C-c C-q | indent the whole function according to indention style |
C-c C-c | comment out marked area |
M-x uncomment-region | uncomment marked area |
M-, | jumps to the next occurence for tags-search |
M-; | insert comment in code |
C-x w h | highlight the text by regexp |
C-x w r | disable highlighting the text by regexp |
To run emacs without X add -nw command line argument.
To run multiply commands 'C-u {number} {command}' or 'M-{digit} {command}'.
emacs has bookmarks that are close to Vim marks:
C-x r m | set a bookmark at current cursor position |
C-x r b | jump to bookmark |
C-x r l | list bookmarks |
M-x bookmark-write | write all bookmarks in given file |
M-x bookmark-load | load bookmarks from given file |
My ~/.emacs looks like:
(setq load-path (cons "~/.emacs.d" load-path)) (auto-compression-mode t) ; uncompress files before displaying them (global-font-lock-mode t) ; use colors to highlight commands, etc. (setq font-lock-maximum-decoration t) (custom-set-faces) (transient-mark-mode t) ; highlight the region whenever it is active (show-paren-mode t) ; highlight parent brace (global-hi-lock-mode t) ; highlight region by regexp (column-number-mode t) ; column-number in the mode line (setq make-backup-files nil) (setq scroll-conservatively most-positive-fixnum) ; scroll only one line when I move past the bottom of the screen (add-hook 'text-mode-hook 'turn-on-auto-fill) ; break lines at space when they are too long (fset 'yes-or-no-p 'y-or-n-p) ; make the y or n suffice for a yes or no question (setq comment-style 'indent) (global-set-key (kbd "C-x C-b") 'buffer-menu) ; buffers menu in the same window (global-set-key (kbd "C-x 3") 'split-window-horizontally-other) ; open new window horisontally and switch to it (defun split-window-horizontally-other () (interactive) (split-window-horizontally) (other-window 1) ) (global-set-key (kbd "C-x 2") 'split-window-vertically-other) ; open new window vertically and switch to it (defun split-window-vertically-other () (interactive) (split-window-vertically) (other-window 1) ) (global-set-key (kbd "C-c c") 'comment-region) ; comment code block (global-set-key (kbd "C-c u") 'uncomment-region) ; uncomment code block (global-set-key (kbd "C-x TAB") 'tab-indent-region) ; indent region (global-set-key (kbd "C-x <backtab>") 'unindent-region) ; unindent region (defun tab-indent-region () (interactive) (setq fill-prefix "\t") (indent-region (region-beginning) (region-end) 4) ) (defun unindent-region () (interactive) (indent-region (region-beginning) (region-end) -1) ) (global-set-key (kbd "TAB") 'self-insert-command) (global-set-key (kbd "RET") 'newline-and-indent) (setq key-translation-map (make-sparse-keymap)) (define-key key-translation-map "\177" (kbd "C-=")) (define-key key-translation-map (kbd "C-=") "\177") (global-set-key "\177" 'delete-backward-char) (global-set-key (kbd "C-=") 'delete-backward-char) (setq indent-tabs-mode t) (setq tab-always-indent t) (setq default-tab-width 4) (setq inhibit-startup-message t) ; do not show startup message (iswitchb-mode t) (desktop-save-mode t) (display-time)
Happy emacsing!
5 comments:
Why not use Vimpulse which adds visual mode (and other VIM stupidity) to Emacs?
In you a traitor I see.
I don't want to use emacs as I used Vim. It's another universe.
I'm enabling transient-mark-mode to view the marked area.
To be honest I'm happy that tried emacs. It's more comfortable than Vim.
I still have to explore its power and bind(rebind) functions to the keys with which I'm comfortable.
>In you a traitor I see.
The force is strong with this one.
Thank you, packey!
I'm pleased that you found this blog interesting!
Post a Comment