Skip to content

Vim & Nano Cheat Sheet(1)

Name

Interactive keyboard shortcut reference for Vim and Nano. Toggle between editors, search shortcuts, and browse by category.

🧭Normal Mode - Navigation(18)

h

Move cursor left

j

Move cursor down

k

Move cursor up

l

Move cursor right

w

Jump forward to start of next word

b

Jump backward to start of word

e

Jump forward to end of word

0

Jump to start of line

$

Jump to end of line

gg

Go to first line of document

G

Go to last line of document

Ctrl+d

Scroll half-page down

Ctrl+u

Scroll half-page up

}

Jump to next paragraph/block

{

Jump to previous paragraph/block

%

Jump to matching bracket

f{char}

Jump forward to character on current line

F{char}

Jump backward to character on current line

✏️Normal Mode - Editing(14)

i

Insert before cursor

a

Insert after cursor

o

Open new line below and enter insert mode

O

Open new line above and enter insert mode

x

Delete character under cursor

dd

Delete (cut) entire line

yy

Yank (copy) entire line

p

Paste after cursor

P

Paste before cursor

u

Undo last change

Ctrl+r

Redo last undone change

.

Repeat last command

J

Join current line with line below

~

Toggle case of character under cursor

πŸ”Normal Mode - Search(6)

/pattern

Search forward for pattern

?pattern

Search backward for pattern

n

Jump to next search match

N

Jump to previous search match

*

Search forward for word under cursor

#

Search backward for word under cursor

🎯Visual Mode(8)

v

Start character-wise visual selection

V

Start line-wise visual selection

Ctrl+v

Start block (column) visual selection

d

Delete selected text

y

Yank (copy) selected text

>

Indent selected text right

<

Indent selected text left

~

Toggle case of selected text

πŸ’»Command Mode(10)

:w

Save (write) file

:q

Quit editor

:wq

Save and quit

:q!

Quit without saving (force)

:e{file}

Open file for editing

:%s/old/new/g

Replace all occurrences in file

:setnumber

Show line numbers

:split

Horizontal split window

:vsplit

Vertical split window

:tabnew

Open new tab

πŸ“‹Registers & Macros(5)

"ay

Yank into register "a"

"ap

Paste from register "a"

qa...q

Record macro into register "a" (qa to start, q to stop)

@a

Execute macro stored in register "a"

@@

Re-run last executed macro

πŸͺŸWindow Management(8)

Ctrl+ws

Split window horizontally

Ctrl+wv

Split window vertically

Ctrl+ww

Cycle through windows

Ctrl+wh

Move to left window

Ctrl+wj

Move to window below

Ctrl+wk

Move to window above

Ctrl+wl

Move to right window

Ctrl+wq

Close current window

πŸ“¦Text Objects(8)

iw

Inner word (select word without surrounding spaces)

aw

A word (select word with surrounding space)

i"

Inner double-quoted string

a"

A double-quoted string (including quotes)

i(

Inner parentheses content

a(

A parenthesized block (including parens)

it

Inner tag (content between HTML/XML tags)

at

A tag block (including tags)

sponsored

Guide

Why Learn Vim and Nano?

Vim and Nano are terminal-based text editors available on virtually every Linux and macOS system. When you SSH into a remote server with no GUI, these editors are often your only option for editing configuration files, scripts, and code.

How This Reference Works

Toggle between Vim and Nano to see shortcuts for each editor. Search by key combination or description, and browse by category β€” navigation, editing, search, and more. Keyboard badges show the exact keys to press.

Getting Started with Terminal Editors

Nano is beginner-friendly with on-screen key hints, while Vim offers powerful modal editing for speed once you learn it. This reference helps bridge the learning curve for both editors.

How do I exit Vim?

Press Esc to make sure you are in Normal mode, then type :q and Enter to quit. If Vim refuses because there are unsaved changes, use :wq (or :x) to save and quit, or :q! to quit and throw the changes away. ZZ in Normal mode saves and quits, and ZQ quits without saving.

Vim's modes

Vim starts in Normal mode, where keys are commands rather than text. i inserts before the cursor, a appends after it and o opens a new line below β€” all three switch to Insert mode. v starts Visual mode for selecting characters, V selects whole lines and Ctrl+V selects a rectangular block. : opens the command line for things like saving and search-and-replace. Esc always takes you back to Normal mode.

Essential Vim editing commands

In Normal mode: x deletes a character, dd deletes a line, yy copies (yanks) a line and p pastes it below. u undoes and Ctrl+R redoes. cw changes a word, and . repeats the last change. gg jumps to the top of the file and G to the end, while :42 goes to line 42. Most commands take a count, so 5dd deletes five lines. :set number turns on line numbers.

Search and replace in Vim

/pattern searches forward and ?pattern searches backward; n and N jump to the next and previous match. :%s/old/new/g replaces every occurrence in the file, :s/old/new/g only on the current line, and adding c (:%s/old/new/gc) asks for confirmation at each match. :noh clears the search highlighting.

Nano essentials

Nano shows its shortcuts at the bottom of the screen, where ^ means Ctrl and M- means Alt. Ctrl+O saves (write out), Ctrl+X exits, Ctrl+W searches, Ctrl+\ searches and replaces, and Ctrl+_ jumps to a line number. Ctrl+K cuts the current line and Ctrl+U pastes it; Alt+U undoes and Alt+E redoes. Open a file at a specific line with nano +42 file.conf.

Set your default terminal editor

Tools like crontab -e, git commit, visudo and sudoedit open whichever editor the EDITOR or VISUAL variable names. Add export EDITOR=vim (or nano) to ~/.bashrc to choose. On Debian and Ubuntu, sudo update-alternatives --config editor sets the system-wide default. To edit protected files, prefer sudoedit /etc/hosts over sudo vim β€” it edits a temporary copy with your own editor settings.