Essential Commands for Vim and Emacs
Core Vim Commands
Vim's modal editing relies heavily on keyboard commands. Mastering movement, editing, and other shortcuts in Normal, Visual, and Insert modes is key to productivity.
Normal Mode
Navigation:
hjkl - left, down, up, right movement
gg - go to the top of the file
G - go to the bottom of the file
0 - jump to the start of the line
$ - jump to the end of the line
ctrl+f/b - page up/down
#, * - jump to the next instance of the word under the cursor
Editing:
x - delete character
dd - delete the whole line
yy - yank/copy line
p - paste
r - replace a single character
u - undo
Search/Replace:
/pattern - search forward
?pattern - Search backward
n - repeat search forward
N - repeat search backward
Modes:
i - insert mode
v - visual mode
esc - back to normal mode
Copy/Paste:
yy - yank/copy line
dd - delete line
p - paste
"+y - copy to the system clipboard
Insert Mode:
i - start inserting text
a - append text after the cursor
o - open a new line below the cursor
esc - exit insert mode
Visual Mode:
v - start the characterwise visual selection
V - start likewise a visual selection
ctrl+v - start the blockwise visual selection
y - yank/copy selection
d - delete selection
- indent selection
< - unindent selection
Ex Mode:
:w - save file
:wq - save and quit
:q! - quit without saving
:grep - search across files
:s/old/new - substitute in line
:e {name} - open file for editing
Essential Emacs Commands
Emacs relies heavily on keyboard shortcuts and modifier keys for its commands. Learning the most common commands helps boost productivity.
Navigation
Arrow keys - move cursor
C-f/b - forward/backward one character
C-n/p - next/previous line
M-f/b - forward/backward one word
C-a/e - beginning/end of line
M-g g - go to a specific line
M-x goto-line - go to the line by the number
Editing
C-d - delete character
M-d - delete word
C-k - kill line (delete the whole line)
C-y - yank (paste)
C-/ - undo
C-s - search forward
C-r - search backward
Buffers and Files
C-x C-f - open file
C-x b - switch buffer
C-x C-s - save buffer
C-x C-w - save as
C-x k - close buffer
Help
C-h t - built-in tutorial
C-h k - describe the key binding
C-h f - describe the function
C-h i - open info manual
Customize
C-x C-b - rebind key
C-x C-f - load file/config
M-x customize - customize options
Additional commands for code editing, windows/frames, macros, etc. Consult Emacs docs for more!
Conclusion
Vim and Emacs both provide powerful sets of keyboard-driven commands for efficient text editing.
Vim's modal editing philosophy separates navigation and editing into Normal mode, text insertion into Insert mode, and selection in Visual mode. Movement and edits use single keystrokes like hjkl and dd. Mastery of Vim commands allows fluid text manipulation without reaching for the mouse.
Emacs utilizes modifier keys like Control and Alt combined with characters for commands. Navigation relies heavily on Control+letter chords like C-f and C-n to move between words and lines. Editing makes use of Control and Meta keys for shortcuts like C-k to kill a line.
Both editors have a learning curve, but expertise pays dividends in speed and efficiency. Vim's commands center around text editing and movement, facilitating rapid modifications once the modes are internalized. Emacs provides a broader range of functionality through key bindings, customized for user needs.
With practice, Vim and Emacs commands become muscle memory. Consult each editor's documentation and cheat sheets for a complete reference. The proficiency gained makes fluid and fast text editing possible without shifting hands from the home row. Mastering the basics opens the door to efficient coding, writing, and other work in these classic text editors.
Subscribe to my newsletter
Read articles from James Mathenge directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
James Mathenge
James Mathenge
A highly skilled professional dev who possesses a unique combination of expertise in both Finance and Software Development