Vim and Emacs

After watching the Bloomerg video of Mr Torvalds, I found that he is using Emacs-like editor, which is uemacs, I immediately compiled my Vim and Emacs cheatsheet.

A programmer can write program without IDE, but cannot write without a good text editor. There are a lot of modern text editors. But I feel that learning using a text user interface (console-based) text is very much important. Imagine that you have to use SSH to write some scripts on the remote computer.

I personally inclined to Vim. This is because of Vi editor, which is a very common text editor in every Unix-like OS. Therefore, I learnt Vim.

Unlike Vim, Emacs does not have the visual mode or insert mode. Therefore, Emacs is easier to highlight/select the text.

The following is the comparison table (my personal cheatsheet),

vim emacs
Left, down, up, right h, j, k, l ←, ↓, ↑, →
Left by word b Ctrl+←
Right by word w (begin), e (end) Ctrl+→
Begin line ^, 0 Home, Meta+a
End line $ End, Meta+e
First line gg Meta+<
Last line G Meta+>
Next single page, previous single page Ctrl+f, Ctrl+b Ctrl+v, Meta+v
Next half page, previous half page Ctrl+d, Ctrl+u
Go to line [:digit:]g Meta+x goto-line
Select v (visual mode) Shift+arrow
Copy y Meta+w
Paste p Ctrl+y
Cut d Ctrl+w
Edit i (insert mode), R (replace mode)
Delete x, d[hjkleb] Del
Append a
Open new line below, above o, O Enter
Undo, redo u, Ctrl+r Ctrl+/
Revert :e! Meta-x revert-buffer
Forward, backward search /pattern, ?pattern Ctrl+s, Ctrl+r
Next, previous n, N Ctrl+s, Ctrl+r
Search and replace :%s/old/new/g, :%s/old/new/gc (with confirmation) Meta+% (interactive)
Toggle case sensitivity :set ic (insensitive case) Meta+c
Regular expression search forward, backward /pattern, ?pattern Ctrl+Meta+s, Ctrl+Meta+r
Regular expression search and replace :%s/old/new/g, :%s/old/new/gc (with confirmation) Ctrl+Meta+% (interactive)
Increase indent, decrease indent >, < (in V) Ctrl+x Tab (interactive)
Horizontal, vertical split Ctrl+ws, Ctrl+wv Ctrl+x 2, Ctrl+x 3
Focus window Ctrl+w[hjkl] Meta+x windmove-[left|down|up|right]
Close window Ctrl+wq Ctrl+x 0
Close others Ctrl+wo Ctrl+x 1
Horizontal, vertical resize :res [+-][:digit:], :vert res [+-][:digit:] Ctrl+x { (horizontal shrink)

Ctrl+x } (horizontal enlarge)

Ctrl+x ^ (vertical enlarge)

Equal size Ctrl+w= Ctrl+x + (balance all)
Switch window Ctrl+ww Ctrl+x o
Tab (buffer and frame)
New tab :tabnew Ctrl+x 5 2 (frame)
Close tab :tabc Ctrl+x 5 0 (frame)
Close others :tab
Switch next, previous tab gt, gT Ctrl+x Left, Ctrl+x Right (buffer)
Switch n tab [:digit:]gt Ctrl+x b (interactive for buffer)
Move tab :tabmove [:digit:]
Quit :q, :q! (without changes) Ctrl+x Ctrl+c
Quit all :qa
Save :w Ctrl+x Ctrl+s
Save as :w filename Ctrl+x Ctrl+w
Save and exit :wq
:o filename
Ctrl+x Ctrl+f
Cancel command Ctrl+g
Command Meta+x command



One thought on “Vim and Emacs

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s